Skip to content

Commit

Permalink
Reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Oct 15, 2023
1 parent fcd483f commit 2a9a5f2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 53 deletions.
117 changes: 68 additions & 49 deletions std/js/lib/Object.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

package js.lib;

import haxe.DynamicAccess;
import haxe.extern.Rest;
import haxe.DynamicAccess;

/**
The `js.lib.Object` constructor creates an object wrapper.
Expand All @@ -32,13 +32,6 @@ import haxe.extern.Rest;
**/
@:native("Object")
extern class Object {
static var prototype(default,never):ObjectPrototype;

/**
The Object constructor creates an object wrapper.
**/
@:pure function new(?value:Any);

/**
The Object.assign() method is used to copy the values of all enumerable
own properties from one or more source objects to a target object. It
Expand All @@ -48,7 +41,7 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
**/
@:pure static function assign<TSource:{}, TDest:{}>(target:TSource, sources:Rest<{}>):TDest;
static function assign<TSource:{}, TDest:{}>(target:TSource, sources:Rest<{}>):TDest;

/**
The Object.create() method create a new object, using an existing object
Expand All @@ -57,25 +50,25 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
**/
@:pure static function create<TObj>(proto:Null<{}>, ?propertiesObject:DynamicAccess<ObjectPropertyDescriptor<Any>>):TObj;
@:pure static function create<T>(proto:Null<{}>, ?propertiesObject:DynamicAccess<ObjectPropertyDescriptor<Any>>):T;

/**
The static method Object.defineProperty() defines a new property directly
on an object, or modifies an existing property on an object, and returns
the object.
The Object.defineProperties() method defines new or modifies existing
properties directly on an object, returning the object.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties
**/
@:overload(function<TObj:{}, TProp>(obj:TObj, prop:Symbol, descriptor:ObjectPropertyDescriptor<TProp>):TObj {})
static function defineProperty<TObj:{}, TProp>(obj:TObj, prop:String, descriptor:ObjectPropertyDescriptor<TProp>):TObj;
static function defineProperties<T:{}>(obj:T, props:DynamicAccess<ObjectPropertyDescriptor<Any>>):T;

/**
The Object.defineProperties() method defines new or modifies existing
properties directly on an object, returning the object.
The static method Object.defineProperty() defines a new property directly
on an object, or modifies an existing property on an object, and returns
the object.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
**/
static function defineProperties<TObj:{}>(obj:TObj, props:DynamicAccess<ObjectPropertyDescriptor<Any>>):TObj;
@:overload(function<T:{}, TProp>(obj:T, prop:Symbol, descriptor:ObjectPropertyDescriptor<TProp>):T {})
static function defineProperty<T:{}, TProp>(obj:T, prop:String, descriptor:ObjectPropertyDescriptor<TProp>):T;

/**
The Object.entries() method returns an array of a given object's own
Expand All @@ -87,7 +80,7 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
**/
@:pure static function entries<TObj:{}>(obj:TObj):Array<ObjectEntry>;
@:pure static function entries<T:{}>(obj:T):Array<ObjectEntry>;

/**
The Object.freeze() method freezes an object: that is, prevents new
Expand All @@ -99,7 +92,13 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
**/
static function freeze<TObj:{}>(obj:TObj):TObj;
static function freeze<T:{}>(obj:T):T;

/**
Returns a new object from an iterable of key-value pairs
(reverses Object.entries).
**/
@:pure static function fromEntries<T:{}>(iterable:Any):T;

/**
The Object.getOwnPropertyDescriptor() method returns a property
Expand All @@ -115,8 +114,8 @@ extern class Object {
@:overload(function(obj:String, prop:Symbol):Null<ObjectPropertyDescriptor<String>> {})
@:overload(function(obj:String, prop:String):Null<ObjectPropertyDescriptor<String>> {})
@:overload(function<T>(target:Array<T>, propertyKey:Int):Null<ObjectPropertyDescriptor<T>> {})
@:overload(function<TObj, TProp>(obj:TObj, prop:Symbol):Null<ObjectPropertyDescriptor<TProp>> {})
@:pure static function getOwnPropertyDescriptor<TObj, TProp>(obj:TObj, prop:String):Null<ObjectPropertyDescriptor<TProp>>;
@:overload(function<T, TProp>(obj:T, prop:Symbol):Null<ObjectPropertyDescriptor<TProp>> {})
@:pure static function getOwnPropertyDescriptor<T, TProp>(obj:T, prop:String):Null<ObjectPropertyDescriptor<TProp>>;

/**
The Object.getOwnPropertyDescriptors() method returns all own property
Expand All @@ -126,7 +125,7 @@ extern class Object {
**/
@:overload(function(target:String):DynamicAccess<ObjectPropertyDescriptor<String>> {})
@:overload(function<T>(target:Array<T>):DynamicAccess<ObjectPropertyDescriptor<T>> {})
@:pure static function getOwnPropertyDescriptors<TObj>(obj:TObj):DynamicAccess<ObjectPropertyDescriptor<Any>>;
@:pure static function getOwnPropertyDescriptors<T>(obj:T):DynamicAccess<ObjectPropertyDescriptor<Any>>;

/**
The Object.getOwnPropertyNames() method returns an array of all
Expand All @@ -135,7 +134,7 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames
**/
@:pure static function getOwnPropertyNames<TObj:{}>(obj:TObj):Array<String>;
@:pure static function getOwnPropertyNames<T:{}>(obj:T):Array<String>;

/**
The Object.getOwnPropertySymbols() method returns an array of all symbol
Expand All @@ -145,15 +144,15 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols
**/
@:pure static function getOwnPropertySymbols<TObj:{}>(obj:TObj):Array<Symbol>;
@:pure static function getOwnPropertySymbols<T:{}>(obj:T):Array<Symbol>;

/**
The Object.getPrototypeOf() method returns the prototype (i.e. the value
of the internal [[Prototype]] property) of the specified object.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf
**/
@:pure static function getPrototypeOf<TObj:{}, TProto>(obj:TObj):TProto;
@:pure static function getPrototypeOf<T:{}, TProto>(obj:T):TProto;

/**
The Object.is() method determines whether two values are the same value.
Expand All @@ -162,29 +161,39 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
**/
@:pure static function is<TObj:{}>(obj1:TObj, obj2:TObj):Bool;
@:native("is") @:pure static function isSame<T:{}>(obj1:T, obj2:T):Bool;

/**
The Object.is() method determines whether two values are the same value.
Note: this is an ES2015 feature
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
**/
@:deprecated("Use Object.isSame()")
@:pure static function is<T:{}>(obj1:T, obj2:T):Bool;

/**
The Object.isExtensible() method determines if an object is extensible
(whether it can have new properties added to it).
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
**/
@:pure static function isExtensible<TObj:{}>(obj:TObj):Bool;
@:pure static function isExtensible<T:{}>(obj:T):Bool;

/**
The Object.isFrozen() determines if an object is frozen.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
**/
@:pure static function isFrozen<TObj:{}>(obj:TObj):Bool;
@:pure static function isFrozen<T:{}>(obj:T):Bool;

/**
The Object.isSealed() method determines if an object is sealed.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
**/
@:pure static function isSealed<TObj:{}>(obj:TObj):Bool;
@:pure static function isSealed<T:{}>(obj:T):Bool;

/**
The Object.keys() method returns an array of a given object's own
Expand All @@ -194,15 +203,15 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
**/
@:pure static function keys<TObj:{}>(obj:TObj):Array<String>;
@:pure static function keys<T:{}>(obj:T):Array<String>;

/**
The Object.preventExtensions() method prevents new properties from ever
being added to an object (i.e. prevents future extensions to the object).
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions
**/
static function preventExtensions<TObj:{}>(obj:TObj):TObj;
static function preventExtensions<T:{}>(obj:T):T;

/**
The Object.seal() method seals an object, preventing new properties from
Expand All @@ -212,7 +221,7 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
**/
static function seal<TObj:{}>(obj:TObj):TObj;
static function seal<T:{}>(obj:T):T;

/**
The Object.setPrototypeOf() method sets the prototype (i.e., the internal
Expand All @@ -222,7 +231,7 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
**/
static function setPrototypeOf<TObj:{}, TProto:{}>(obj:TObj, proto:Null<TProto>):TObj;
static function setPrototypeOf<T:{}, TProto:{}>(obj:T, proto:Null<TProto>):T;

/**
The Object.values() method returns an array of a given object's own
Expand All @@ -234,7 +243,17 @@ extern class Object {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
**/
@:pure static function values<TObj:{}>(obj:TObj):Array<Dynamic>;
@:pure static function values<T:{}>(obj:T):Array<Any>;

/**
Allows the addition of properties to all objects of type Object.
**/
static var prototype(default, never):ObjectPrototype;

/**
The Object constructor creates an object wrapper.
**/
@:pure function new(?value:Any);
}

/**
Expand All @@ -247,45 +266,39 @@ typedef ObjectPrototype = {
property as a direct property of that object and not inherited through
the prototype chain.
**/
var hasOwnProperty(default,never):Function;
var hasOwnProperty(default, never):Function;

/**
Returns a boolean indicating whether the object this method is called
upon is in the prototype chain of the specified object.
**/
var isPrototypeOf(default,never):Function;
var isPrototypeOf(default, never):Function;

/**
Returns a boolean indicating if the internal enumerable attribute is set.
**/
var propertyIsEnumerable(default,never):Function;
var propertyIsEnumerable(default, never):Function;

/**
Calls `toString()`.
**/
var toLocaleString(default,never):Function;
var toLocaleString(default, never):Function;

/**
Returns a string representation of the object.
**/
var toString(default,never):Function;
var toString(default, never):Function;

/**
Returns the primitive value of the specified object.
**/
var valueOf(default,never):Function;
var valueOf(default, never):Function;
}

/**
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty>
**/
typedef ObjectPropertyDescriptor<TProp> = {
/**
The value associated with the property.
Can be any valid JavaScript value (number, object, function, etc).
**/
var ?value:TProp;

/**
`true` if and only if the type of this property descriptor may be
changed and if the property may be deleted from the corresponding object.
Expand All @@ -300,6 +313,12 @@ typedef ObjectPropertyDescriptor<TProp> = {
**/
var ?enumerable:Bool;

/**
The value associated with the property.
Can be any valid JavaScript value (number, object, function, etc).
**/
var ?value:TProp;

/**
`true` if and only if the value associated with the property may be
changed with an assignment operator.
Expand Down
12 changes: 8 additions & 4 deletions std/js/lib/Symbol.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ extern class Symbol {
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
**/
@:native('for') static function for_(key:String):Symbol;
@:native("for") static function for_(key:String):Symbol;

/**
The Symbol.keyFor(sym) method retrieves a shared symbol key from the
global symbol registry for the given symbol.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor
**/
@:pure static function keyFor(symbol:Symbol):Null<String>;
@:pure static function keyFor(sym:Symbol):Null<String>;

/**
Returns a string containing the description of the Symbol.
**/
@:pure function toString():String;

/**
A method returning the default iterator for an object. Used by for...of.
A method returning the default iterator for an object.
**/
static var iterator(default, null):Symbol;

/**
A method that returns the default AsyncIterator for an object.
**/
static var asyncIterator(default, null):Symbol;

/**
A method that matches against a string, also used to determine if an
object may be used as a regular expression. Used by
Expand Down Expand Up @@ -128,4 +133,3 @@ extern class Symbol {
inline function ofObject<T>(object:{}):Null<T>
return (cast object)[cast this];
}

0 comments on commit 2a9a5f2

Please sign in to comment.