mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 07:25:07 +00:00
LibJS/JIT: Support the EnterObjectEnvironment bytecode instruction
We can now use `with` statements in jitted code. :^)
This commit is contained in:
parent
cfdb8a2756
commit
cb7169d73f
4 changed files with 26 additions and 5 deletions
|
@ -444,6 +444,13 @@ void Interpreter::catch_exception()
|
||||||
vm().running_execution_context().lexical_environment = context.lexical_environment;
|
vm().running_execution_context().lexical_environment = context.lexical_environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Interpreter::enter_object_environment(Object& object)
|
||||||
|
{
|
||||||
|
auto& old_environment = vm().running_execution_context().lexical_environment;
|
||||||
|
saved_lexical_environment_stack().append(old_environment);
|
||||||
|
vm().running_execution_context().lexical_environment = new_object_environment(object, true, old_environment);
|
||||||
|
}
|
||||||
|
|
||||||
ThrowCompletionOr<NonnullRefPtr<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, FunctionKind kind, DeprecatedFlyString const& name)
|
ThrowCompletionOr<NonnullRefPtr<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, FunctionKind kind, DeprecatedFlyString const& name)
|
||||||
{
|
{
|
||||||
auto executable_result = Bytecode::Generator::generate(node, kind);
|
auto executable_result = Bytecode::Generator::generate(node, kind);
|
||||||
|
@ -743,11 +750,8 @@ ThrowCompletionOr<void> CreateLexicalEnvironment::execute_impl(Bytecode::Interpr
|
||||||
|
|
||||||
ThrowCompletionOr<void> EnterObjectEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
|
ThrowCompletionOr<void> EnterObjectEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
auto& vm = interpreter.vm();
|
auto object = TRY(interpreter.accumulator().to_object(interpreter.vm()));
|
||||||
auto& old_environment = vm.running_execution_context().lexical_environment;
|
interpreter.enter_object_environment(*object);
|
||||||
interpreter.saved_lexical_environment_stack().append(old_environment);
|
|
||||||
auto object = TRY(interpreter.accumulator().to_object(vm));
|
|
||||||
vm.running_execution_context().lexical_environment = new_object_environment(object, true, old_environment);
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,8 @@ public:
|
||||||
void leave_unwind_context();
|
void leave_unwind_context();
|
||||||
void catch_exception();
|
void catch_exception();
|
||||||
|
|
||||||
|
void enter_object_environment(Object&);
|
||||||
|
|
||||||
Executable& current_executable() { return *m_current_executable; }
|
Executable& current_executable() { return *m_current_executable; }
|
||||||
Executable const& current_executable() const { return *m_current_executable; }
|
Executable const& current_executable() const { return *m_current_executable; }
|
||||||
BasicBlock const& current_block() const { return *m_current_block; }
|
BasicBlock const& current_block() const { return *m_current_block; }
|
||||||
|
|
|
@ -1988,6 +1988,20 @@ void Compiler::compile_leave_lexical_environment(Bytecode::Op::LeaveLexicalEnvir
|
||||||
native_call((void*)cxx_leave_lexical_environment);
|
native_call((void*)cxx_leave_lexical_environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Value cxx_enter_object_environment(VM& vm, Value value)
|
||||||
|
{
|
||||||
|
auto object = TRY_OR_SET_EXCEPTION(value.to_object(vm));
|
||||||
|
vm.bytecode_interpreter().enter_object_environment(*object);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Compiler::compile_enter_object_environment(Bytecode::Op::EnterObjectEnvironment const&)
|
||||||
|
{
|
||||||
|
load_accumulator(ARG1);
|
||||||
|
native_call((void*)cxx_enter_object_environment);
|
||||||
|
check_exception();
|
||||||
|
}
|
||||||
|
|
||||||
static Value cxx_concat_string(VM& vm, Value lhs, Value rhs)
|
static Value cxx_concat_string(VM& vm, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
auto string = TRY_OR_SET_EXCEPTION(rhs.to_primitive_string(vm));
|
auto string = TRY_OR_SET_EXCEPTION(rhs.to_primitive_string(vm));
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
O(Catch, catch) \
|
O(Catch, catch) \
|
||||||
O(CreateLexicalEnvironment, create_lexical_environment) \
|
O(CreateLexicalEnvironment, create_lexical_environment) \
|
||||||
O(LeaveLexicalEnvironment, leave_lexical_environment) \
|
O(LeaveLexicalEnvironment, leave_lexical_environment) \
|
||||||
|
O(EnterObjectEnvironment, enter_object_environment) \
|
||||||
O(ToNumeric, to_numeric) \
|
O(ToNumeric, to_numeric) \
|
||||||
O(ResolveThisBinding, resolve_this_binding) \
|
O(ResolveThisBinding, resolve_this_binding) \
|
||||||
O(Return, return) \
|
O(Return, return) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue