mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 01:15:07 +00:00
LibJS/Bytecode: Move CreateVariable impl to CommonImplementations
This commit is contained in:
parent
1d3062de9e
commit
54f1f7a51b
3 changed files with 28 additions and 27 deletions
|
@ -423,4 +423,30 @@ MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter& interpreter)
|
|||
return argument_values;
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> create_variable(VM& vm, DeprecatedFlyString const& name, Op::EnvironmentMode mode, bool is_global, bool is_immutable, bool is_strict)
|
||||
{
|
||||
if (mode == Op::EnvironmentMode::Lexical) {
|
||||
VERIFY(!is_global);
|
||||
|
||||
// Note: This is papering over an issue where "FunctionDeclarationInstantiation" creates these bindings for us.
|
||||
// Instead of crashing in there, we'll just raise an exception here.
|
||||
if (TRY(vm.lexical_environment()->has_binding(name)))
|
||||
return vm.throw_completion<InternalError>(TRY_OR_THROW_OOM(vm, String::formatted("Lexical environment already has binding '{}'", name)));
|
||||
|
||||
if (is_immutable)
|
||||
return vm.lexical_environment()->create_immutable_binding(vm, name, is_strict);
|
||||
return vm.lexical_environment()->create_mutable_binding(vm, name, is_strict);
|
||||
}
|
||||
|
||||
if (!is_global) {
|
||||
if (is_immutable)
|
||||
return vm.variable_environment()->create_immutable_binding(vm, name, is_strict);
|
||||
return vm.variable_environment()->create_mutable_binding(vm, name, is_strict);
|
||||
}
|
||||
|
||||
// NOTE: CreateVariable with m_is_global set to true is expected to only be used in GlobalDeclarationInstantiation currently, which only uses "false" for "can_be_deleted".
|
||||
// The only area that sets "can_be_deleted" to true is EvalDeclarationInstantiation, which is currently fully implemented in C++ and not in Bytecode.
|
||||
return verify_cast<GlobalEnvironment>(vm.variable_environment())->create_global_var_binding(name, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue