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

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

Reviewed by Geoffrey Garen.

This patch implements Reflect.get API.
It can take the receiver object as the third argument.
When the receiver is specified and there's a getter for the given property name,
we call the getter with the receiver as the |this| value.

  • runtime/ReflectObject.cpp:

(JSC::reflectObjectGet):

  • runtime/SparseArrayValueMap.cpp:

(JSC::SparseArrayEntry::get): Deleted.

  • runtime/SparseArrayValueMap.h:
  • tests/stress/reflect-get.js: Added.

(shouldBe):
(shouldThrow):
(.get shouldThrow):
(.get var):
(get var.object.get hello):
(.get shouldBe):
(get var.object.set hello):

File:
1 edited

Legend:

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

    r188529 r188532  
    3737static EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState*);
    3838static EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState*);
     39static EncodedJSValue JSC_HOST_CALL reflectObjectGet(ExecState*);
    3940static EncodedJSValue JSC_HOST_CALL reflectObjectGetOwnPropertyDescriptor(ExecState*);
    4041static EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState*);
     
    6061    deleteProperty           reflectObjectDeleteProperty           DontEnum|Function 2
    6162    enumerate                reflectObjectEnumerate                DontEnum|Function 1
     63    get                      reflectObjectGet                      DontEnum|Function 2
    6264    getOwnPropertyDescriptor reflectObjectGetOwnPropertyDescriptor DontEnum|Function 2
    6365    getPrototypeOf           reflectObjectGetPrototypeOf           DontEnum|Function 1
     
    119121}
    120122
     123// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.get
     124EncodedJSValue JSC_HOST_CALL reflectObjectGet(ExecState* exec)
     125{
     126    JSValue target = exec->argument(0);
     127    if (!target.isObject())
     128        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.get requires the first argument be an object")));
     129
     130    const Identifier propertyName = exec->argument(1).toPropertyKey(exec);
     131    if (exec->hadException())
     132        return JSValue::encode(jsNull());
     133
     134    JSValue receiver = target;
     135    if (exec->argumentCount() >= 3)
     136        receiver = exec->argument(2);
     137
     138    PropertySlot slot(receiver);
     139    return JSValue::encode(target.get(exec, propertyName, slot));
     140}
     141
    121142// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.getownpropertydescriptor
    122143EncodedJSValue JSC_HOST_CALL reflectObjectGetOwnPropertyDescriptor(ExecState* exec)
Note: See TracChangeset for help on using the changeset viewer.