summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-07-17 19:25:23 +0100
committerLinus Groh <mail@linusgroh.de>2022-07-18 09:00:21 +0100
commitfe2efbb2fc816263e3e6d5d51e9edc70179348ba (patch)
tree3ff3ad86aeeba442934b4a71ce5fb3270c2fffb9 /Userland
parent0151dc562ad7db010e03bb6f40fade933f547c9a (diff)
downloadserenity-fe2efbb2fc816263e3e6d5d51e9edc70179348ba.zip
LibJS/Bytecode: Implement initializers for array binding patterns
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index 4201467660..5a4e8dd37f 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -1270,6 +1270,8 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
VERIFY(name.has<Empty>());
if (is_rest) {
+ VERIFY(!initializer);
+
if (first) {
// The iterator has not been called, and is thus known to be not exhausted
generator.emit<Bytecode::Op::Load>(iterator_reg);
@@ -1358,6 +1360,21 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
// pattern if necessary.
generator.switch_to_basic_block(create_binding_block);
+ if (initializer) {
+ auto& value_is_undefined_block = generator.make_block();
+ auto& value_is_not_undefined_block = generator.make_block();
+
+ generator.emit<Bytecode::Op::JumpUndefined>().set_targets(
+ Bytecode::Label { value_is_undefined_block },
+ Bytecode::Label { value_is_not_undefined_block });
+
+ generator.switch_to_basic_block(value_is_undefined_block);
+ TRY(initializer->generate_bytecode(generator));
+ generator.emit<Bytecode::Op::Jump>(Bytecode::Label { value_is_not_undefined_block });
+
+ generator.switch_to_basic_block(value_is_not_undefined_block);
+ }
+
TRY(assign_accumulator_to_alias(alias));
first = false;