mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:48:11 +00:00
LibJS/Bytecode: Implement initializers for array binding patterns
This commit is contained in:
parent
0151dc562a
commit
fe2efbb2fc
1 changed files with 17 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue