Changeset 48568 in webkit


Ignore:
Timestamp:
Sep 19, 2009 6:13:51 PM (15 years ago)
Author:
oliver@apple.com
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.

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r48565 r48568  
     12009-09-19  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Implement ES5 Object.create function
     6        https://bugs.webkit.org/show_bug.cgi?id=29524
     7
     8        Implement Object.create.  Very simple patch, effectively Object.defineProperties
     9        only creating the target object itself.
     10
     11        * runtime/CommonIdentifiers.h:
     12        * runtime/ObjectConstructor.cpp:
     13        (JSC::ObjectConstructor::ObjectConstructor):
     14        (JSC::objectConstructorCreate):
     15
    1162009-09-19  Dan Bernstein  <mitz@apple.com>
    217
  • trunk/JavaScriptCore/runtime/CommonIdentifiers.h

    r48565 r48568  
    4040    macro(configurable) \
    4141    macro(constructor) \
     42    macro(create) \
    4243    macro(defineProperty) \
    4344    macro(defineProperties) \
  • 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
  • trunk/LayoutTests/ChangeLog

    r48566 r48568  
     12009-09-19  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Implement ES5 Object.create function
     6        https://bugs.webkit.org/show_bug.cgi?id=29524
     7
     8        Add tests for Object.create API
     9
     10        * fast/js/Object-create-expected.txt: Added.
     11        * fast/js/Object-create.html: Added.
     12        * fast/js/resources/Object-create.js: Added.
     13
    1142009-09-19  Sam Weinig  <sam@webkit.org>
    215
Note: See TracChangeset for help on using the changeset viewer.