From aef831303360f330719f79e26d13f754e030445d Mon Sep 17 00:00:00 2001 From: Kai Tamkun Date: Tue, 29 Oct 2024 15:18:59 -0700 Subject: [PATCH 1/3] Add method to get own property names plus inherited property names --- .../runtime/ObjectConstructor.cpp | 18 ++++++++++++++++-- .../JavaScriptCore/runtime/ObjectConstructor.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp index 62bf8c34edc12..cdae48738c630 100644 --- a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp +++ b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp @@ -1240,7 +1240,7 @@ static CachedPropertyNamesKind inferCachedPropertyNamesKind(PropertyNameMode pro RELEASE_ASSERT_NOT_REACHED(); } -JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) +static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode, bool inherit) { VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); @@ -1262,7 +1262,11 @@ JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, Propert } PropertyNameArray properties(vm, propertyNameMode, PrivateSymbolMode::Exclude); - object->methodTable()->getOwnPropertyNames(object, globalObject, properties, dontEnumPropertiesMode); + if (inherit) { + object->getPropertyNames(globalObject, properties, dontEnumPropertiesMode); + } else { + object->methodTable()->getOwnPropertyNames(object, globalObject, properties, dontEnumPropertiesMode); + } RETURN_IF_EXCEPTION(scope, nullptr); size_t numProperties = properties.size(); @@ -1349,6 +1353,16 @@ JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, Propert return keys; } +JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) +{ + return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode, false); +} + +JSArray* allPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) +{ + return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode, true); +} + JSObject* constructObjectFromPropertyDescriptorSlow(JSGlobalObject* globalObject, const PropertyDescriptor& descriptor) { VM& vm = getVM(globalObject); diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.h b/Source/JavaScriptCore/runtime/ObjectConstructor.h index f85cb3f679b76..0331918f5325a 100644 --- a/Source/JavaScriptCore/runtime/ObjectConstructor.h +++ b/Source/JavaScriptCore/runtime/ObjectConstructor.h @@ -160,6 +160,7 @@ JS_EXPORT_PRIVATE JSObject* objectConstructorSeal(JSGlobalObject*, JSObject*); JSValue objectConstructorGetOwnPropertyDescriptor(JSGlobalObject*, JSObject*, const Identifier&); JSValue objectConstructorGetOwnPropertyDescriptors(JSGlobalObject*, JSObject*); JSArray* ownPropertyKeys(JSGlobalObject*, JSObject*, PropertyNameMode, DontEnumPropertiesMode); +JSArray* allPropertyKeys(JSGlobalObject*, JSObject*, PropertyNameMode, DontEnumPropertiesMode); bool toPropertyDescriptor(JSGlobalObject*, JSValue, PropertyDescriptor&); void objectAssignGeneric(JSGlobalObject*, VM&, JSObject* target, JSObject* source); JSValue objectValues(VM&, JSGlobalObject*, JSValue); From c7f338c25c1243961614824fa83ba5ec13d85cbe Mon Sep 17 00:00:00 2001 From: Kai Tamkun Date: Mon, 4 Nov 2024 17:02:32 -0800 Subject: [PATCH 2/3] Run CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eae990178e089..630cfe1169ac1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ env: on: # Triggers the workflow on push or pull request events but only for the "master" branch push: - branches: ["main"] + branches: ["main", "kai/inherited-property-names"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 12344672d12f3463311c01aa4168ba7254e86560 Mon Sep 17 00:00:00 2001 From: Kai Tamkun Date: Fri, 8 Nov 2024 17:39:47 -0800 Subject: [PATCH 3/3] Templatize getPropertyKeys --- Source/JavaScriptCore/runtime/ObjectConstructor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp index cdae48738c630..7bd8354e59a43 100644 --- a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp +++ b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp @@ -1240,7 +1240,8 @@ static CachedPropertyNamesKind inferCachedPropertyNamesKind(PropertyNameMode pro RELEASE_ASSERT_NOT_REACHED(); } -static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode, bool inherit) +template +static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) { VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); @@ -1262,7 +1263,7 @@ static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, } PropertyNameArray properties(vm, propertyNameMode, PrivateSymbolMode::Exclude); - if (inherit) { + if constexpr (Inherit) { object->getPropertyNames(globalObject, properties, dontEnumPropertiesMode); } else { object->methodTable()->getOwnPropertyNames(object, globalObject, properties, dontEnumPropertiesMode); @@ -1355,12 +1356,12 @@ static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) { - return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode, false); + return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode); } JSArray* allPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode) { - return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode, true); + return getPropertyKeys(globalObject, object, propertyNameMode, dontEnumPropertiesMode); } JSObject* constructObjectFromPropertyDescriptorSlow(JSGlobalObject* globalObject, const PropertyDescriptor& descriptor)