mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +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>());
|
VERIFY(name.has<Empty>());
|
||||||
|
|
||||||
if (is_rest) {
|
if (is_rest) {
|
||||||
|
VERIFY(!initializer);
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
// The iterator has not been called, and is thus known to be not exhausted
|
// The iterator has not been called, and is thus known to be not exhausted
|
||||||
generator.emit<Bytecode::Op::Load>(iterator_reg);
|
generator.emit<Bytecode::Op::Load>(iterator_reg);
|
||||||
|
@ -1358,6 +1360,21 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
|
||||||
// pattern if necessary.
|
// pattern if necessary.
|
||||||
generator.switch_to_basic_block(create_binding_block);
|
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));
|
TRY(assign_accumulator_to_alias(alias));
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue