From 6913f06b6f8c58be771caa5af155d775e570aa73 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sat, 12 Jun 2021 17:32:54 +0300 Subject: [PATCH] LibJS: Store and maintain an "execution generation" counter This counter is increased each time a synchronous execution sequence completes, and will allow us to emulate the abstract operations AddToKeptObjects & ClearKeptObjects efficiently. --- Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 2 ++ Userland/Libraries/LibJS/Interpreter.cpp | 2 ++ Userland/Libraries/LibJS/Runtime/VM.h | 5 +++++ Userland/Libraries/LibWeb/DOM/Document.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 94c3e1e5122..eb63d3f895a 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -141,6 +141,8 @@ Value Interpreter::run(Executable const& executable, BasicBlock const* entry_poi if (vm().call_stack().size() == 1) vm().pop_call_frame(); + vm().finish_execution_generation(); + return return_value; } diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index 1c6ef8f73a8..63acef125cd 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -63,6 +63,8 @@ void Interpreter::run(GlobalObject& global_object, const Program& program) // At this point we may have already run any queued promise jobs via on_call_stack_emptied, // in which case this is a no-op. vm.run_queued_promise_jobs(); + + vm.finish_execution_generation(); } GlobalObject& Interpreter::global_object() diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 66e55447932..6f9f5de524a 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -166,6 +166,9 @@ public: bool underscore_is_last_value() const { return m_underscore_is_last_value; } void set_underscore_is_last_value(bool b) { m_underscore_is_last_value = b; } + u32 execution_generation() const { return m_execution_generation; } + void finish_execution_generation() { ++m_execution_generation; } + void unwind(ScopeType type, FlyString label = {}) { m_unwind_until = type; @@ -279,6 +282,8 @@ private: Shape* m_scope_object_shape { nullptr }; bool m_underscore_is_last_value { false }; + + u32 m_execution_generation { 0 }; }; template<> diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e7f8ee57876..98cc56969c8 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -655,6 +655,8 @@ JS::Interpreter& Document::interpreter() dbgln(" {} at {}:{}:{}", function_name, source_range.filename, source_range.start.line, source_range.start.column); } } + + vm.finish_execution_generation(); }; m_interpreter = JS::Interpreter::create(vm, *m_window); }