X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/runtime/ObjectConstructor.cpp?ds=inline diff --git a/runtime/ObjectConstructor.cpp b/runtime/ObjectConstructor.cpp index b7dd716..1a11e28 100644 --- a/runtime/ObjectConstructor.cpp +++ b/runtime/ObjectConstructor.cpp @@ -21,33 +21,37 @@ #include "config.h" #include "ObjectConstructor.h" +#include "ButterflyInlines.h" +#include "CopiedSpaceInlines.h" #include "Error.h" #include "ExceptionHelpers.h" -#include "JSFunction.h" #include "JSArray.h" +#include "JSCInlines.h" +#include "JSFunction.h" #include "JSGlobalObject.h" +#include "JSGlobalObjectFunctions.h" #include "Lookup.h" #include "ObjectPrototype.h" #include "PropertyDescriptor.h" #include "PropertyNameArray.h" +#include "StackVisitor.h" +#include "Symbol.h" namespace JSC { -ASSERT_CLASS_FITS_IN_CELL(ObjectConstructor); - -static EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState*); -static EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorSetPrototypeOf(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorIs(ExecState*); } @@ -55,13 +59,14 @@ static EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState*); namespace JSC { -ASSERT_HAS_TRIVIAL_DESTRUCTOR(ObjectConstructor); +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ObjectConstructor); -const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::objectConstructorTable, CREATE_METHOD_TABLE(ObjectConstructor) }; +const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_info, &objectConstructorTable, CREATE_METHOD_TABLE(ObjectConstructor) }; /* Source for ObjectConstructor.lut.h @begin objectConstructorTable getPrototypeOf objectConstructorGetPrototypeOf DontEnum|Function 1 + setPrototypeOf objectConstructorSetPrototypeOf DontEnum|Function 2 getOwnPropertyDescriptor objectConstructorGetOwnPropertyDescriptor DontEnum|Function 2 getOwnPropertyNames objectConstructorGetOwnPropertyNames DontEnum|Function 1 keys objectConstructorKeys DontEnum|Function 1 @@ -74,46 +79,57 @@ const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_i isSealed objectConstructorIsSealed DontEnum|Function 1 isFrozen objectConstructorIsFrozen DontEnum|Function 1 isExtensible objectConstructorIsExtensible DontEnum|Function 1 + is objectConstructorIs DontEnum|Function 2 + assign objectConstructorAssign DontEnum|Function 2 @end */ -ObjectConstructor::ObjectConstructor(JSGlobalObject* globalObject, Structure* structure) - : InternalFunction(globalObject, structure) +ObjectConstructor::ObjectConstructor(VM& vm, Structure* structure) + : InternalFunction(vm, structure) { } -void ObjectConstructor::finishCreation(ExecState* exec, ObjectPrototype* objectPrototype) +void ObjectConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, ObjectPrototype* objectPrototype) { - Base::finishCreation(exec->globalData(), Identifier(exec, "Object")); + Base::finishCreation(vm, objectPrototype->classInfo()->className); // ECMA 15.2.3.1 - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, objectPrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(vm, vm.propertyNames->prototype, objectPrototype, DontEnum | DontDelete | ReadOnly); // no. of arguments for constructor - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); + putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete); + + if (!globalObject->runtimeFlags().isSymbolDisabled()) + JSC_NATIVE_FUNCTION("getOwnPropertySymbols", objectConstructorGetOwnPropertySymbols, DontEnum, 1); + + JSC_NATIVE_FUNCTION(vm.propertyNames->getPrototypeOfPrivateName, objectConstructorGetPrototypeOf, DontEnum, 1); + JSC_NATIVE_FUNCTION(vm.propertyNames->getOwnPropertyNamesPrivateName, objectConstructorGetOwnPropertyNames, DontEnum, 1); } -bool ObjectConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot) +JSFunction* ObjectConstructor::addDefineProperty(ExecState* exec, JSGlobalObject* globalObject) { - return getStaticFunctionSlot(exec, ExecState::objectConstructorTable(exec), jsCast(cell), propertyName, slot); + VM& vm = exec->vm(); + JSFunction* definePropertyFunction = JSFunction::create(vm, globalObject, 3, vm.propertyNames->defineProperty.string(), objectConstructorDefineProperty); + putDirectWithoutTransition(vm, vm.propertyNames->defineProperty, definePropertyFunction, DontEnum); + return definePropertyFunction; } -bool ObjectConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool ObjectConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot) { - return getStaticFunctionDescriptor(exec, ExecState::objectConstructorTable(exec), jsCast(object), propertyName, descriptor); + return getStaticFunctionSlot(exec, objectConstructorTable, jsCast(object), propertyName, slot); } -// ECMA 15.2.2 -static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args) +static ALWAYS_INLINE JSObject* constructObject(ExecState* exec) { + JSGlobalObject* globalObject = exec->callee()->globalObject(); + ArgList args(exec); JSValue arg = args.at(0); if (arg.isUndefinedOrNull()) - return constructEmptyObject(exec, globalObject); + return constructEmptyObject(exec, globalObject->objectPrototype()); return arg.toObject(exec, globalObject); } static EncodedJSValue JSC_HOST_CALL constructWithObjectConstructor(ExecState* exec) { - ArgList args(exec); - return JSValue::encode(constructObject(exec, asInternalFunction(exec->callee())->globalObject(), args)); + return JSValue::encode(constructObject(exec)); } ConstructType ObjectConstructor::getConstructData(JSCell*, ConstructData& constructData) @@ -124,8 +140,7 @@ ConstructType ObjectConstructor::getConstructData(JSCell*, ConstructData& constr static EncodedJSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec) { - ArgList args(exec); - return JSValue::encode(constructObject(exec, asInternalFunction(exec->callee())->globalObject(), args)); + return JSValue::encode(constructObject(exec)); } CallType ObjectConstructor::getCallData(JSCell*, CallData& callData) @@ -134,43 +149,100 @@ CallType ObjectConstructor::getCallData(JSCell*, CallData& callData) return CallTypeHost; } +class ObjectConstructorGetPrototypeOfFunctor { +public: + ObjectConstructorGetPrototypeOfFunctor(JSObject* object) + : m_hasSkippedFirstFrame(false) + , m_object(object) + , m_result(JSValue::encode(jsUndefined())) + { + } + + EncodedJSValue result() const { return m_result; } + + StackVisitor::Status operator()(StackVisitor& visitor) + { + if (!m_hasSkippedFirstFrame) { + m_hasSkippedFirstFrame = true; + return StackVisitor::Continue; + } + + if (m_object->allowsAccessFrom(visitor->callFrame())) + m_result = JSValue::encode(m_object->prototype()); + return StackVisitor::Done; + } + +private: + bool m_hasSkippedFirstFrame; + JSObject* m_object; + EncodedJSValue m_result; +}; + EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec) { - if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Requested prototype of a value that is not an object.")); - JSObject* object = asObject(exec->argument(0)); - if (!object->allowsAccessFrom(exec->trueCallerFrame())) + JSObject* object = exec->argument(0).toObject(exec); + if (exec->hadException()) + return JSValue::encode(jsNull()); + ObjectConstructorGetPrototypeOfFunctor functor(object); + exec->iterate(functor); + return functor.result(); +} + +EncodedJSValue JSC_HOST_CALL objectConstructorSetPrototypeOf(ExecState* exec) +{ + JSValue objectValue = exec->argument(0); + if (objectValue.isUndefinedOrNull()) + return throwVMTypeError(exec); + + JSValue protoValue = exec->argument(1); + if (!protoValue.isObject() && !protoValue.isNull()) + return throwVMTypeError(exec); + + JSObject* object = objectValue.toObject(exec); + if (exec->hadException()) + return JSValue::encode(objectValue); + + if (!checkProtoSetterAccessAllowed(exec, object)) + return JSValue::encode(objectValue); + + if (!object->isExtensible()) + return throwVMError(exec, createTypeError(exec, StrictModeReadonlyPropertyWriteError)); + + if (!object->setPrototypeWithCycleCheck(exec, protoValue)) { + exec->vm().throwException(exec, createError(exec, ASCIILiteral("cyclic __proto__ value"))); return JSValue::encode(jsUndefined()); - return JSValue::encode(object->prototype()); + } + + return JSValue::encode(objectValue); } EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec) { - if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Requested property descriptor of a value that is not an object.")); - UString propertyName = exec->argument(1).toString(exec)->value(exec); + JSObject* object = exec->argument(0).toObject(exec); + if (exec->hadException()) + return JSValue::encode(jsNull()); + auto propertyName = exec->argument(1).toPropertyKey(exec); if (exec->hadException()) return JSValue::encode(jsNull()); - JSObject* object = asObject(exec->argument(0)); PropertyDescriptor descriptor; - if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, Identifier(exec, propertyName), descriptor)) + if (!object->getOwnPropertyDescriptor(exec, propertyName, descriptor)) return JSValue::encode(jsUndefined()); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSObject* description = constructEmptyObject(exec); if (!descriptor.isAccessorDescriptor()) { - description->putDirect(exec->globalData(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0); - description->putDirect(exec->globalData(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0); + description->putDirect(exec->vm(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0); + description->putDirect(exec->vm(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0); } else { ASSERT(descriptor.getter()); ASSERT(descriptor.setter()); - description->putDirect(exec->globalData(), exec->propertyNames().get, descriptor.getter(), 0); - description->putDirect(exec->globalData(), exec->propertyNames().set, descriptor.setter(), 0); + description->putDirect(exec->vm(), exec->propertyNames().get, descriptor.getter(), 0); + description->putDirect(exec->vm(), exec->propertyNames().set, descriptor.setter(), 0); } - description->putDirect(exec->globalData(), exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0); - description->putDirect(exec->globalData(), exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0); + description->putDirect(exec->vm(), exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0); + description->putDirect(exec->vm(), exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0); return JSValue::encode(description); } @@ -178,28 +250,48 @@ EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState // FIXME: Use the enumeration cache. EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState* exec) { - if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Requested property names of a value that is not an object.")); + JSObject* object = exec->argument(0).toObject(exec); + if (exec->hadException()) + return JSValue::encode(jsNull()); PropertyNameArray properties(exec); - asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, IncludeDontEnumProperties); - JSArray* names = constructEmptyArray(exec); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include)); + JSArray* names = constructEmptyArray(exec, 0); size_t numProperties = properties.size(); for (size_t i = 0; i < numProperties; i++) - names->push(exec, jsOwnedString(exec, properties[i].ustring())); + names->push(exec, jsOwnedString(exec, properties[i].string())); + return JSValue::encode(names); +} + +// FIXME: Use the enumeration cache. +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertySymbols(ExecState* exec) +{ + JSObject* object = exec->argument(0).toObject(exec); + if (exec->hadException()) + return JSValue::encode(jsNull()); + PropertyNameArray properties(exec); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include, SymbolPropertiesMode::Include)); + JSArray* names = constructEmptyArray(exec, 0); + size_t numProperties = properties.size(); + for (size_t i = 0; i < numProperties; i++) { + auto impl = properties[i].impl(); + if (impl->isSymbol() && !exec->propertyNames().isPrivateName(*impl)) + names->push(exec, Symbol::create(exec->vm(), static_cast(*impl))); + } return JSValue::encode(names); } // FIXME: Use the enumeration cache. EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec) { - if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Requested keys of a value that is not an object.")); + JSObject* object = exec->argument(0).toObject(exec); + if (exec->hadException()) + return JSValue::encode(jsNull()); PropertyNameArray properties(exec); - asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, ExcludeDontEnumProperties); - JSArray* keys = constructEmptyArray(exec); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode()); + JSArray* keys = constructEmptyArray(exec, 0); size_t numProperties = properties.size(); for (size_t i = 0; i < numProperties; i++) - keys->push(exec, jsOwnedString(exec, properties[i].ustring())); + keys->push(exec, jsOwnedString(exec, properties[i].string())); return JSValue::encode(keys); } @@ -207,7 +299,7 @@ EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec) static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc) { if (!in.isObject()) { - throwError(exec, createTypeError(exec, "Property description must be an object.")); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Property description must be an object."))); return false; } JSObject* description = asObject(in); @@ -249,7 +341,7 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor if (!get.isUndefined()) { CallData callData; if (getCallData(get, callData) == CallTypeNone) { - throwError(exec, createTypeError(exec, "Getter must be a function.")); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Getter must be a function."))); return false; } } @@ -264,7 +356,7 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor if (!set.isUndefined()) { CallData callData; if (getCallData(set, callData) == CallTypeNone) { - throwError(exec, createTypeError(exec, "Setter must be a function.")); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Setter must be a function."))); return false; } } @@ -275,12 +367,12 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor return true; if (desc.value()) { - throwError(exec, createTypeError(exec, "Invalid property. 'value' present on property with getter or setter.")); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'value' present on property with getter or setter."))); return false; } if (desc.writablePresent()) { - throwError(exec, createTypeError(exec, "Invalid property. 'writable' present on property with getter or setter.")); + exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'writable' present on property with getter or setter."))); return false; } return true; @@ -289,9 +381,9 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Properties can only be defined on Objects.")); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects."))); JSObject* O = asObject(exec->argument(0)); - UString propertyName = exec->argument(1).toString(exec)->value(exec); + auto propertyName = exec->argument(1).toPropertyKey(exec); if (exec->hadException()) return JSValue::encode(jsNull()); PropertyDescriptor descriptor; @@ -299,19 +391,18 @@ EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) return JSValue::encode(jsNull()); ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor())); ASSERT(!exec->hadException()); - O->methodTable()->defineOwnProperty(O, exec, Identifier(exec, propertyName), descriptor, true); + O->methodTable(exec->vm())->defineOwnProperty(O, exec, propertyName, descriptor, true); return JSValue::encode(O); } static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties) { PropertyNameArray propertyNames(exec); - asObject(properties)->methodTable()->getOwnPropertyNames(asObject(properties), exec, propertyNames, ExcludeDontEnumProperties); + asObject(properties)->methodTable(exec->vm())->getOwnPropertyNames(asObject(properties), exec, propertyNames, EnumerationMode(DontEnumPropertiesMode::Exclude, SymbolPropertiesMode::Include)); size_t numProperties = propertyNames.size(); Vector descriptors; MarkedArgumentBuffer markBuffer; for (size_t i = 0; i < numProperties; i++) { - PropertySlot slot; JSValue prop = properties->get(exec, propertyNames[i]); if (exec->hadException()) return jsNull(); @@ -330,7 +421,10 @@ static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* pro } } for (size_t i = 0; i < numProperties; i++) { - object->methodTable()->defineOwnProperty(object, exec, propertyNames[i], descriptors[i], true); + Identifier propertyName = propertyNames[i]; + if (exec->propertyNames().isPrivateName(propertyName)) + continue; + object->methodTable(exec->vm())->defineOwnProperty(object, exec, propertyName, descriptors[i], true); if (exec->hadException()) return jsNull(); } @@ -340,81 +434,83 @@ static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* pro EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwVMError(exec, createTypeError(exec, "Properties can only be defined on Objects.")); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects."))); return JSValue::encode(defineProperties(exec, asObject(exec->argument(0)), exec->argument(1).toObject(exec))); } EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec) { - if (!exec->argument(0).isObject() && !exec->argument(0).isNull()) - return throwVMError(exec, createTypeError(exec, "Object prototype may only be an Object or null.")); JSValue proto = exec->argument(0); - JSObject* newObject = proto.isObject() ? constructEmptyObject(exec, asObject(proto)->inheritorID(exec->globalData())) : constructEmptyObject(exec, exec->lexicalGlobalObject()->nullPrototypeObjectStructure()); + if (!proto.isObject() && !proto.isNull()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object prototype may only be an Object or null."))); + JSObject* newObject = proto.isObject() + ? constructEmptyObject(exec, asObject(proto)) + : constructEmptyObject(exec, exec->lexicalGlobalObject()->nullPrototypeObjectStructure()); if (exec->argument(1).isUndefined()) return JSValue::encode(newObject); if (!exec->argument(1).isObject()) - return throwVMError(exec, createTypeError(exec, "Property descriptor list must be an Object.")); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Property descriptor list must be an Object."))); return JSValue::encode(defineProperties(exec, newObject, asObject(exec->argument(1)))); } EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState* exec) { - // 1. If Type(O) is not Object throw a TypeError exception. + // 1. If Type(O) is not Object, return O. JSValue obj = exec->argument(0); if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.seal can only be called on Objects.")); + return JSValue::encode(obj); JSObject* object = asObject(obj); if (isJSFinalObject(object)) { - object->seal(exec->globalData()); + object->seal(exec->vm()); return JSValue::encode(obj); } // 2. For each named own property name P of O, PropertyNameArray properties(exec); - object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include, SymbolPropertiesMode::Include)); PropertyNameArray::const_iterator end = properties.end(); for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) { + Identifier propertyName = *iter; + if (exec->propertyNames().isPrivateName(propertyName)) + continue; // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P. PropertyDescriptor desc; - if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc)) + if (!object->getOwnPropertyDescriptor(exec, propertyName, desc)) continue; // b. If desc.[[Configurable]] is true, set desc.[[Configurable]] to false. desc.setConfigurable(false); // c. Call the [[DefineOwnProperty]] internal method of O with P, desc, and true as arguments. - object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true); + object->methodTable(exec->vm())->defineOwnProperty(object, exec, propertyName, desc, true); if (exec->hadException()) return JSValue::encode(obj); } // 3. Set the [[Extensible]] internal property of O to false. - object->preventExtensions(exec->globalData()); + object->preventExtensions(exec->vm()); // 4. Return O. return JSValue::encode(obj); } -EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec) +JSObject* objectConstructorFreeze(ExecState* exec, JSObject* object) { - // 1. If Type(O) is not Object throw a TypeError exception. - JSValue obj = exec->argument(0); - if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.freeze can only be called on Objects.")); - JSObject* object = asObject(obj); - - if (isJSFinalObject(object)) { - object->freeze(exec->globalData()); - return JSValue::encode(obj); + if (isJSFinalObject(object) && !hasIndexedProperties(object->indexingType())) { + object->freeze(exec->vm()); + return object; } // 2. For each named own property name P of O, PropertyNameArray properties(exec); - object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include, SymbolPropertiesMode::Include)); PropertyNameArray::const_iterator end = properties.end(); for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) { + Identifier propertyName = *iter; + if (exec->propertyNames().isPrivateName(propertyName)) + continue; // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P. PropertyDescriptor desc; - if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc)) + if (!object->getOwnPropertyDescriptor(exec, propertyName, desc)) continue; // b. If IsDataDescriptor(desc) is true, then // i. If desc.[[Writable]] is true, set desc.[[Writable]] to false. @@ -423,46 +519,58 @@ EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec) // c. If desc.[[Configurable]] is true, set desc.[[Configurable]] to false. desc.setConfigurable(false); // d. Call the [[DefineOwnProperty]] internal method of O with P, desc, and true as arguments. - object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true); + object->methodTable(exec->vm())->defineOwnProperty(object, exec, propertyName, desc, true); if (exec->hadException()) - return JSValue::encode(obj); + return object; } // 3. Set the [[Extensible]] internal property of O to false. - object->preventExtensions(exec->globalData()); + object->preventExtensions(exec->vm()); // 4. Return O. - return JSValue::encode(obj); + return object; +} + +EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec) +{ + // 1. If Type(O) is not Object, return O. + JSValue obj = exec->argument(0); + if (!obj.isObject()) + return JSValue::encode(obj); + return JSValue::encode(objectConstructorFreeze(exec, asObject(obj))); } EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState* exec) { JSValue obj = exec->argument(0); if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.preventExtensions can only be called on Objects.")); - asObject(obj)->preventExtensions(exec->globalData()); + return JSValue::encode(obj); + asObject(obj)->preventExtensions(exec->vm()); return JSValue::encode(obj); } EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState* exec) { - // 1. If Type(O) is not Object throw a TypeError exception. + // 1. If Type(O) is not Object, return true. JSValue obj = exec->argument(0); if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.isSealed can only be called on Objects.")); + return JSValue::encode(jsBoolean(true)); JSObject* object = asObject(obj); if (isJSFinalObject(object)) - return JSValue::encode(jsBoolean(object->isSealed(exec->globalData()))); + return JSValue::encode(jsBoolean(object->isSealed(exec->vm()))); // 2. For each named own property name P of O, PropertyNameArray properties(exec); - object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include, SymbolPropertiesMode::Include)); PropertyNameArray::const_iterator end = properties.end(); for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) { + Identifier propertyName = *iter; + if (exec->propertyNames().isPrivateName(propertyName)) + continue; // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P. PropertyDescriptor desc; - if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc)) + if (!object->getOwnPropertyDescriptor(exec, propertyName, desc)) continue; // b. If desc.[[Configurable]] is true, then return false. if (desc.configurable()) @@ -476,23 +584,26 @@ EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState* exec) EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState* exec) { - // 1. If Type(O) is not Object throw a TypeError exception. + // 1. If Type(O) is not Object, return true. JSValue obj = exec->argument(0); if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.isFrozen can only be called on Objects.")); + return JSValue::encode(jsBoolean(true)); JSObject* object = asObject(obj); if (isJSFinalObject(object)) - return JSValue::encode(jsBoolean(object->isFrozen(exec->globalData()))); + return JSValue::encode(jsBoolean(object->isFrozen(exec->vm()))); // 2. For each named own property name P of O, PropertyNameArray properties(exec); - object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); + object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include, SymbolPropertiesMode::Include)); PropertyNameArray::const_iterator end = properties.end(); for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) { + Identifier propertyName = *iter; + if (exec->propertyNames().isPrivateName(propertyName)) + continue; // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P. PropertyDescriptor desc; - if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc)) + if (!object->getOwnPropertyDescriptor(exec, propertyName, desc)) continue; // b. If IsDataDescriptor(desc) is true then // i. If desc.[[Writable]] is true, return false. c. If desc.[[Configurable]] is true, then return false. @@ -509,8 +620,13 @@ EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState* exec) { JSValue obj = exec->argument(0); if (!obj.isObject()) - return throwVMError(exec, createTypeError(exec, "Object.isExtensible can only be called on Objects.")); + return JSValue::encode(jsBoolean(false)); return JSValue::encode(jsBoolean(asObject(obj)->isExtensible())); } +EncodedJSValue JSC_HOST_CALL objectConstructorIs(ExecState* exec) +{ + return JSValue::encode(jsBoolean(sameValue(exec, exec->argument(0), exec->argument(1)))); +} + } // namespace JSC