1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:17:35 +00:00

LibJS: Use MarkedValueList for internal own properties getter functions

Letting these create and return a JS::Array directly is pretty awkward
since we then need to go through the indexed properties for iteration.
Just use a MarkedValueList (i.e. Vector<Value>) for this and add a new
Array::create_from() function to turn the Vector into a returnable
Array as we did before.

This brings it a lot closer to the spec as well, which uses the
CreateArrayFromList abstract operation to do exactly this.

There's an optimization opportunity for the future here, since we know
the Vector's size we could prepare the newly created Array accordingly,
e.g. by switching to generic storage upfront if needed.
This commit is contained in:
Linus Groh 2021-04-06 21:39:17 +02:00 committed by Andreas Kling
parent a42886d8ff
commit 1c3eef5317
7 changed files with 37 additions and 31 deletions

View file

@ -209,7 +209,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
if (vm.exception())
return {};
return obj_arg->get_enumerable_own_property_names(PropertyKind::Key);
return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::Key));
}
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
@ -222,7 +222,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
if (vm.exception())
return {};
return obj_arg->get_enumerable_own_property_names(PropertyKind::Value);
return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::Value));
}
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
@ -235,7 +235,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
if (vm.exception())
return {};
return obj_arg->get_enumerable_own_property_names(PropertyKind::KeyAndValue);
return Array::create_from(global_object, obj_arg->get_enumerable_own_property_names(PropertyKind::KeyAndValue));
}
}