Skip to content

Commit

Permalink
Merge pull request #68 from oven-sh/kai/inherited-property-names
Browse files Browse the repository at this point in the history
Add method to get own property names plus inherited property names
  • Loading branch information
Jarred-Sumner authored Nov 9, 2024
2 parents c402bba + 79430de commit 3bc4abf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Source/JavaScriptCore/runtime/ObjectConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,8 @@ static CachedPropertyNamesKind inferCachedPropertyNamesKind(PropertyNameMode pro
RELEASE_ASSERT_NOT_REACHED();
}

JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode)
template <bool Inherit>
static JSArray* getPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Expand All @@ -1262,7 +1263,11 @@ JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, Propert
}

PropertyNameArray properties(vm, propertyNameMode, PrivateSymbolMode::Exclude);
object->methodTable()->getOwnPropertyNames(object, globalObject, properties, dontEnumPropertiesMode);
if constexpr (Inherit) {
object->getPropertyNames(globalObject, properties, dontEnumPropertiesMode);
} else {
object->methodTable()->getOwnPropertyNames(object, globalObject, properties, dontEnumPropertiesMode);
}
RETURN_IF_EXCEPTION(scope, nullptr);

size_t numProperties = properties.size();
Expand Down Expand Up @@ -1349,6 +1354,16 @@ JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, Propert
return keys;
}

JSArray* ownPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode)
{
return getPropertyKeys<false>(globalObject, object, propertyNameMode, dontEnumPropertiesMode);
}

JSArray* allPropertyKeys(JSGlobalObject* globalObject, JSObject* object, PropertyNameMode propertyNameMode, DontEnumPropertiesMode dontEnumPropertiesMode)
{
return getPropertyKeys<true>(globalObject, object, propertyNameMode, dontEnumPropertiesMode);
}

JSObject* constructObjectFromPropertyDescriptorSlow(JSGlobalObject* globalObject, const PropertyDescriptor& descriptor)
{
VM& vm = getVM(globalObject);
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/ObjectConstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3bc4abf

Please sign in to comment.