Ignore:
Timestamp:
Aug 17, 2015, 11:28:19 AM (10 years ago)
Author:
Yusuke Suzuki
Message:

[ES6] Implement Reflect.getOwnPropertyDescriptor
https://bugs.webkit.org/show_bug.cgi?id=147929

Reviewed by Geoffrey Garen.

Implement Reflect.getOwnPropertyDescriptor.
The difference from the Object.getOwnPropertyDescriptor is
Reflect.getOwnPropertyDescriptor does not perform ToObject onto
the first argument. If the first argument is not an Object, it
immediately raises the TypeError.

  • runtime/ObjectConstructor.cpp:

(JSC::objectConstructorGetOwnPropertyDescriptor):

  • runtime/ObjectConstructor.h:
  • runtime/ReflectObject.cpp:

(JSC::reflectObjectGetOwnPropertyDescriptor):

  • tests/stress/reflect-get-own-property.js: Added.

(shouldBe):
(shouldThrow):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/ReflectObject.cpp

    r188384 r188529  
    3737static EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState*);
    3838static EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState*);
     39static EncodedJSValue JSC_HOST_CALL reflectObjectGetOwnPropertyDescriptor(ExecState*);
    3940static EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState*);
    4041static EncodedJSValue JSC_HOST_CALL reflectObjectIsExtensible(ExecState*);
     
    5556/* Source for ReflectObject.lut.h
    5657@begin reflectObjectTable
    57     apply             reflectObjectApply             DontEnum|Function 3
    58     defineProperty    reflectObjectDefineProperty    DontEnum|Function 3
    59     deleteProperty    reflectObjectDeleteProperty    DontEnum|Function 2
    60     enumerate         reflectObjectEnumerate         DontEnum|Function 1
    61     getPrototypeOf    reflectObjectGetPrototypeOf    DontEnum|Function 1
    62     has               reflectObjectHas               DontEnum|Function 2
    63     isExtensible      reflectObjectIsExtensible      DontEnum|Function 1
    64     ownKeys           reflectObjectOwnKeys           DontEnum|Function 1
    65     preventExtensions reflectObjectPreventExtensions DontEnum|Function 1
    66     setPrototypeOf    reflectObjectSetPrototypeOf    DontEnum|Function 2
     58    apply                    reflectObjectApply                    DontEnum|Function 3
     59    defineProperty           reflectObjectDefineProperty           DontEnum|Function 3
     60    deleteProperty           reflectObjectDeleteProperty           DontEnum|Function 2
     61    enumerate                reflectObjectEnumerate                DontEnum|Function 1
     62    getOwnPropertyDescriptor reflectObjectGetOwnPropertyDescriptor DontEnum|Function 2
     63    getPrototypeOf           reflectObjectGetPrototypeOf           DontEnum|Function 1
     64    has                      reflectObjectHas                      DontEnum|Function 2
     65    isExtensible             reflectObjectIsExtensible             DontEnum|Function 1
     66    ownKeys                  reflectObjectOwnKeys                  DontEnum|Function 1
     67    preventExtensions        reflectObjectPreventExtensions        DontEnum|Function 1
     68    setPrototypeOf           reflectObjectSetPrototypeOf           DontEnum|Function 2
    6769@end
    6870*/
     
    115117        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.enumerate requires the first argument be an object")));
    116118    return JSValue::encode(JSPropertyNameIterator::create(exec, exec->lexicalGlobalObject()->propertyNameIteratorStructure(), asObject(target)));
     119}
     120
     121// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.getownpropertydescriptor
     122EncodedJSValue JSC_HOST_CALL reflectObjectGetOwnPropertyDescriptor(ExecState* exec)
     123{
     124    JSValue target = exec->argument(0);
     125    if (!target.isObject())
     126        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.getOwnPropertyDescriptor requires the first argument be an object")));
     127
     128    auto key = exec->argument(1).toPropertyKey(exec);
     129    if (exec->hadException())
     130        return JSValue::encode(jsUndefined());
     131
     132    return JSValue::encode(objectConstructorGetOwnPropertyDescriptor(exec, asObject(target), key));
    117133}
    118134
Note: See TracChangeset for help on using the changeset viewer.