mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05: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:
parent
a42886d8ff
commit
1c3eef5317
7 changed files with 37 additions and 31 deletions
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/Function.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
|
@ -235,7 +236,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys)
|
|||
auto* target = get_target_object_from(global_object, "ownKeys");
|
||||
if (!target)
|
||||
return {};
|
||||
return target->get_own_properties(PropertyKind::Key);
|
||||
return Array::create_from(global_object, target->get_own_properties(PropertyKind::Key));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::prevent_extensions)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue