Changeset 281799 in webkit


Ignore:
Timestamp:
Aug 31, 2021 5:48:14 AM (11 months ago)
Author:
commit-queue@webkit.org
Message:

Implement Object.hasOwn()
https://bugs.webkit.org/show_bug.cgi?id=226291

Patch by Aditi Singh <asingh@igalia.com> on 2021-08-31
Reviewed by Alexey Shvayka.

This patch implements Object.hasOwn() method which is a stage 3 proposal. The method is disabled by default and can be enabled using the feature flag.
The proposal details can be found here: https://github.com/tc39/proposal-accessible-object-hasownproperty.
The patch also refines objectPrototypeHasOwnProperty() to accept JSObject* base rather than JSValue.

  • dfg/DFGOperations.cpp:

(JSC::DFG::JSC_DEFINE_JIT_OPERATION):

  • runtime/CommonIdentifiers.h:
  • runtime/CommonSlowPaths.cpp:

(JSC::JSC_DEFINE_COMMON_SLOW_PATH):

  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructor::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/ObjectPrototype.cpp:

(JSC::objectPrototypeHasOwnProperty):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/ObjectPrototype.h:
  • runtime/OptionsList.h:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/test262/config.yaml

    r281429 r281799  
    88  String.prototype.at: useAtMethod
    99  array-find-from-last: useArrayFindLastMethod
     10  Object.hasOwn: useHasOwn
    1011skip:
    1112  features:
     
    1516    - cleanupSome
    1617    - resizable-arraybuffer
    17     - Object.hasOwn
    1818    - Temporal
    1919    - import-assertions
  • trunk/Source/JavaScriptCore/ChangeLog

    r281791 r281799  
     12021-08-31  Aditi Singh  <asingh@igalia.com>
     2
     3        Implement Object.hasOwn()
     4        https://bugs.webkit.org/show_bug.cgi?id=226291
     5
     6        Reviewed by Alexey Shvayka.
     7       
     8        This patch implements Object.hasOwn() method which is a stage 3 proposal. The method is disabled by default and can be enabled using the feature flag.
     9        The proposal details can be found here: https://github.com/tc39/proposal-accessible-object-hasownproperty.
     10        The patch also refines objectPrototypeHasOwnProperty() to accept JSObject* base rather than JSValue.
     11
     12        * dfg/DFGOperations.cpp:
     13        (JSC::DFG::JSC_DEFINE_JIT_OPERATION):
     14        * runtime/CommonIdentifiers.h:
     15        * runtime/CommonSlowPaths.cpp:
     16        (JSC::JSC_DEFINE_COMMON_SLOW_PATH):
     17        * runtime/ObjectConstructor.cpp:
     18        (JSC::ObjectConstructor::finishCreation):
     19        (JSC::JSC_DEFINE_HOST_FUNCTION):
     20        * runtime/ObjectPrototype.cpp:
     21        (JSC::objectPrototypeHasOwnProperty):
     22        (JSC::JSC_DEFINE_HOST_FUNCTION):
     23        * runtime/ObjectPrototype.h:
     24        * runtime/OptionsList.h:
     25
    1262021-08-26  Darin Adler  <darin@apple.com>
    227
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r281500 r281799  
    25542554    auto identifier = propertyName->toIdentifier(globalObject);
    25552555    RETURN_IF_EXCEPTION(scope, { });
    2556     RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, identifier))));
     2556    JSObject* baseObject = base.toObject(globalObject);
     2557    RETURN_IF_EXCEPTION(scope, { });
     2558    RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseObject, identifier))));
    25572559}
    25582560
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r281788 r281799  
    134134    macro(has) \
    135135    macro(hasIndices) \
     136    macro(hasOwn) \
    136137    macro(hasOwnProperty) \
    137138    macro(hash) \
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp

    r280760 r281799  
    10931093    auto propertyName = string->toIdentifier(globalObject);
    10941094    CHECK_EXCEPTION();
    1095     RETURN(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseValue, propertyName)));
     1095    JSObject* baseObject = baseValue.toObject(globalObject);
     1096    CHECK_EXCEPTION();
     1097    RETURN(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseObject, propertyName)));
    10961098}
    10971099
  • trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

    r279690 r281799  
    4747static JSC_DECLARE_HOST_FUNCTION(objectConstructorIsFrozen);
    4848static JSC_DECLARE_HOST_FUNCTION(objectConstructorIsExtensible);
     49static JSC_DECLARE_HOST_FUNCTION(objectConstructorHasOwn);
    4950
    5051}
     
    101102    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().createPrivateName(), objectConstructorCreate, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
    102103    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().definePropertyPrivateName(), objectConstructorDefineProperty, static_cast<unsigned>(PropertyAttribute::DontEnum), 3);
     104    if (Options::useHasOwn())
     105        JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->hasOwn, objectConstructorHasOwn, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
    103106}
    104107
     
    10121015}
    10131016
     1017JSC_DEFINE_HOST_FUNCTION(objectConstructorHasOwn, (JSGlobalObject* globalObject, CallFrame* callFrame))
     1018{
     1019    VM& vm = globalObject->vm();
     1020    auto scope = DECLARE_THROW_SCOPE(vm);
     1021    JSObject* base = callFrame->argument(0).toObject(globalObject);
     1022    RETURN_IF_EXCEPTION(scope, { });
     1023    auto propertyName = callFrame->argument(1).toPropertyKey(globalObject);
     1024    RETURN_IF_EXCEPTION(scope, { });
     1025    RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, propertyName))));
     1026}
     1027
    10141028} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/ObjectPrototype.cpp

    r278888 r281799  
    9090}
    9191
    92 bool objectPrototypeHasOwnProperty(JSGlobalObject* globalObject, JSValue base, const Identifier& propertyName)
    93 {
    94     VM& vm = globalObject->vm();
    95     auto scope = DECLARE_THROW_SCOPE(vm);
    96     JSValue thisValue = base.toThis(globalObject, ECMAMode::strict());
    97     JSObject* thisObject = thisValue.toObject(globalObject);
    98     EXCEPTION_ASSERT(!!scope.exception() == !thisObject);
    99     if (UNLIKELY(!thisObject))
    100         return false;
    101 
     92bool objectPrototypeHasOwnProperty(JSGlobalObject* globalObject, JSObject* thisObject, const Identifier& propertyName)
     93{
     94    VM& vm = globalObject->vm();
     95    auto scope = DECLARE_THROW_SCOPE(vm);
    10296    Structure* structure = thisObject->structure(vm);
    10397    HasOwnPropertyCache* hasOwnPropertyCache = vm.ensureHasOwnPropertyCache();
     
    124118    auto propertyName = callFrame->argument(0).toPropertyKey(globalObject);
    125119    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    126     scope.release();
    127     return JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, propertyName)));
     120    JSObject* thisObject = base.toThis(globalObject, ECMAMode::strict()).toObject(globalObject);
     121    RETURN_IF_EXCEPTION(scope, { });
     122    RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, thisObject, propertyName))));
    128123}
    129124
  • trunk/Source/JavaScriptCore/runtime/ObjectPrototype.h

    r275544 r281799  
    5353JS_EXPORT_PRIVATE JSC_DECLARE_HOST_FUNCTION(objectProtoFuncToString);
    5454JSString* objectPrototypeToString(JSGlobalObject*, JSValue thisValue);
    55 bool objectPrototypeHasOwnProperty(JSGlobalObject*, JSValue base, const Identifier& property);
     55bool objectPrototypeHasOwnProperty(JSGlobalObject*, JSObject* base, const Identifier& property);
    5656
    5757} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r281693 r281799  
    543543    v(Bool, useArrayFindLastMethod, true, Normal, "Expose the findLast() and findLastIndex() methods on Array and %TypedArray%.") \
    544544    v(Bool, useIntlEnumeration, true, Normal, "Expose the Intl enumeration APIs.") \
     545    v(Bool, useHasOwn, false, Normal, "Expose the Object.hasOwn method") \
    545546
    546547
Note: See TracChangeset for help on using the changeset viewer.