diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/JavaScriptCore/runtime/ObjectConstructor.cpp | |
parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/JavaScriptCore/runtime/ObjectConstructor.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/ObjectConstructor.cpp | 321 |
1 files changed, 93 insertions, 228 deletions
diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp index 65acb4817..72169e7d2 100644 --- a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp +++ b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp @@ -22,36 +22,35 @@ #include "ObjectConstructor.h" #include "ButterflyInlines.h" +#include "CallFrameInlines.h" #include "CopiedSpaceInlines.h" #include "Error.h" #include "ExceptionHelpers.h" -#include "JSArray.h" -#include "JSCInlines.h" #include "JSFunction.h" +#include "JSArray.h" #include "JSGlobalObject.h" -#include "JSGlobalObjectFunctions.h" #include "Lookup.h" #include "ObjectPrototype.h" +#include "Operations.h" #include "PropertyDescriptor.h" #include "PropertyNameArray.h" #include "StackVisitor.h" -#include "Symbol.h" namespace JSC { -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*); +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*); } @@ -61,12 +60,11 @@ namespace JSC { STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ObjectConstructor); -const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_info, &objectConstructorTable, CREATE_METHOD_TABLE(ObjectConstructor) }; +const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::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 @@ -79,8 +77,6 @@ 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 */ @@ -89,30 +85,18 @@ ObjectConstructor::ObjectConstructor(VM& vm, Structure* structure) { } -void ObjectConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, ObjectPrototype* objectPrototype) +void ObjectConstructor::finishCreation(VM& vm, ObjectPrototype* objectPrototype) { - Base::finishCreation(vm, objectPrototype->classInfo()->className); + Base::finishCreation(vm, Identifier(&vm, "Object").string()); // ECMA 15.2.3.1 putDirectWithoutTransition(vm, vm.propertyNames->prototype, objectPrototype, DontEnum | DontDelete | ReadOnly); // no. of arguments for constructor putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete); - - 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); -} - -JSFunction* ObjectConstructor::addDefineProperty(ExecState* exec, JSGlobalObject* globalObject) -{ - 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::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot) { - return getStaticFunctionSlot<JSObject>(exec, objectConstructorTable, jsCast<ObjectConstructor*>(object), propertyName, slot); + return getStaticFunctionSlot<JSObject>(exec, ExecState::objectConstructorTable(exec->vm()), jsCast<ObjectConstructor*>(object), propertyName, slot); } static ALWAYS_INLINE JSObject* constructObject(ExecState* exec) @@ -152,11 +136,11 @@ public: ObjectConstructorGetPrototypeOfFunctor(JSObject* object) : m_hasSkippedFirstFrame(false) , m_object(object) - , m_result(jsUndefined()) + , m_result(JSValue::encode(jsUndefined())) { } - JSValue result() const { return m_result; } + EncodedJSValue result() const { return m_result; } StackVisitor::Status operator()(StackVisitor& visitor) { @@ -165,73 +149,37 @@ public: return StackVisitor::Continue; } - if (m_object->allowsAccessFrom(visitor->callFrame())) - m_result = m_object->prototype(); - return StackVisitor::Done; - } + if (m_object->allowsAccessFrom(visitor->callFrame())) + m_result = JSValue::encode(m_object->prototype()); + return StackVisitor::Done; +} private: bool m_hasSkippedFirstFrame; JSObject* m_object; - JSValue m_result; + EncodedJSValue m_result; }; -JSValue objectConstructorGetPrototypeOf(ExecState* exec, JSObject* object) +EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec) { + if (!exec->argument(0).isObject()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested prototype of a value that is not an object."))); + JSObject* object = asObject(exec->argument(0)); ObjectConstructorGetPrototypeOfFunctor functor(object); exec->iterate(functor); return functor.result(); } -EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec) -{ - JSObject* object = exec->argument(0).toObject(exec); - if (exec->hadException()) - return JSValue::encode(jsUndefined()); - return JSValue::encode(objectConstructorGetPrototypeOf(exec, object)); -} - -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->prototype() == protoValue) - 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(objectValue); -} - EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec) { - JSObject* object = exec->argument(0).toObject(exec); - if (exec->hadException()) - return JSValue::encode(jsNull()); - auto propertyName = exec->argument(1).toPropertyKey(exec); + if (!exec->argument(0).isObject()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested property descriptor of a value that is not an object."))); + String propertyName = exec->argument(1).toString(exec)->value(exec); if (exec->hadException()) return JSValue::encode(jsNull()); + JSObject* object = asObject(exec->argument(0)); PropertyDescriptor descriptor; - if (!object->getOwnPropertyDescriptor(exec, propertyName, descriptor)) + if (!object->getOwnPropertyDescriptor(exec, Identifier(exec, propertyName), descriptor)) return JSValue::encode(jsUndefined()); if (exec->hadException()) return JSValue::encode(jsUndefined()); @@ -256,40 +204,33 @@ EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState // FIXME: Use the enumeration cache. EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState* exec) { - JSObject* object = exec->argument(0).toObject(exec); - if (exec->hadException()) - return JSValue::encode(jsNull()); - return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::Strings, DontEnumPropertiesMode::Include)); -} - -// 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()); - return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::Symbols, DontEnumPropertiesMode::Include)); + if (!exec->argument(0).isObject()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested property names of a value that is not an object."))); + PropertyNameArray properties(exec); + asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, IncludeDontEnumProperties); + 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].string())); + return JSValue::encode(names); } // FIXME: Use the enumeration cache. EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec) { - JSObject* object = exec->argument(0).toObject(exec); - if (exec->hadException()) - return JSValue::encode(jsNull()); - return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::Strings, DontEnumPropertiesMode::Exclude)); -} - -EncodedJSValue JSC_HOST_CALL ownEnumerablePropertyKeys(ExecState* exec) -{ - JSObject* object = exec->argument(0).toObject(exec); - if (exec->hadException()) - return JSValue::encode(jsNull()); - return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::StringsAndSymbols, DontEnumPropertiesMode::Exclude)); + if (!exec->argument(0).isObject()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested keys of a value that is not an object."))); + PropertyNameArray properties(exec); + asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, ExcludeDontEnumProperties); + 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].string())); + return JSValue::encode(keys); } // ES5 8.10.5 ToPropertyDescriptor -bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc) +static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc) { if (!in.isObject()) { exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Property description must be an object."))); @@ -376,7 +317,7 @@ EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) if (!exec->argument(0).isObject()) return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects."))); JSObject* O = asObject(exec->argument(0)); - auto propertyName = exec->argument(1).toPropertyKey(exec); + String propertyName = exec->argument(1).toString(exec)->value(exec); if (exec->hadException()) return JSValue::encode(jsNull()); PropertyDescriptor descriptor; @@ -384,14 +325,14 @@ EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) return JSValue::encode(jsNull()); ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor())); ASSERT(!exec->hadException()); - O->methodTable(exec->vm())->defineOwnProperty(O, exec, propertyName, descriptor, true); + O->methodTable()->defineOwnProperty(O, exec, Identifier(exec, propertyName), descriptor, true); return JSValue::encode(O); } static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties) { - PropertyNameArray propertyNames(exec, PropertyNameMode::StringsAndSymbols); - asObject(properties)->methodTable(exec->vm())->getOwnPropertyNames(asObject(properties), exec, propertyNames, EnumerationMode(DontEnumPropertiesMode::Exclude)); + PropertyNameArray propertyNames(exec); + asObject(properties)->methodTable()->getOwnPropertyNames(asObject(properties), exec, propertyNames, ExcludeDontEnumProperties); size_t numProperties = propertyNames.size(); Vector<PropertyDescriptor> descriptors; MarkedArgumentBuffer markBuffer; @@ -414,10 +355,7 @@ static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* pro } } for (size_t i = 0; i < numProperties; i++) { - Identifier propertyName = propertyNames[i]; - if (exec->propertyNames().isPrivateName(propertyName)) - continue; - object->methodTable(exec->vm())->defineOwnProperty(object, exec, propertyName, descriptors[i], true); + object->methodTable()->defineOwnProperty(object, exec, propertyNames[i], descriptors[i], true); if (exec->hadException()) return jsNull(); } @@ -448,10 +386,10 @@ EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec) EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState* exec) { - // 1. If Type(O) is not Object, return O. + // 1. If Type(O) is not Object throw a TypeError exception. JSValue obj = exec->argument(0); if (!obj.isObject()) - return JSValue::encode(obj); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.seal can only be called on Objects."))); JSObject* object = asObject(obj); if (isJSFinalObject(object)) { @@ -460,21 +398,18 @@ EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState* exec) } // 2. For each named own property name P of O, - PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols); - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include)); + PropertyNameArray properties(exec); + object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); 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->getOwnPropertyDescriptor(exec, propertyName, desc)) + if (!object->getOwnPropertyDescriptor(exec, *iter, 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(exec->vm())->defineOwnProperty(object, exec, propertyName, desc, true); + object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true); if (exec->hadException()) return JSValue::encode(obj); } @@ -486,24 +421,27 @@ EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState* exec) return JSValue::encode(obj); } -JSObject* objectConstructorFreeze(ExecState* exec, JSObject* object) +EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec) { - if (isJSFinalObject(object) && !hasIndexedProperties(object->indexingType())) { + // 1. If Type(O) is not Object throw a TypeError exception. + JSValue obj = exec->argument(0); + if (!obj.isObject()) + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.freeze can only be called on Objects."))); + JSObject* object = asObject(obj); + + if (isJSFinalObject(object) && !hasIndexedProperties(object->structure()->indexingType())) { object->freeze(exec->vm()); - return object; + return JSValue::encode(obj); } // 2. For each named own property name P of O, - PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols); - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include)); + PropertyNameArray properties(exec); + object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); 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->getOwnPropertyDescriptor(exec, propertyName, desc)) + if (!object->getOwnPropertyDescriptor(exec, *iter, desc)) continue; // b. If IsDataDescriptor(desc) is true, then // i. If desc.[[Writable]] is true, set desc.[[Writable]] to false. @@ -512,58 +450,46 @@ JSObject* objectConstructorFreeze(ExecState* exec, JSObject* object) // 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(exec->vm())->defineOwnProperty(object, exec, propertyName, desc, true); + object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true); if (exec->hadException()) - return object; + return JSValue::encode(obj); } // 3. Set the [[Extensible]] internal property of O to false. object->preventExtensions(exec->vm()); // 4. Return O. - 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))); + return JSValue::encode(obj); } EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState* exec) { JSValue obj = exec->argument(0); if (!obj.isObject()) - return JSValue::encode(obj); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.preventExtensions can only be called on Objects."))); asObject(obj)->preventExtensions(exec->vm()); return JSValue::encode(obj); } EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState* exec) { - // 1. If Type(O) is not Object, return true. + // 1. If Type(O) is not Object throw a TypeError exception. JSValue obj = exec->argument(0); if (!obj.isObject()) - return JSValue::encode(jsBoolean(true)); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isSealed can only be called on Objects."))); JSObject* object = asObject(obj); if (isJSFinalObject(object)) return JSValue::encode(jsBoolean(object->isSealed(exec->vm()))); // 2. For each named own property name P of O, - PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols); - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include)); + PropertyNameArray properties(exec); + object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); 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->getOwnPropertyDescriptor(exec, propertyName, desc)) + if (!object->getOwnPropertyDescriptor(exec, *iter, desc)) continue; // b. If desc.[[Configurable]] is true, then return false. if (desc.configurable()) @@ -577,26 +503,23 @@ EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState* exec) EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState* exec) { - // 1. If Type(O) is not Object, return true. + // 1. If Type(O) is not Object throw a TypeError exception. JSValue obj = exec->argument(0); if (!obj.isObject()) - return JSValue::encode(jsBoolean(true)); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isFrozen can only be called on Objects."))); JSObject* object = asObject(obj); if (isJSFinalObject(object)) return JSValue::encode(jsBoolean(object->isFrozen(exec->vm()))); // 2. For each named own property name P of O, - PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols); - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include)); + PropertyNameArray properties(exec); + object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties); 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->getOwnPropertyDescriptor(exec, propertyName, desc)) + if (!object->getOwnPropertyDescriptor(exec, *iter, 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. @@ -613,66 +536,8 @@ EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState* exec) { JSValue obj = exec->argument(0); if (!obj.isObject()) - return JSValue::encode(jsBoolean(false)); + return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isExtensible can only be called on Objects."))); 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)))); -} - -// FIXME: Use the enumeration cache. -JSArray* ownPropertyKeys(ExecState* exec, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) -{ - PropertyNameArray properties(exec, propertyNameMode); - object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(dontEnumPropertiesMode)); - - JSArray* keys = constructEmptyArray(exec, 0); - - switch (propertyNameMode) { - case PropertyNameMode::Strings: { - size_t numProperties = properties.size(); - for (size_t i = 0; i < numProperties; i++) { - const auto& identifier = properties[i]; - ASSERT(!identifier.isSymbol()); - keys->push(exec, jsOwnedString(exec, identifier.string())); - } - break; - } - - case PropertyNameMode::Symbols: { - size_t numProperties = properties.size(); - for (size_t i = 0; i < numProperties; i++) { - const auto& identifier = properties[i]; - ASSERT(identifier.isSymbol()); - if (!exec->propertyNames().isPrivateName(identifier)) - keys->push(exec, Symbol::create(exec->vm(), static_cast<SymbolImpl&>(*identifier.impl()))); - } - break; - } - - case PropertyNameMode::StringsAndSymbols: { - Vector<Identifier, 16> propertySymbols; - size_t numProperties = properties.size(); - for (size_t i = 0; i < numProperties; i++) { - const auto& identifier = properties[i]; - if (identifier.isSymbol()) { - if (!exec->propertyNames().isPrivateName(identifier)) - propertySymbols.append(identifier); - } else - keys->push(exec, jsOwnedString(exec, identifier.string())); - } - - // To ensure the order defined in the spec (9.1.12), we append symbols at the last elements of keys. - for (const auto& identifier : propertySymbols) - keys->push(exec, Symbol::create(exec->vm(), static_cast<SymbolImpl&>(*identifier.impl()))); - - break; - } - } - - return keys; -} - } // namespace JSC |