mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
LibJS/Bytecode: Make NewArray write directly to indexed properties
This follows how the regular AST interpreter creates arrays, as using Array::create_from uses create_data_property_or_throw, which will crash when it encounters an empty value. We require empty values to represent array holes.
This commit is contained in:
parent
750b69540e
commit
e517cb505a
1 changed files with 6 additions and 5 deletions
|
@ -127,11 +127,12 @@ ThrowCompletionOr<void> NewBigInt::execute_impl(Bytecode::Interpreter& interpret
|
|||
|
||||
ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
Vector<Value> elements;
|
||||
elements.ensure_capacity(m_element_count);
|
||||
for (size_t i = 0; i < m_element_count; i++)
|
||||
elements.append(interpreter.reg(m_elements[i]));
|
||||
interpreter.accumulator() = Array::create_from(interpreter.global_object(), elements);
|
||||
auto* array = MUST(Array::create(interpreter.global_object(), 0));
|
||||
for (size_t i = 0; i < m_element_count; i++) {
|
||||
auto& value = interpreter.reg(m_elements[i]);
|
||||
array->indexed_properties().put(i, value, default_attributes);
|
||||
}
|
||||
interpreter.accumulator() = array;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue