mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:05:08 +00:00
LibJS/Bytecode: Move SetVariable implementation to CommonImplementations
This commit is contained in:
parent
e946440ed3
commit
393d90abe1
4 changed files with 24 additions and 10 deletions
|
@ -244,4 +244,24 @@ ThrowCompletionOr<Value> typeof_variable(VM& vm, DeprecatedFlyString const& stri
|
|||
return PrimitiveString::create(vm, value.typeof());
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> set_variable(
|
||||
VM& vm,
|
||||
DeprecatedFlyString const& name,
|
||||
Value value,
|
||||
Op::EnvironmentMode mode,
|
||||
Op::SetVariable::InitializationMode initialization_mode)
|
||||
{
|
||||
auto environment = mode == Op::EnvironmentMode::Lexical ? vm.running_execution_context().lexical_environment : vm.running_execution_context().variable_environment;
|
||||
auto reference = TRY(vm.resolve_binding(name, environment));
|
||||
switch (initialization_mode) {
|
||||
case Op::SetVariable::InitializationMode::Initialize:
|
||||
TRY(reference.initialize_referenced_binding(vm, value));
|
||||
break;
|
||||
case Op::SetVariable::InitializationMode::Set:
|
||||
TRY(reference.put_value(vm, value));
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue