Reflect.hx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib;
  23. import haxe.Constraints.Function;
  24. import js.lib.Object;
  25. /**
  26. `Reflect` is a built-in object that provides methods for interceptable JavaScript operations.
  27. The methods are the same as those of [proxy handlers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler).
  28. Reflect is not a function object, so it's not constructible.
  29. Documentation [Reflect](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  30. **/
  31. @:native("Reflect")
  32. extern class Reflect {
  33. /**
  34. Calls a target function with arguments as specified by the args parameter.
  35. See also `Function.prototype.apply()`.
  36. */
  37. static function apply<T>(target:Function, thisArgument:{}, argumentsList:Array<Any>):T;
  38. /**
  39. The `new` operator as a function. Equivalent to calling `new target(...args)`.
  40. Provides also the optional possibility to specify a different prototype.
  41. */
  42. static function construct<T, S:T>(target:Class<T>, argumentsList:Array<Any>, ?newTarget:Class<S>):T;
  43. /**
  44. Similar to `Object.defineProperty()`. Returns a Bool.
  45. */
  46. static function defineProperty(target:{}, propertyKey:String, attributes:ObjectPropertyDescriptor):Bool;
  47. /**
  48. The `delete` operator as a function. Equivalent to calling `delete target[name]`.
  49. */
  50. @:overload(function<T>(target:Array<T>, propertyKey:Int):Bool {})
  51. static function deleteProperty(target:{}, propertyKey:String):Bool;
  52. /**
  53. A function that returns the value of properties.
  54. */
  55. @:overload(function<T>(target:Array<T>, propertyKey:Int, ?receiver:{}):Null<T> {})
  56. @:pure static function get<T>(target:{}, propertyKey:String, ?receiver:{}):Null<T>;
  57. /**
  58. Similar to `Object.getOwnPropertyDescriptor()`.
  59. Returns a property descriptor of the given property if it exists on the object,
  60. `undefined` otherwise.
  61. */
  62. @:pure static function getOwnPropertyDescriptor(target:{}, propertyKey:String):Null<ObjectPropertyDescriptor>;
  63. /**
  64. Same as `Object.getPrototypeOf()`.
  65. */
  66. @:pure static function getPrototypeOf<TProto:{}>(target:{}):Null<TProto>;
  67. /**
  68. The `in` operator as function. Returns a boolean indicating whether an own
  69. or inherited property exists.
  70. */
  71. @:pure static function has(target:{}, propertyKey:String):Bool;
  72. /**
  73. Same as `Object.isExtensible()`.
  74. */
  75. @:pure static function isExtensible(target:{}):Bool;
  76. /**
  77. Returns an array of the target object's own (not inherited) property keys.
  78. */
  79. @:pure static function ownKeys(target:{}):Array<String>;
  80. /**
  81. Similar to `Object.preventExtensions()`. Returns a Bool.
  82. */
  83. static function preventExtensions(obj:{}):Bool;
  84. /**
  85. A function that assigns values to properties. Returns a Bool that is true
  86. if the update was successful.
  87. */
  88. @:overload(function<T>(target:Array<T>, propertyKey:Int, value:T, ?receiver:{}):Bool {})
  89. static function set<T>(target:{}, propertyKey:String, value:T, ?receiver:{}):Bool;
  90. /**
  91. A function that sets the prototype of an object.
  92. */
  93. static function setPrototypeOf<TProto:{}>(target:{}, prototype:TProto):Bool;
  94. }