Reflect.hx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. @:overload(function(target:{}, propertyKey:Symbol, attributes:ObjectPropertyDescriptor):Bool {})
  47. static function defineProperty(target:{}, propertyKey:String, attributes:ObjectPropertyDescriptor):Bool;
  48. /**
  49. The `delete` operator as a function. Equivalent to calling `delete target[name]`.
  50. */
  51. @:overload(function<T>(target:Array<T>, propertyKey:Int):Bool {})
  52. @:overload(function<T>(target:{}, propertyKey:Symbol):Bool {})
  53. static function deleteProperty(target:{}, propertyKey:String):Bool;
  54. /**
  55. A function that returns the value of properties.
  56. */
  57. @:overload(function<T>(target:Array<T>, propertyKey:Int, ?receiver:{}):Null<T> {})
  58. @:overload(function<T>(target:{}, propertyKey:Symbol, ?receiver:{}):Null<T> {})
  59. @:pure static function get<T>(target:{}, propertyKey:String, ?receiver:{}):Null<T>;
  60. /**
  61. Similar to `Object.getOwnPropertyDescriptor()`.
  62. Returns a property descriptor of the given property if it exists on the object,
  63. `undefined` otherwise.
  64. */
  65. @:overload(function<T>(target:Array<T>, propertyKey:Int):Null<ObjectPropertyDescriptor> {})
  66. @:overload(function(target:{}, propertyKey:Symbol):Null<ObjectPropertyDescriptor> {})
  67. @:pure static function getOwnPropertyDescriptor(target:{}, propertyKey:String):Null<ObjectPropertyDescriptor>;
  68. /**
  69. Same as `Object.getPrototypeOf()`.
  70. */
  71. @:pure static function getPrototypeOf<TProto:{}>(target:{}):Null<TProto>;
  72. /**
  73. The `in` operator as function. Returns a boolean indicating whether an own
  74. or inherited property exists.
  75. */
  76. @:overload(function<T>(target:Array<T>, propertyKey:Int):Bool {})
  77. @:overload(function(target:{}, propertyKey:Symbol):Bool {})
  78. @:pure static function has(target:{}, propertyKey:String):Bool;
  79. /**
  80. Same as `Object.isExtensible()`.
  81. */
  82. @:pure static function isExtensible(target:{}):Bool;
  83. /**
  84. Returns an array of the target object's own (not inherited) property keys.
  85. */
  86. @:pure static function ownKeys(target:{}):Array<String>;
  87. /**
  88. Similar to `Object.preventExtensions()`. Returns a Bool.
  89. */
  90. static function preventExtensions(obj:{}):Bool;
  91. /**
  92. A function that assigns values to properties. Returns a Bool that is true
  93. if the update was successful.
  94. */
  95. @:overload(function<T>(target:Array<T>, propertyKey:Int, value:T, ?receiver:{}):Bool {})
  96. @:overload(function<T>(target:{}, propertyKey:Symbol, value:T, ?receiver:{}):Bool {})
  97. static function set<T>(target:{}, propertyKey:String, value:T, ?receiver:{}):Bool;
  98. /**
  99. A function that sets the prototype of an object.
  100. */
  101. static function setPrototypeOf<TProto:{}>(target:{}, prototype:TProto):Bool;
  102. }