diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/ObjectConstructor.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/ObjectConstructor.h | 138 |
1 files changed, 89 insertions, 49 deletions
diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.h b/Source/JavaScriptCore/runtime/ObjectConstructor.h index 4a6b4711b..fc52790da 100644 --- a/Source/JavaScriptCore/runtime/ObjectConstructor.h +++ b/Source/JavaScriptCore/runtime/ObjectConstructor.h @@ -1,6 +1,6 @@ /* * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) - * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2016-2017 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,8 +18,7 @@ * */ -#ifndef ObjectConstructor_h -#define ObjectConstructor_h +#pragma once #include "InternalFunction.h" #include "JSGlobalObject.h" @@ -27,62 +26,103 @@ namespace JSC { - class ObjectPrototype; +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptors(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertySymbols(ExecState*); +EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*); +EncodedJSValue JSC_HOST_CALL ownEnumerablePropertyKeys(ExecState*); - class ObjectConstructor : public InternalFunction { - public: - typedef InternalFunction Base; +class ObjectPrototype; - static ObjectConstructor* create(VM& vm, Structure* structure, ObjectPrototype* objectPrototype) - { - ObjectConstructor* constructor = new (NotNull, allocateCell<ObjectConstructor>(vm.heap)) ObjectConstructor(vm, structure); - constructor->finishCreation(vm, objectPrototype); - return constructor; - } +class ObjectConstructor : public InternalFunction { +public: + typedef InternalFunction Base; + static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable; - static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); - - DECLARE_INFO; - - static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) - { - return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); - } - - protected: - void finishCreation(VM& vm, ObjectPrototype*); - static const unsigned StructureFlags = OverridesGetOwnPropertySlot | InternalFunction::StructureFlags; - - private: - ObjectConstructor(VM&, Structure*); - static ConstructType getConstructData(JSCell*, ConstructData&); - static CallType getCallData(JSCell*, CallData&); - }; - - inline JSObject* constructEmptyObject(ExecState* exec, Structure* structure) + static ObjectConstructor* create(VM& vm, JSGlobalObject* globalObject, Structure* structure, ObjectPrototype* objectPrototype) { - return JSFinalObject::create(exec, structure); + ObjectConstructor* constructor = new (NotNull, allocateCell<ObjectConstructor>(vm.heap)) ObjectConstructor(vm, structure); + constructor->finishCreation(vm, globalObject, objectPrototype); + return constructor; } - inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype, unsigned inlineCapacity) - { - JSGlobalObject* globalObject = exec->lexicalGlobalObject(); - PrototypeMap& prototypeMap = globalObject->vm().prototypeMap; - Structure* structure = prototypeMap.emptyObjectStructureForPrototype( - prototype, inlineCapacity); - return constructEmptyObject(exec, structure); - } + DECLARE_INFO; - inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype) + static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) { - return constructEmptyObject(exec, prototype, JSFinalObject::defaultInlineCapacity()); + return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); } - inline JSObject* constructEmptyObject(ExecState* exec) - { - return constructEmptyObject(exec, exec->lexicalGlobalObject()->objectPrototype()); +protected: + void finishCreation(VM&, JSGlobalObject*, ObjectPrototype*); + +private: + ObjectConstructor(VM&, Structure*); + static ConstructType getConstructData(JSCell*, ConstructData&); + static CallType getCallData(JSCell*, CallData&); +}; + +inline JSObject* constructEmptyObject(ExecState* exec, Structure* structure) +{ + return JSFinalObject::create(exec, structure); +} + +inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype, unsigned inlineCapacity) +{ + JSGlobalObject* globalObject = exec->lexicalGlobalObject(); + PrototypeMap& prototypeMap = globalObject->vm().prototypeMap; + Structure* structure = prototypeMap.emptyObjectStructureForPrototype(globalObject, prototype, inlineCapacity); + return constructEmptyObject(exec, structure); +} + +inline JSObject* constructEmptyObject(ExecState* exec, JSObject* prototype) +{ + return constructEmptyObject(exec, prototype, JSFinalObject::defaultInlineCapacity()); +} + +inline JSObject* constructEmptyObject(ExecState* exec) +{ + return constructEmptyObject(exec, exec->lexicalGlobalObject()->objectStructureForObjectConstructor()); +} + +inline JSObject* constructObject(ExecState* exec, JSGlobalObject* globalObject, JSValue arg) +{ + if (arg.isUndefinedOrNull()) + return constructEmptyObject(exec, globalObject->objectPrototype()); + return arg.toObject(exec, globalObject); +} + +// Section 6.2.4.4 of the ES6 specification. +// https://tc39.github.io/ecma262/#sec-frompropertydescriptor +inline JSObject* constructObjectFromPropertyDescriptor(ExecState* exec, const PropertyDescriptor& descriptor) +{ + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + JSObject* description = constructEmptyObject(exec); + RETURN_IF_EXCEPTION(scope, nullptr); + + if (!descriptor.isAccessorDescriptor()) { + description->putDirect(vm, vm.propertyNames->value, descriptor.value() ? descriptor.value() : jsUndefined(), 0); + description->putDirect(vm, vm.propertyNames->writable, jsBoolean(descriptor.writable()), 0); + } else { + ASSERT(descriptor.getter() || descriptor.setter()); + if (descriptor.getter()) + description->putDirect(vm, vm.propertyNames->get, descriptor.getter(), 0); + if (descriptor.setter()) + description->putDirect(vm, vm.propertyNames->set, descriptor.setter(), 0); } + + description->putDirect(vm, vm.propertyNames->enumerable, jsBoolean(descriptor.enumerable()), 0); + description->putDirect(vm, vm.propertyNames->configurable, jsBoolean(descriptor.configurable()), 0); -} // namespace JSC + return description; +} -#endif // ObjectConstructor_h + +JS_EXPORT_PRIVATE JSObject* objectConstructorFreeze(ExecState*, JSObject*); +JSValue objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, const Identifier&); +JSValue objectConstructorGetOwnPropertyDescriptors(ExecState*, JSObject*); +JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode); +bool toPropertyDescriptor(ExecState*, JSValue, PropertyDescriptor&); + +} // namespace JSC |