mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibJS/Bytecode: Implement var/lexical binding destructuring in for/of
This commit is contained in:
parent
64cfe2b163
commit
758a4cb1a6
Notes:
sideshowbarker
2024-07-17 03:35:25 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/758a4cb1a6 Pull-request: https://github.com/SerenityOS/serenity/pull/16400 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg ✅
1 changed files with 22 additions and 10 deletions
|
@ -2273,13 +2273,13 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
|
|||
auto destructuring = head_result.is_destructuring;
|
||||
|
||||
// 5. If destructuring is true and if lhsKind is assignment, then
|
||||
if (destructuring) {
|
||||
if (destructuring && head_result.lhs_kind == LHSKind::Assignment) {
|
||||
// a. Assert: lhs is a LeftHandSideExpression.
|
||||
// b. Let assignmentPattern be the AssignmentPattern that is covered by lhs.
|
||||
// FIXME: Implement this.
|
||||
return Bytecode::CodeGenerationError {
|
||||
&node,
|
||||
"Unimplemented: destructuring in for-in/of"sv,
|
||||
"Unimplemented: assignment destructuring in for/of"sv,
|
||||
};
|
||||
}
|
||||
// 6. Repeat,
|
||||
|
@ -2326,7 +2326,9 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
|
|||
TRY(generator.emit_store_to_reference(**ptr));
|
||||
} else {
|
||||
auto& binding_pattern = lhs.get<NonnullRefPtr<BindingPattern>>();
|
||||
TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Register::accumulator()));
|
||||
auto value_register = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Store>(value_register);
|
||||
TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, Bytecode::Op::SetVariable::InitializationMode::Set, value_register));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2386,9 +2388,9 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
|
|||
}
|
||||
// j. Else,
|
||||
else {
|
||||
// FIXME: Implement destructuring
|
||||
// i. If lhsKind is assignment, then
|
||||
// 1. Let status be Completion(DestructuringAssignmentEvaluation of assignmentPattern with argument nextValue).
|
||||
// FIXME: i. If lhsKind is assignment, then
|
||||
// 1. Let status be Completion(DestructuringAssignmentEvaluation of assignmentPattern with argument nextValue).
|
||||
|
||||
// ii. Else if lhsKind is varBinding, then
|
||||
// 1. Assert: lhs is a ForBinding.
|
||||
// 2. Let status be Completion(BindingInitialization of lhs with arguments nextValue and undefined).
|
||||
|
@ -2396,10 +2398,20 @@ static Bytecode::CodeGenerationErrorOr<void> for_in_of_body_evaluation(Bytecode:
|
|||
// 1. Assert: lhsKind is lexicalBinding.
|
||||
// 2. Assert: lhs is a ForDeclaration.
|
||||
// 3. Let status be Completion(ForDeclarationBindingInitialization of lhs with arguments nextValue and iterationEnv).
|
||||
return Bytecode::CodeGenerationError {
|
||||
&node,
|
||||
"Unimplemented: destructuring in for-in/of"sv,
|
||||
};
|
||||
if (head_result.lhs_kind == LHSKind::VarBinding || head_result.lhs_kind == LHSKind::LexicalBinding) {
|
||||
auto& declaration = static_cast<VariableDeclaration const&>(*lhs.get<NonnullRefPtr<ASTNode>>());
|
||||
VERIFY(declaration.declarations().size() == 1);
|
||||
auto& binding_pattern = declaration.declarations().first().target().get<NonnullRefPtr<BindingPattern>>();
|
||||
|
||||
auto value_register = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Store>(value_register);
|
||||
TRY(generate_binding_pattern_bytecode(generator, *binding_pattern, head_result.lhs_kind == LHSKind::VarBinding ? Bytecode::Op::SetVariable::InitializationMode::Set : Bytecode::Op::SetVariable::InitializationMode::Initialize, value_register));
|
||||
} else {
|
||||
return Bytecode::CodeGenerationError {
|
||||
&node,
|
||||
"Unimplemented: assignment destructuring in for/of"sv,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Implement iteration closure.
|
||||
|
|
Loading…
Reference in a new issue