Draft 2 of the spec for the Object class. Changelog near the beginning. --larsTitle: The class "Object"
The class Object
NAME: "The class 'Object'" FILE: spec/library/Object.html CATEGORY: Pre-defined classes (E262-3 Chapter 15) SOURCES: REFERENCES [1], [2] SPEC AUTHOR: Lars DRAFT STATUS: DRAFT 2 - 2008-03-10 REVIEWED AGAINST ES3: YES REVIEWED AGAINST ERRATA: YES REVIEWED AGAINST BASE DOC: YES REVIEWED AGAINST PROPOSALS: YES REVIEWED AGAINST CODE: YES IMPLEMENTATION STATUS: ES4RI TEST CASE STATUS: ? CHANGES SINCE DRAFT 1 (2008-03-05) * More elaborate status block above * Prototype methods do not delegate to the corresponding intrinsic methods, but to shared private methods that are also called by the intrinsic method. In this fashion, prototype method behavior is invariant of subclassing. * Introduction of a specification-only protocol helper::getClassName for overriding class names for ES3 compatibility. NOTES * The use of 'Private' instead of 'private' below is a workaround for a bug in the reference implementation (#368). * The function 'helper::toEnumerableId' converts an arbitrary value to a member of 'EnumerableId': int, uint, string, or Name. It is specified elsewhere but in general you can think of it as converting any number to int or uint, leaving strings and Names alone, and converting everything else to string. REFERENCES [1] [1] http://wiki.ecmascript.org/doku.php?id=proposals:enumerability [2] builtins/Name.es in the ES4 RI
The class
Objectis a dynamic non-final class that does not subclass any other objects: it is the root of the class hierarchy.All values in ECMAScript except undefined and null are instances of the class
Objector one of its subclasses.NOTE Host objects may not be instances of
Objector its subclasses, but must to some extent behave as if they are (see Host objects).Synopsis
The class
Objectprovides this interface:public dynamic class Object { public function Object(value=undefined) static meta function invoke(value=undefined) static public const length = 1 intrinsic function toString() : string intrinsic function toLocaleString() : string intrinsic function valueOf() : Object intrinsic function hasOwnProperty(name: EnumerableId): boolean intrinsic function isPrototypeOf(value): boolean intrinsic function propertyIsEnumerable(name: EnumerableId, flag: (boolean|undefined) = undefined): boolean }The
Objectprototype object provides these direct properties:toString: function () , toLocaleString: function () , valueOf: function () , hasOwnProperty: function (name) , isPrototypeOf: function (value) , propertyIsEnumerable: function (name, flag=undefined) ,The
Objectprototype object is itself an instance of the classObject, with the exception that the value of its[[Prototype]]property is null.Methods on the
Objectclass objectnew Object ( value= )
Description
When the
Objectconstructor is called with an argument value (defaulting to undefined) as part of anew_expression_, it transforms the value to an object in a way that depends on the type of value.Returns
The
Objectconstructor returns an object (an instance ofObjector one of its subclasses, or a host object).NOTE The
Objectconstructor is the only constructor function defined on a class in the language whose result may be a value of a different class than the one in which the constructor is defined.Implementation
The
Objectconstructor can't be expressed as a regular ECMAScript constructor. Instead it is presented below as a helper functionmakeObjectthat the ECMAScript implementation will invoke when it evaluatesnew Object.The helper function
makeObjectonly is invoked on native ECMAScript values. Ifnew Objectis evaluated on a host object, then actions are taken and a result is returned in an implementation dependent manner that may depend on the host object.helper function makeObject(value=undefined) { switch type (value) { case (s: string) { return new String(s); } case (b: boolean) { return new Boolean(b); } case (n: (int|uint|double|decimal)) { return new Number(n); } case (x: (null|undefined)) { return magic::createObject(); } case (o: Object) { return o; } } }Object ( value= )
Description
When the
Objectclass object is called as a function with zero or one arguments it performs a type conversion.Returns
It returns the converted value.
Implementation
static meta function invoke(value=undefined) new Object(value);Methods on
ObjectinstancesThe intrinsic methods on
Objectinstances delegate to private methods that are also called by the prototype methods.intrinsic::toString ( )
Description
The intrinsic
toStringmethod converts thethisobject to a string.Returns
The intrinsic
toStringmethod returns the concatenation of"[","object", the class name of the object, and"]".Implementation
intrinsic function toString() : string Private::toString(); Private function toString(): string "[object " + helper::getClassName() + "]";The helper function
getClassNamereturns the name for the class. This method is overridden in some of the pre-defined classes in order to provide backward compatibility with the 3rd Edition of this Standard: It is overridden by the class Error.helper function getClassName() magic::getClassName(this);The function
magic::getClassNameextracts the class name from the object. See magic:getClassName.intrinsic::toLocaleString ( )
Description
The intrinsic
toLocaleStringmethod calls the publictoStringmethod on thethisobject.NOTE This method is provided to give all objects a generic
toLocaleStringinterface, even though not all may use it. Currently,Array,Number, andDateprovide their own locale-sensitivetoLocaleStringmethods.NOTE The first parameter to this function is likely to be used in a future version of this standard; it is recommended that implementations do not use this parameter position for anything else.
Returns
The intrinsic
toLocaleStringmethod returns a string.Implementation
intrinsic function toLocaleString() : string Private::toLocaleString(); Private function toLocaleString() this.toString();intrinsic::valueOf ( )
Description
The intrinsic
valueOfmethod returns itsthisvalue.If the object is the result of calling the Object constructor with a host object (Host objects), it is implementation-defined whether
valueOfreturns itsthisvalue or another value such as the host object originally passed to the constructor.Returns
The intrinsic
valueOfmethod returns an object value.Implementation
intrinsic function valueOf() : Object Private::valueOf(); Private function valueOf(): Object this;intrinsic::hasOwnProperty ( name )
Description
The intrinsic
hasOwnPropertymethod determines whether thethisobject contains a property with a certain name, without considering the prototype chain.NOTE Unlike
[[HasProperty]](see HasProperty-defn), this method does not consider objects in the prototype chain.Returns
The intrinsic
hasOwnPropertymethod returnstrueif the object contains the property, otherwise it returnsfalse.Implementation
intrinsic function hasOwnProperty(name: EnumerableId): boolean magic::hasOwnProperty(this, name); Private function hasOwnProperty(name: EnumerableId): boolean magic::hasOwnProperty(this, name);The function
magic::hasOwnPropertytests whether the object contains the named property on its local property list (the prototype chain is not considered). See magic:hasOwnProperty.The helper function
toEnumerableIdreturns its argument if it is one of the member types ofEnumerableId(int,uint,string, andName) and otherwise converts the argument tostring.helper function toEnumerableId(x) { switch type (x) { case (x: EnumerableId) { return x; } case (x: *) { return string(x); } } }intrinsic::isPrototypeOf ( value )
Description
The intrinsic
isPrototypeOfmethod determines whether itsthisobject is a prototype object of the argument value.Returns
The intrinsic
isPrototypeOfmethod returnstrueif thethisobject is on the prototype chain of value, otherwise it returnsfalse.Implementation
intrinsic function isPrototypeOf(value): boolean Private::isPrototypeOf(value); Private function isPrototypeOf(value): boolean { if (!(value is Object)) return false; let obj = value; while (true) { obj = magic::getPrototype(obj); if (obj === null || obj === undefined) return false; if (obj === this) return true; } }The function
magic::getPrototypeextracts the[[Prototype]]property from the object. See magic:getPrototype.intrinsic::propertyIsEnumerable ( name, flag= )
Description
The intrinsic
propertyIsEnumerablemethod retrieves, and optionally sets, the enumerability flag for a property with a certain name on thethisobject, without considering the prototype chain.COMPATIBILITY NOTE The functionality to set the enumerability flag is new in the 4th Edition of this Standard.
NOTE This method does not consider objects in the prototype chain.
Returns
The intrinsic
propertyIsEnumerablemethod returnsfalseif the property does not exist on thethisobject; otherwise it returns the value of the enumerability flag for the property before any change was made.Implementation
intrinsic function propertyIsEnumerable(name: EnumerableId, flag: (boolean|undefined) = undefined): boolean Private::propertyIsEnumerable(name, flag); Private function propertyIsEnumerable(name, flag) { if (!magic::hasOwnProperty(this, name)) return false; let oldval = !magic::getPropertyIsDontEnum(this, name); if (!magic::getPropertyIsDontDelete(this, name)) if (flag !== undefined) magic::setPropertyIsDontEnum(this, name, !flag); return oldval; }The function
magic::hasOwnPropertytests whether the object contains the named property on its local property list. See magic:hasOwnProperty.The function
magic::getPropertyIsDontEnumgets the DontEnum flag of the property. See magic:getPropertyIsDontEnum.The function
magic::getPropertyIsDontDeletegets the DontDelete flag of the property. See magic:getPropertyIsDontDelete.The function
magic::setPropertyIsDontEnumsets the DontEnum flag of the property. See magic:setPropertyIsDontEnum.Methods on the
Objectprototype objectDescription
The methods on the
Objectprototype object all perform simple type adjustments and then perform the same actions as the corresponding intrinsic methods.Returns
The prototype methods return what their corresponding intrinsic methods return.
Implementation
prototype function toString() this.Private::toString(); prototype function toLocaleString() this.Private::toLocaleString(); prototype function valueOf() this.Private::valueOf(); prototype function hasOwnProperty(name) this.Private::hasOwnProperty(helper::toEnumerableId(name)); prototype function isPrototypeOf(value) this.Private::isPrototypeOf(value); prototype function propertyIsEnumerable(name, flag=undefined) this.Private::propertyIsEnumerable(helper::toEnumerableId(name), flag === undefined ? flag : boolean(flag));_______________________________________________ Es4-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es4-discuss
