Changeset 188361 in webkit


Ignore:
Timestamp:
Aug 12, 2015, 3:59:05 PM (10 years ago)
Author:
Yusuke Suzuki
Message:

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

Reviewed by Saam Barati.

This patch implements Reflect.defineProperty.
The difference from the Object.defineProperty is,

  1. Reflect.defineProperty does not perform ToObject operation onto the first argument.
  2. Reflect.defineProperty does not throw a TypeError when the DefineOwnProperty operation fails.
  3. Reflect.defineProperty returns the boolean value that represents whether DefineOwnProperty succeeded.

And this patch comments the links to the ES6 spec.

  • builtins/ReflectObject.js:
  • runtime/ObjectConstructor.cpp:

(JSC::toPropertyDescriptor):

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

(JSC::reflectObjectDefineProperty):

  • tests/stress/reflect-define-property.js: Added.

(shouldBe):
(shouldThrow):
(.set getter):
(setter):
(.get testDescriptor):
(.set get var):
(.set testDescriptor):
(.set get testDescriptor):
(.set get shouldThrow):
(.get var):

Location:
trunk/Source/JavaScriptCore
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r188357 r188361  
     12015-08-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [ES6] Implement Reflect.defineProperty
     4        https://bugs.webkit.org/show_bug.cgi?id=147943
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch implements Reflect.defineProperty.
     9        The difference from the Object.defineProperty is,
     10
     11        1. Reflect.defineProperty does not perform ToObject operation onto the first argument.
     12        2. Reflect.defineProperty does not throw a TypeError when the [[DefineOwnProperty]] operation fails.
     13        3. Reflect.defineProperty returns the boolean value that represents whether [[DefineOwnProperty]] succeeded.
     14
     15        And this patch comments the links to the ES6 spec.
     16
     17        * builtins/ReflectObject.js:
     18        * runtime/ObjectConstructor.cpp:
     19        (JSC::toPropertyDescriptor):
     20        * runtime/ObjectConstructor.h:
     21        * runtime/ReflectObject.cpp:
     22        (JSC::reflectObjectDefineProperty):
     23        * tests/stress/reflect-define-property.js: Added.
     24        (shouldBe):
     25        (shouldThrow):
     26        (.set getter):
     27        (setter):
     28        (.get testDescriptor):
     29        (.set get var):
     30        (.set testDescriptor):
     31        (.set get testDescriptor):
     32        (.set get shouldThrow):
     33        (.get var):
     34
    1352015-08-12  Filip Pizlo  <fpizlo@apple.com>
    236
  • trunk/Source/JavaScriptCore/builtins/ReflectObject.js

    r188264 r188361  
    2424 */
    2525
     26// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.apply
    2627function apply(target, thisArgument, argumentsList)
    2728{
     
    3738}
    3839
     40// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.deleteproperty
    3941function deleteProperty(target, propertyKey)
    4042{
     
    4850}
    4951
     52// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.has
    5053function has(target, propertyKey)
    5154{
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

    r188262 r188361  
    287287
    288288// ES5 8.10.5 ToPropertyDescriptor
    289 static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
     289bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
    290290{
    291291    if (!in.isObject()) {
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h

    r188262 r188361  
    9494JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*);
    9595JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
     96bool toPropertyDescriptor(ExecState*, JSValue, PropertyDescriptor&);
    9697
    9798} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/ReflectObject.cpp

    r188264 r188361  
    3535namespace JSC {
    3636
     37static EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState*);
    3738static EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState*);
    3839static EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState*);
     
    5556@begin reflectObjectTable
    5657    apply             reflectObjectApply             DontEnum|Function 3
     58    defineProperty    reflectObjectDefineProperty    DontEnum|Function 3
    5759    deleteProperty    reflectObjectDeleteProperty    DontEnum|Function 2
    5860    enumerate         reflectObjectEnumerate         DontEnum|Function 1
     
    8486// ------------------------------ Functions --------------------------------
    8587
     88// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.defineproperty
     89EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState* exec)
     90{
     91    JSValue target = exec->argument(0);
     92    if (!target.isObject())
     93        return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.defineProperty requires the first argument be an object")));
     94    auto propertyName = exec->argument(1).toPropertyKey(exec);
     95    if (exec->hadException())
     96        return JSValue::encode(jsUndefined());
     97
     98    PropertyDescriptor descriptor;
     99    if (!toPropertyDescriptor(exec, exec->argument(2), descriptor))
     100        return JSValue::encode(jsUndefined());
     101    ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
     102    ASSERT(!exec->hadException());
     103
     104    // Reflect.defineProperty should not throw an error when the defineOwnProperty operation fails.
     105    bool shouldThrow = false;
     106    JSObject* targetObject = asObject(target);
     107    return JSValue::encode(jsBoolean(targetObject->methodTable(exec->vm())->defineOwnProperty(targetObject, exec, propertyName, descriptor, shouldThrow)));
     108}
     109
     110// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.enumerate
    86111EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState* exec)
    87112{
     
    92117}
    93118
     119// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.getprototypeof
    94120EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState* exec)
    95121{
     
    100126}
    101127
     128// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.isextensible
    102129EncodedJSValue JSC_HOST_CALL reflectObjectIsExtensible(ExecState* exec)
    103130{
     
    108135}
    109136
     137// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.ownkeys
    110138EncodedJSValue JSC_HOST_CALL reflectObjectOwnKeys(ExecState* exec)
    111139{
     
    116144}
    117145
     146// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.preventextensions
    118147EncodedJSValue JSC_HOST_CALL reflectObjectPreventExtensions(ExecState* exec)
    119148{
     
    125154}
    126155
     156// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.setprototypeof
    127157EncodedJSValue JSC_HOST_CALL reflectObjectSetPrototypeOf(ExecState* exec)
    128158{
Note: See TracChangeset for help on using the changeset viewer.