Explorar o código

Fix Object, Reflect and Proxy (closes #9408) (#9409)

terurou %!s(int64=5) %!d(string=hai) anos
pai
achega
23e1444f45
Modificáronse 3 ficheiros con 18 adicións e 6 borrados
  1. 3 0
      std/js/lib/Object.hx
  2. 7 6
      std/js/lib/Proxy.hx
  3. 8 0
      std/js/lib/Reflect.hx

+ 3 - 0
std/js/lib/Object.hx

@@ -51,6 +51,7 @@ extern class Object {
 	/**
 		Adds the named property described by a given descriptor to an object.
 	**/
+	@:overload(function<T:{}>(obj:T, prop:Symbol, descriptor:ObjectPropertyDescriptor):T {})
 	static function defineProperty<T:{}>(obj:T, prop:String, descriptor:ObjectPropertyDescriptor):T;
 
 	/**
@@ -73,6 +74,8 @@ extern class Object {
 	/**
 		Returns a property descriptor for a named property on an object.
 	**/
+	@:overload(function<T>(target:Array<T>, propertyKey:Int):Null<ObjectPropertyDescriptor> {})
+	@:overload(function(obj:{}, prop:Symbol):Null<ObjectPropertyDescriptor> {})
 	@:pure static function getOwnPropertyDescriptor(obj:{}, prop:String):Null<ObjectPropertyDescriptor>;
 
 	/**

+ 7 - 6
std/js/lib/Proxy.hx

@@ -23,6 +23,7 @@
 package js.lib;
 
 import js.lib.Object;
+import haxe.extern.EitherType;
 
 /**
 	The `Proxy` object is used to define custom behavior for fundamental operations
@@ -64,32 +65,32 @@ typedef ProxyHandler<T:{}> = {
 	/**
 		A trap for `Object.getOwnPropertyDescriptor`.
 	**/
-	var ?getOwnPropertyDescriptor:(target:T, prop:String) -> Null<ObjectPropertyDescriptor>;
+	var ?getOwnPropertyDescriptor:(target:T, prop:EitherType<String, Symbol>) -> Null<ObjectPropertyDescriptor>;
 
 	/**
 		A trap for `Object.defineProperty`.
 	**/
-	var ?defineProperty:(target:T, property:String, descriptor:ObjectPropertyDescriptor) -> Bool;
+	var ?defineProperty:(target:T, property:EitherType<String, Symbol>, descriptor:ObjectPropertyDescriptor) -> Bool;
 
 	/**
 		A trap for the `in` operator.
 	**/
-	var ?has:(target:T, prop:String) -> Bool;
+	var ?has:(target:T, prop:EitherType<String, EitherType<Int, Symbol>>) -> Bool;
 
 	/**
 		A trap for getting property values.
 	**/
-	var ?get:(target:T, property:String, receiver:Null<{}>) -> Any;
+	var ?get:(target:T, property:EitherType<String, EitherType<Int, Symbol>>, receiver:Null<{}>) -> Any;
 
 	/**
 		A trap for setting property values.
 	**/
-	var ?set:(target:T, property:String, value:Any, receiver:Null<{}>) -> Bool;
+	var ?set:(target:T, property:EitherType<String, EitherType<Int, Symbol>>, value:Any, receiver:Null<{}>) -> Bool;
 
 	/**
 		A trap for the `delete` operator.
 	**/
-	var ?deleteProperty:(target:T, property:String) -> Bool;
+	var ?deleteProperty:(target:T, property:EitherType<String, EitherType<Int, Symbol>>) -> Bool;
 
 	/**
 		A trap for `Object.getOwnPropertyNames` and `Object.getOwnPropertySymbols`.

+ 8 - 0
std/js/lib/Reflect.hx

@@ -49,18 +49,21 @@ extern class Reflect {
 	/**
 		Similar to `Object.defineProperty()`. Returns a Bool.
 	 */
+	@:overload(function(target:{}, propertyKey:Symbol, attributes:ObjectPropertyDescriptor):Bool {})
 	static function defineProperty(target:{}, propertyKey:String, attributes:ObjectPropertyDescriptor):Bool;
 
 	/**
 		The `delete` operator as a function. Equivalent to calling `delete target[name]`.
 	 */
 	@:overload(function<T>(target:Array<T>, propertyKey:Int):Bool {})
+	@:overload(function<T>(target:{}, propertyKey:Symbol):Bool {})
 	static function deleteProperty(target:{}, propertyKey:String):Bool;
 
 	/**
 		A function that returns the value of properties.
 	 */
 	@:overload(function<T>(target:Array<T>, propertyKey:Int, ?receiver:{}):Null<T> {})
+	@:overload(function<T>(target:{}, propertyKey:Symbol, ?receiver:{}):Null<T> {})
 	@:pure static function get<T>(target:{}, propertyKey:String, ?receiver:{}):Null<T>;
 
 	/**
@@ -68,6 +71,8 @@ extern class Reflect {
 		Returns a property descriptor of the given property if it exists on the object,
 		`undefined` otherwise.
 	 */
+	@:overload(function<T>(target:Array<T>, propertyKey:Int):Null<ObjectPropertyDescriptor> {})
+	@:overload(function(target:{}, propertyKey:Symbol):Null<ObjectPropertyDescriptor> {})
 	@:pure static function getOwnPropertyDescriptor(target:{}, propertyKey:String):Null<ObjectPropertyDescriptor>;
 
 	/**
@@ -79,6 +84,8 @@ extern class Reflect {
 		The `in` operator as function. Returns a boolean indicating whether an own
 		or inherited property exists.
 	 */
+	@:overload(function<T>(target:Array<T>, propertyKey:Int):Bool {})
+	@:overload(function(target:{}, propertyKey:Symbol):Bool {})
 	@:pure static function has(target:{}, propertyKey:String):Bool;
 
 	/**
@@ -101,6 +108,7 @@ extern class Reflect {
 		if the update was successful.
 	 */
 	@:overload(function<T>(target:Array<T>, propertyKey:Int, value:T, ?receiver:{}):Bool {})
+	@:overload(function<T>(target:{}, propertyKey:Symbol, value:T, ?receiver:{}):Bool {})
 	static function set<T>(target:{}, propertyKey:String, value:T, ?receiver:{}):Bool;
 
 	/**