mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +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());
|
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 {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,6 @@ ThrowCompletionOr<Value> perform_call(Interpreter&, Value this_value, Op::CallTy
|
||||||
template<typename InstructionType>
|
template<typename InstructionType>
|
||||||
ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee);
|
ThrowCompletionOr<void> throw_if_needed_for_call(Interpreter&, InstructionType const&, Value callee);
|
||||||
ThrowCompletionOr<Value> typeof_variable(VM&, DeprecatedFlyString const&);
|
ThrowCompletionOr<Value> typeof_variable(VM&, DeprecatedFlyString const&);
|
||||||
|
ThrowCompletionOr<void> set_variable(VM&, DeprecatedFlyString const&, Value, Op::EnvironmentMode, Op::SetVariable::InitializationMode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -925,16 +925,7 @@ ThrowCompletionOr<void> SetVariable::execute_impl(Bytecode::Interpreter& interpr
|
||||||
{
|
{
|
||||||
auto& vm = interpreter.vm();
|
auto& vm = interpreter.vm();
|
||||||
auto const& name = interpreter.current_executable().get_identifier(m_identifier);
|
auto const& name = interpreter.current_executable().get_identifier(m_identifier);
|
||||||
auto environment = m_mode == EnvironmentMode::Lexical ? vm.running_execution_context().lexical_environment : vm.running_execution_context().variable_environment;
|
TRY(set_variable(vm, name, interpreter.accumulator(), m_mode, m_initialization_mode));
|
||||||
auto reference = TRY(vm.resolve_binding(name, environment));
|
|
||||||
switch (m_initialization_mode) {
|
|
||||||
case InitializationMode::Initialize:
|
|
||||||
TRY(reference.initialize_referenced_binding(vm, interpreter.accumulator()));
|
|
||||||
break;
|
|
||||||
case InitializationMode::Set:
|
|
||||||
TRY(reference.put_value(vm, interpreter.accumulator()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -428,6 +428,8 @@ public:
|
||||||
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
||||||
|
|
||||||
IdentifierTableIndex identifier() const { return m_identifier; }
|
IdentifierTableIndex identifier() const { return m_identifier; }
|
||||||
|
EnvironmentMode mode() const { return m_mode; }
|
||||||
|
InitializationMode initialization_mode() const { return m_initialization_mode; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IdentifierTableIndex m_identifier;
|
IdentifierTableIndex m_identifier;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue