Changeset 196040 in webkit


Ignore:
Timestamp:
Feb 2, 2016 7:17:53 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[JSC] Implement Object.getOwnPropertyDescriptors() proposal
https://bugs.webkit.org/show_bug.cgi?id=153799

Patch by Caitlin Potter <caitp@igalia.com> on 2016-02-02
Reviewed by Darin Adler.

Source/JavaScriptCore:

Implements the Object.getOwnPropertyDescriptors() proposal, which
reached Stage 3 in the TC39 process in January 2016.
https://github.com/tc39/proposal-object-getownpropertydescriptors

The method extracts a set of property descriptor objects, which can
be safely used via Object.create().

  • runtime/ObjectConstructor.cpp:

(JSC::objectConstructorGetOwnPropertyDescriptors):

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/script-tests/Object-getOwnPropertyNames.js:
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r196038 r196040  
     12016-02-02  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] Implement Object.getOwnPropertyDescriptors() proposal
     4        https://bugs.webkit.org/show_bug.cgi?id=153799
     5
     6        Reviewed by Darin Adler.
     7
     8        * js/Object-getOwnPropertyNames-expected.txt:
     9        * js/script-tests/Object-getOwnPropertyNames.js:
     10
    1112016-02-02  Brady Eidson  <beidson@apple.com>
    212
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r195460 r196040  
    4242PASS getSortedOwnPropertyNames(encodeURI) is ['length', 'name']
    4343PASS getSortedOwnPropertyNames(encodeURIComponent) is ['length', 'name']
    44 PASS getSortedOwnPropertyNames(Object) is ['assign', 'create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf']
     44PASS getSortedOwnPropertyNames(Object) is ['assign', 'create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf']
    4545PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']
    4646PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r195460 r196040  
    5151    "encodeURIComponent": "['length', 'name']",
    5252// Built-in ECMA objects
    53     "Object": "['assign', 'create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf']",
     53    "Object": "['assign', 'create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf']",
    5454    "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']",
    5555    "Function": "['length', 'name', 'prototype']",
  • trunk/Source/JavaScriptCore/ChangeLog

    r196035 r196040  
     12016-02-02  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] Implement Object.getOwnPropertyDescriptors() proposal
     4        https://bugs.webkit.org/show_bug.cgi?id=153799
     5
     6        Reviewed by Darin Adler.
     7
     8        Implements the Object.getOwnPropertyDescriptors() proposal, which
     9        reached Stage 3 in the TC39 process in January 2016.
     10        https://github.com/tc39/proposal-object-getownpropertydescriptors
     11
     12        The method extracts a set of property descriptor objects, which can
     13        be safely used via `Object.create()`.
     14
     15        * runtime/ObjectConstructor.cpp:
     16        (JSC::objectConstructorGetOwnPropertyDescriptors):
     17
    1182016-02-02  Filip Pizlo  <fpizlo@apple.com>
    219
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

    r195528 r196040  
    6969  setPrototypeOf            objectConstructorSetPrototypeOf             DontEnum|Function 2
    7070  getOwnPropertyDescriptor  objectConstructorGetOwnPropertyDescriptor   DontEnum|Function 2
     71  getOwnPropertyDescriptors objectConstructorGetOwnPropertyDescriptors  DontEnum|Function 1
    7172  getOwnPropertyNames       objectConstructorGetOwnPropertyNames        DontEnum|Function 1
    7273  keys                      objectConstructorKeys                       DontEnum|Function 1
     
    248249}
    249250
     251JSValue objectConstructorGetOwnPropertyDescriptors(ExecState* exec, JSObject* object)
     252{
     253    PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols);
     254    object->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include));
     255    if (exec->hadException())
     256        return jsUndefined();
     257
     258    JSObject* descriptors = constructEmptyObject(exec);
     259
     260    for (auto& propertyName : properties) {
     261        JSValue fromDescriptor = objectConstructorGetOwnPropertyDescriptor(exec, object, propertyName);
     262        if (exec->hadException())
     263            return jsUndefined();
     264
     265        descriptors->putDirect(exec->vm(), propertyName, fromDescriptor, 0);
     266    }
     267
     268    return descriptors;
     269}
     270
    250271EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec)
    251272{
     
    257278        return JSValue::encode(jsUndefined());
    258279    return JSValue::encode(objectConstructorGetOwnPropertyDescriptor(exec, object, propertyName));
     280}
     281
     282EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptors(ExecState* exec)
     283{
     284    JSObject* object = exec->argument(0).toObject(exec);
     285    if (exec->hadException())
     286        return JSValue::encode(jsUndefined());
     287    return JSValue::encode(objectConstructorGetOwnPropertyDescriptors(exec, object));
    259288}
    260289
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h

    r188529 r196040  
    2929
    3030EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*);
     31EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptors(ExecState*);
    3132EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertySymbols(ExecState*);
    3233EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*);
     
    9495JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*);
    9596JSValue objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, const Identifier&);
     97JSValue objectConstructorGetOwnPropertyDescriptors(ExecState*, JSObject*);
    9698JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
    9799bool toPropertyDescriptor(ExecState*, JSValue, PropertyDescriptor&);
  • trunk/Source/JavaScriptCore/tests/es6.yaml

    r196033 r196040  
    12171217- path: es6/well-known_symbols_Symbol.toStringTag_misc._built-ins.js
    12181218  cmd: runES6 :normal
     1219# Late-stage proposals for a future ECMAScript standard
     1220# FIXME: move these to a new directory?
     1221- path: es6/Object_static_methods_Object.getOwnPropertyDescriptors.js
     1222  cmd: runES6 :normal
     1223- path: es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js
     1224  cmd: runES6 :fail
Note: See TracChangeset for help on using the changeset viewer.