Ignore:
Timestamp:
Sep 19, 2009, 6:13:51 PM (16 years ago)
Author:
[email protected]
Message:

Implement ES5 Object.create function
https://bugs.webkit.org/show_bug.cgi?id=29524

Reviewed by Maciej Stachowiak

Implement Object.create. Very simple patch, effectively Object.defineProperties
only creating the target object itself.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/ObjectConstructor.cpp

    r48565 r48568  
    4040static JSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*, JSObject*, JSValue, const ArgList&);
    4141static JSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*, JSObject*, JSValue, const ArgList&);
     42static JSValue JSC_HOST_CALL objectConstructorCreate(ExecState*, JSObject*, JSValue, const ArgList&);
    4243
    4344ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure)
     
    5556    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 3, exec->propertyNames().defineProperty, objectConstructorDefineProperty), DontEnum);
    5657    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 2, exec->propertyNames().defineProperties, objectConstructorDefineProperties), DontEnum);
     58    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 2, exec->propertyNames().create, objectConstructorCreate), DontEnum);
    5759}
    5860
     
    283285}
    284286
     287JSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec, JSObject*, JSValue, const ArgList& args)
     288{
     289    if (!args.at(0).isObject() && !args.at(0).isNull())
     290        return throwError(exec, TypeError, "Object prototype may only be an Object or null.");
     291    JSObject* newObject = constructEmptyObject(exec);
     292    newObject->setPrototype(args.at(0));
     293    if (args.at(1).isUndefined())
     294        return newObject;
     295    if (!args.at(1).isObject())
     296        return throwError(exec, TypeError, "Property descriptor list must be an Object.");
     297    return defineProperties(exec, newObject, asObject(args.at(1)));
     298}
     299
    285300} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.