1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 02:48:11 +00:00

LibJS: Expose some information about the bytecode interpreters state

This is quite helpful, when reporting internal errors.
This commit is contained in:
Hendiadyoin1 2022-10-30 11:58:46 +01:00 committed by Andreas Kling
parent 937fcfc75c
commit a1f1d9e4a7
2 changed files with 11 additions and 5 deletions

View file

@ -61,7 +61,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
pushed_execution_context = true; pushed_execution_context = true;
} }
auto block = entry_point ?: &executable.basic_blocks.first(); m_current_block = entry_point ?: &executable.basic_blocks.first();
if (in_frame) if (in_frame)
m_register_windows.append(in_frame); m_register_windows.append(in_frame);
else else
@ -70,7 +70,9 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
registers().resize(executable.number_of_registers); registers().resize(executable.number_of_registers);
for (;;) { for (;;) {
Bytecode::InstructionStreamIterator pc(block->instruction_stream()); Bytecode::InstructionStreamIterator pc(m_current_block->instruction_stream());
TemporaryChange temp_change { m_pc, &pc };
bool will_jump = false; bool will_jump = false;
bool will_return = false; bool will_return = false;
while (!pc.at_end()) { while (!pc.at_end()) {
@ -85,7 +87,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
if (unwind_context.executable != m_current_executable) if (unwind_context.executable != m_current_executable)
break; break;
if (unwind_context.handler) { if (unwind_context.handler) {
block = unwind_context.handler; m_current_block = unwind_context.handler;
unwind_context.handler = nullptr; unwind_context.handler = nullptr;
// If there's no finalizer, there's nowhere for the handler block to unwind to, so the unwind context is no longer needed. // If there's no finalizer, there's nowhere for the handler block to unwind to, so the unwind context is no longer needed.
@ -98,7 +100,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
break; break;
} }
if (unwind_context.finalizer) { if (unwind_context.finalizer) {
block = unwind_context.finalizer; m_current_block = unwind_context.finalizer;
m_unwind_contexts.take_last(); m_unwind_contexts.take_last();
will_jump = true; will_jump = true;
break; break;
@ -108,7 +110,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
if (m_pending_jump.has_value()) { if (m_pending_jump.has_value()) {
block = m_pending_jump.release_value(); m_current_block = m_pending_jump.release_value();
will_jump = true; will_jump = true;
break; break;
} }

View file

@ -64,6 +64,8 @@ public:
ThrowCompletionOr<void> continue_pending_unwind(Label const& resume_label); ThrowCompletionOr<void> continue_pending_unwind(Label const& resume_label);
Executable const& current_executable() { return *m_current_executable; } Executable const& current_executable() { return *m_current_executable; }
BasicBlock const& current_block() const { return *m_current_block; }
size_t pc() const { return m_pc ? m_pc->offset() : 0; }
enum class OptimizationLevel { enum class OptimizationLevel {
None, None,
@ -99,6 +101,8 @@ private:
Vector<UnwindInfo> m_unwind_contexts; Vector<UnwindInfo> m_unwind_contexts;
Handle<Value> m_saved_exception; Handle<Value> m_saved_exception;
OwnPtr<JS::Interpreter> m_ast_interpreter; OwnPtr<JS::Interpreter> m_ast_interpreter;
BasicBlock const* m_current_block { nullptr };
InstructionStreamIterator* m_pc { nullptr };
}; };
extern bool g_dump_bytecode; extern bool g_dump_bytecode;