// ----------------------------------------------------------------------------
// Object
+var DefaultObjectToString = NoSideEffectsObjectToString;
// ECMA-262 - 15.2.4.2
-function ObjectToString() {
+function NoSideEffectsObjectToString() {
if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
if (IS_NULL(this)) return "[object Null]";
return "[object " + %_ClassOf(ToObject(this)) + "]";
// ECMA-262 - 15.2.4.5
function ObjectHasOwnProperty(V) {
- if (%IsJSProxy(this)) {
+ if (%_IsJSProxy(this)) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(V)) return false;
// ECMA-262 - 15.2.4.6
function ObjectIsPrototypeOf(V) {
- CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf");
if (!IS_SPEC_OBJECT(V)) return false;
+ CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf");
return %IsInPrototypeChain(this, V);
}
// ECMA-262 - 15.2.4.6
function ObjectPropertyIsEnumerable(V) {
var P = ToName(V);
- if (%IsJSProxy(this)) {
+ if (%_IsJSProxy(this)) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(V)) return false;
function ObjectKeys(obj) {
- if (!IS_SPEC_OBJECT(obj)) {
- throw MakeTypeError("called_on_non_object", ["Object.keys"]);
- }
- if (%IsJSProxy(obj)) {
+ obj = ToObject(obj);
+ if (%_IsJSProxy(obj)) {
var handler = %GetHandler(obj);
var names = CallTrap0(handler, "keys", DerivedKeysTrap);
return ToNameArray(names, "keys", false);
"set_",
"hasSetter_"
), $Array(
- "toString", function() {
+ "toString", function PropertyDescriptor_ToString() {
return "[object PropertyDescriptor]";
},
- "setValue", function(value) {
+ "setValue", function PropertyDescriptor_SetValue(value) {
this.value_ = value;
this.hasValue_ = true;
},
- "getValue", function() {
+ "getValue", function PropertyDescriptor_GetValue() {
return this.value_;
},
- "hasValue", function() {
+ "hasValue", function PropertyDescriptor_HasValue() {
return this.hasValue_;
},
- "setEnumerable", function(enumerable) {
+ "setEnumerable", function PropertyDescriptor_SetEnumerable(enumerable) {
this.enumerable_ = enumerable;
this.hasEnumerable_ = true;
},
- "isEnumerable", function () {
+ "isEnumerable", function PropertyDescriptor_IsEnumerable() {
return this.enumerable_;
},
- "hasEnumerable", function() {
+ "hasEnumerable", function PropertyDescriptor_HasEnumerable() {
return this.hasEnumerable_;
},
- "setWritable", function(writable) {
+ "setWritable", function PropertyDescriptor_SetWritable(writable) {
this.writable_ = writable;
this.hasWritable_ = true;
},
- "isWritable", function() {
+ "isWritable", function PropertyDescriptor_IsWritable() {
return this.writable_;
},
- "hasWritable", function() {
+ "hasWritable", function PropertyDescriptor_HasWritable() {
return this.hasWritable_;
},
- "setConfigurable", function(configurable) {
+ "setConfigurable",
+ function PropertyDescriptor_SetConfigurable(configurable) {
this.configurable_ = configurable;
this.hasConfigurable_ = true;
},
- "hasConfigurable", function() {
+ "hasConfigurable", function PropertyDescriptor_HasConfigurable() {
return this.hasConfigurable_;
},
- "isConfigurable", function() {
+ "isConfigurable", function PropertyDescriptor_IsConfigurable() {
return this.configurable_;
},
- "setGet", function(get) {
+ "setGet", function PropertyDescriptor_SetGetter(get) {
this.get_ = get;
- this.hasGetter_ = true;
+ this.hasGetter_ = true;
},
- "getGet", function() {
+ "getGet", function PropertyDescriptor_GetGetter() {
return this.get_;
},
- "hasGetter", function() {
+ "hasGetter", function PropertyDescriptor_HasGetter() {
return this.hasGetter_;
},
- "setSet", function(set) {
+ "setSet", function PropertyDescriptor_SetSetter(set) {
this.set_ = set;
this.hasSetter_ = true;
},
- "getSet", function() {
+ "getSet", function PropertyDescriptor_GetSetter() {
return this.set_;
},
- "hasSetter", function() {
+ "hasSetter", function PropertyDescriptor_HasSetter() {
return this.hasSetter_;
}));
// ES5 section 8.12.1.
function GetOwnPropertyJS(obj, v) {
var p = ToName(v);
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(v)) return UNDEFINED;
// ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies.
function DefineOwnProperty(obj, p, desc, should_throw) {
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(p)) return false;
}
-function ObjectGetOwnPropertyKeys(obj, symbolsOnly) {
+function ObjectGetOwnPropertyKeys(obj, filter) {
var nameArrays = new InternalArray();
- var filter = symbolsOnly ?
- PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL :
- PROPERTY_ATTRIBUTES_SYMBOLIC;
+ filter |= PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
// Find all the indexed properties.
// Only get own element names if we want to include string keys.
- if (!symbolsOnly) {
+ if ((filter & PROPERTY_ATTRIBUTES_STRING) === 0) {
var ownElementNames = %GetOwnElementNames(obj);
for (var i = 0; i < ownElementNames.length; ++i) {
ownElementNames[i] = %_NumberToString(ownElementNames[i]);
var j = 0;
for (var i = 0; i < propertyNames.length; ++i) {
var name = propertyNames[i];
- if (symbolsOnly) {
- if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue;
+ if (IS_SYMBOL(name)) {
+ if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) {
+ continue;
+ }
} else {
- if (IS_SYMBOL(name)) continue;
+ if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
name = ToString(name);
}
if (seenKeys[name]) continue;
// ES5 section 15.2.3.4.
function ObjectGetOwnPropertyNames(obj) {
- if (!IS_SPEC_OBJECT(obj)) {
- throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
- }
+ obj = ToObject(obj);
// Special handling for proxies.
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
var handler = %GetHandler(obj);
var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
return ToNameArray(names, "getOwnPropertyNames", false);
}
- return ObjectGetOwnPropertyKeys(obj, false);
+ return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC);
}
throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]);
}
var name = ToName(p);
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
// Clone the attributes object for protection.
// TODO(rossberg): not spec'ed yet, so not sure if this should involve
// non-own properties as it does (or non-enumerable ones, as it doesn't?).
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.seal"]);
}
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
ProxyFix(obj);
}
var names = ObjectGetOwnPropertyNames(obj);
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.freeze"]);
}
- var isProxy = %IsJSProxy(obj);
+ var isProxy = %_IsJSProxy(obj);
if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
if (isProxy) {
ProxyFix(obj);
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]);
}
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
ProxyFix(obj);
}
%PreventExtensions(obj);
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isSealed"]);
}
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
return false;
}
if (%IsExtensible(obj)) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]);
}
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
return false;
}
if (%IsExtensible(obj)) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]);
}
- if (%IsJSProxy(obj)) {
+ if (%_IsJSProxy(obj)) {
return true;
}
return %IsExtensible(obj);
}
-// Harmony egal.
+// ECMA-262, Edition 6, section 19.1.2.10
function ObjectIs(obj1, obj2) {
- if (obj1 === obj2) {
- return (obj1 !== 0) || (1 / obj1 === 1 / obj2);
- } else {
- return (obj1 !== obj1) && (obj2 !== obj2);
- }
+ return SameValue(obj1, obj2);
}
// Set up non-enumerable functions on the Object.prototype object.
InstallFunctions($Object.prototype, DONT_ENUM, $Array(
- "toString", ObjectToString,
+ "toString", NoSideEffectsObjectToString,
"toLocaleString", ObjectToLocaleString,
"valueOf", ObjectValueOf,
"hasOwnProperty", ObjectHasOwnProperty,
throw new $TypeError('Function.prototype.toString is not generic');
}
+ var classSource = %ClassGetSourceCode(func);
+ if (IS_STRING(classSource)) {
+ return classSource;
+ }
+
var source = %FunctionGetSourceCode(func);
if (!IS_STRING(source) || %FunctionIsBuiltin(func)) {
var name = %FunctionGetName(func);