mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibJS/Bytecode: Leave FunctionDeclarationInstantantiation in C++
Instead of trying to implement this AO in bytecode, we can just let it be a C++ thing. Once we implement fast uncaptured locals, we won't even be calling it super often.
This commit is contained in:
parent
17fe2c4822
commit
872d798951
2 changed files with 11 additions and 50 deletions
|
@ -247,44 +247,7 @@ Bytecode::CodeGenerationErrorOr<void> ScopeNode::generate_bytecode(Bytecode::Gen
|
||||||
generator.emit<Bytecode::Op::CreateVariable>(index, Bytecode::Op::EnvironmentMode::Var, false, true);
|
generator.emit<Bytecode::Op::CreateVariable>(index, Bytecode::Op::EnvironmentMode::Var, false, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Perform the steps of FunctionDeclarationInstantiation.
|
// FunctionDeclarationInstantiation is handled by the C++ AO.
|
||||||
generator.begin_variable_scope(Bytecode::Generator::BindingMode::Var, Bytecode::Generator::SurroundingScopeKind::Function);
|
|
||||||
pushed_scope_count++;
|
|
||||||
if (has_lexical_declarations()) {
|
|
||||||
generator.begin_variable_scope(Bytecode::Generator::BindingMode::Lexical, Bytecode::Generator::SurroundingScopeKind::Function);
|
|
||||||
pushed_scope_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Implement this boi correctly.
|
|
||||||
(void)for_each_lexically_scoped_declaration([&](Declaration const& declaration) -> ThrowCompletionOr<void> {
|
|
||||||
auto is_constant_declaration = declaration.is_constant_declaration();
|
|
||||||
// NOTE: Nothing in the callback throws an exception.
|
|
||||||
MUST(declaration.for_each_bound_name([&](auto const& name) {
|
|
||||||
auto index = generator.intern_identifier(name);
|
|
||||||
if (is_constant_declaration || !generator.has_binding(index)) {
|
|
||||||
generator.register_binding(index);
|
|
||||||
generator.emit<Bytecode::Op::CreateVariable>(index, Bytecode::Op::EnvironmentMode::Lexical, is_constant_declaration);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (is<FunctionDeclaration>(declaration)) {
|
|
||||||
auto& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
|
|
||||||
if (auto result = function_declaration.generate_bytecode(generator); result.is_error()) {
|
|
||||||
maybe_error = result.release_error();
|
|
||||||
// To make `for_each_lexically_scoped_declaration` happy.
|
|
||||||
return failing_completion;
|
|
||||||
}
|
|
||||||
auto const& name = function_declaration.name();
|
|
||||||
auto index = generator.intern_identifier(name);
|
|
||||||
if (!generator.has_binding(index)) {
|
|
||||||
generator.register_binding(index);
|
|
||||||
generator.emit<Bytecode::Op::CreateVariable>(index, Bytecode::Op::EnvironmentMode::Lexical, false);
|
|
||||||
}
|
|
||||||
generator.emit<Bytecode::Op::SetVariable>(index, Bytecode::Op::SetVariable::InitializationMode::InitializeOrSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maybe_error.has_value())
|
if (maybe_error.has_value())
|
||||||
|
|
|
@ -573,19 +573,17 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
||||||
if (!scope_body)
|
if (!scope_body)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (!Bytecode::Interpreter::current()) {
|
// NOTE: Due to the use of MUST in the callback, an exception should not result from `for_each_lexically_scoped_declaration`.
|
||||||
// NOTE: Due to the use of MUST in the callback, an exception should not result from `for_each_lexically_scoped_declaration`.
|
MUST(scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
|
||||||
MUST(scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
|
// NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below,
|
||||||
// NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below,
|
// an exception should not result from `for_each_bound_name`.
|
||||||
// an exception should not result from `for_each_bound_name`.
|
MUST(declaration.for_each_bound_name([&](auto const& name) {
|
||||||
MUST(declaration.for_each_bound_name([&](auto const& name) {
|
if (declaration.is_constant_declaration())
|
||||||
if (declaration.is_constant_declaration())
|
MUST(lex_environment->create_immutable_binding(vm, name, true));
|
||||||
MUST(lex_environment->create_immutable_binding(vm, name, true));
|
else
|
||||||
else
|
MUST(lex_environment->create_mutable_binding(vm, name, false));
|
||||||
MUST(lex_environment->create_mutable_binding(vm, name, false));
|
|
||||||
}));
|
|
||||||
}));
|
}));
|
||||||
}
|
}));
|
||||||
|
|
||||||
auto private_environment = callee_context.private_environment;
|
auto private_environment = callee_context.private_environment;
|
||||||
for (auto& declaration : functions_to_initialize) {
|
for (auto& declaration : functions_to_initialize) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue