ObjectConstructor.h [plain text]
#ifndef ObjectConstructor_h
#define ObjectConstructor_h
#include "InternalFunction.h"
#include "JSGlobalObject.h"
#include "ObjectPrototype.h"
namespace JSC {
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 ObjectPrototype;
class ObjectConstructor : public InternalFunction {
public:
typedef InternalFunction Base;
static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
static ObjectConstructor* create(VM& vm, JSGlobalObject* globalObject, Structure* structure, ObjectPrototype* objectPrototype)
{
ObjectConstructor* constructor = new (NotNull, allocateCell<ObjectConstructor>(vm.heap)) ObjectConstructor(vm, structure);
constructor->finishCreation(vm, globalObject, objectPrototype);
return constructor;
}
DECLARE_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
JSFunction* addDefineProperty(ExecState*, JSGlobalObject*);
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(
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);
}
inline JSObject* constructObjectFromPropertyDescriptor(ExecState* exec, const PropertyDescriptor& descriptor)
{
VM& vm = exec->vm();
JSObject* description = constructEmptyObject(exec);
if (vm.exception())
return 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);
return description;
}
JSObject* objectConstructorFreeze(ExecState*, JSObject*);
JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*);
JSValue objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, const Identifier&);
JSValue objectConstructorGetOwnPropertyDescriptors(ExecState*, JSObject*);
JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
bool toPropertyDescriptor(ExecState*, JSValue, PropertyDescriptor&);
}
#endif // ObjectConstructor_h