summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-03-14 12:44:01 +0000
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-03-14 21:15:27 +0330
commite517cb505a1b026fdca02167baaffee257ec6c91 (patch)
tree388564dc395e14e07e6dd7ae8e98666e8573ef61 /Userland
parent750b69540ef07b6a2ebdbb15f01bd87ee9b5938a (diff)
downloadserenity-e517cb505a1b026fdca02167baaffee257ec6c91.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 8202bc1f8f..795ae98e0e 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -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 {};
}