Diff
Modified: trunk/JSTests/test262/config.yaml (281798 => 281799)
--- trunk/JSTests/test262/config.yaml 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/JSTests/test262/config.yaml 2021-08-31 12:48:14 UTC (rev 281799)
@@ -7,6 +7,7 @@
TypedArray.prototype.at: useAtMethod
String.prototype.at: useAtMethod
array-find-from-last: useArrayFindLastMethod
+ Object.hasOwn: useHasOwn
skip:
features:
- Atomics.waitAsync
@@ -14,7 +15,6 @@
- regexp-lookbehind
- cleanupSome
- resizable-arraybuffer
- - Object.hasOwn
- Temporal
- import-assertions
- json-modules
Modified: trunk/Source/_javascript_Core/ChangeLog (281798 => 281799)
--- trunk/Source/_javascript_Core/ChangeLog 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-08-31 12:48:14 UTC (rev 281799)
@@ -1,3 +1,28 @@
+2021-08-31 Aditi Singh <[email protected]>
+
+ Implement Object.hasOwn()
+ https://bugs.webkit.org/show_bug.cgi?id=226291
+
+ 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:
+
2021-08-26 Darin Adler <[email protected]>
Cut down on use of CFGetTypeID, using dynamic_cf_cast instead; related streamlining
Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (281798 => 281799)
--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp 2021-08-31 12:48:14 UTC (rev 281799)
@@ -2553,7 +2553,9 @@
JSString* propertyName = jsSecureCast<JSString*>(vm, JSValue::decode(propertyNameValue));
auto identifier = propertyName->toIdentifier(globalObject);
RETURN_IF_EXCEPTION(scope, { });
- RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, identifier))));
+ JSObject* baseObject = base.toObject(globalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+ RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseObject, identifier))));
}
JSC_DEFINE_JIT_OPERATION(operationNewRegexpWithLastIndex, JSCell*, (JSGlobalObject* globalObject, JSCell* regexpPtr, EncodedJSValue encodedLastIndex))
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2021-08-31 12:48:14 UTC (rev 281799)
@@ -133,6 +133,7 @@
macro(groups) \
macro(has) \
macro(hasIndices) \
+ macro(hasOwn) \
macro(hasOwnProperty) \
macro(hash) \
macro(header) \
Modified: trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/CommonSlowPaths.cpp 2021-08-31 12:48:14 UTC (rev 281799)
@@ -1092,7 +1092,9 @@
JSString* string = asString(GET(bytecode.m_propertyName).jsValue());
auto propertyName = string->toIdentifier(globalObject);
CHECK_EXCEPTION();
- RETURN(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseValue, propertyName)));
+ JSObject* baseObject = baseValue.toObject(globalObject);
+ CHECK_EXCEPTION();
+ RETURN(jsBoolean(objectPrototypeHasOwnProperty(globalObject, baseObject, propertyName)));
}
JSC_DEFINE_COMMON_SLOW_PATH(slow_path_profile_type_clear_log)
Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp 2021-08-31 12:48:14 UTC (rev 281799)
@@ -46,6 +46,7 @@
static JSC_DECLARE_HOST_FUNCTION(objectConstructorIsSealed);
static JSC_DECLARE_HOST_FUNCTION(objectConstructorIsFrozen);
static JSC_DECLARE_HOST_FUNCTION(objectConstructorIsExtensible);
+static JSC_DECLARE_HOST_FUNCTION(objectConstructorHasOwn);
}
@@ -100,6 +101,8 @@
JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().createPrivateName(), objectConstructorCreate, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().definePropertyPrivateName(), objectConstructorDefineProperty, static_cast<unsigned>(PropertyAttribute::DontEnum), 3);
+ if (Options::useHasOwn())
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->hasOwn, objectConstructorHasOwn, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
}
// ES 19.1.1.1 Object([value])
@@ -1011,4 +1014,15 @@
return result;
}
+JSC_DEFINE_HOST_FUNCTION(objectConstructorHasOwn, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+ VM& vm = globalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ JSObject* base = callFrame->argument(0).toObject(globalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+ auto propertyName = callFrame->argument(1).toPropertyKey(globalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+ RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, propertyName))));
+}
+
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp 2021-08-31 12:48:14 UTC (rev 281799)
@@ -89,16 +89,10 @@
return JSValue::encode(valueObj);
}
-bool objectPrototypeHasOwnProperty(JSGlobalObject* globalObject, JSValue base, const Identifier& propertyName)
+bool objectPrototypeHasOwnProperty(JSGlobalObject* globalObject, JSObject* thisObject, const Identifier& propertyName)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- JSValue thisValue = base.toThis(globalObject, ECMAMode::strict());
- JSObject* thisObject = thisValue.toObject(globalObject);
- EXCEPTION_ASSERT(!!scope.exception() == !thisObject);
- if (UNLIKELY(!thisObject))
- return false;
-
Structure* structure = thisObject->structure(vm);
HasOwnPropertyCache* hasOwnPropertyCache = vm.ensureHasOwnPropertyCache();
if (std::optional<bool> result = hasOwnPropertyCache->get(structure, propertyName)) {
@@ -123,8 +117,9 @@
JSValue base = callFrame->thisValue();
auto propertyName = callFrame->argument(0).toPropertyKey(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
- scope.release();
- return JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, base, propertyName)));
+ JSObject* thisObject = base.toThis(globalObject, ECMAMode::strict()).toObject(globalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+ RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(objectPrototypeHasOwnProperty(globalObject, thisObject, propertyName))));
}
JSC_DEFINE_HOST_FUNCTION(objectProtoFuncIsPrototypeOf, (JSGlobalObject* globalObject, CallFrame* callFrame))
Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.h (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.h 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.h 2021-08-31 12:48:14 UTC (rev 281799)
@@ -52,6 +52,6 @@
JS_EXPORT_PRIVATE JSC_DECLARE_HOST_FUNCTION(objectProtoFuncToString);
JSString* objectPrototypeToString(JSGlobalObject*, JSValue thisValue);
-bool objectPrototypeHasOwnProperty(JSGlobalObject*, JSValue base, const Identifier& property);
+bool objectPrototypeHasOwnProperty(JSGlobalObject*, JSObject* base, const Identifier& property);
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/OptionsList.h (281798 => 281799)
--- trunk/Source/_javascript_Core/runtime/OptionsList.h 2021-08-31 11:48:10 UTC (rev 281798)
+++ trunk/Source/_javascript_Core/runtime/OptionsList.h 2021-08-31 12:48:14 UTC (rev 281799)
@@ -542,6 +542,7 @@
v(Bool, useTemporal, false, Normal, "Expose the Temporal object.") \
v(Bool, useArrayFindLastMethod, true, Normal, "Expose the findLast() and findLastIndex() methods on Array and %TypedArray%.") \
v(Bool, useIntlEnumeration, true, Normal, "Expose the Intl enumeration APIs.") \
+ v(Bool, useHasOwn, false, Normal, "Expose the Object.hasOwn method") \
enum OptionEquivalence {