diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-20 19:24:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-20 19:24:44 +0200 |
commit | 1c43442be46926a572059d4aad6d8f3a7e95d3b2 (patch) | |
tree | d7c58db53782d143eec803f07657b9ca758c6ecd /Userland/js.cpp | |
parent | c6ae0c41d908ae59a858a28a737b4382cceaeb6c (diff) | |
download | serenity-1c43442be46926a572059d4aad6d8f3a7e95d3b2.zip |
LibJS+Clients: Add JS::VM object, separate Heap from Interpreter
Taking a big step towards a world of multiple global object, this patch
adds a new JS::VM object that houses the JS::Heap.
This means that the Heap moves out of Interpreter, and the same Heap
can now be used by multiple Interpreters, and can also outlive them.
The VM keeps a stack of Interpreter pointers. We push/pop on this
stack when entering/exiting execution with a given Interpreter.
This allows us to make this change without disturbing too much of
the existing code.
There is still a 1-to-1 relationship between Interpreter and the
global object. This will change in the future.
Ultimately, the goal here is to make Interpreter a transient object
that only needs to exist while you execute some code. Getting there
will take a lot more work though. :^)
Note that in LibWeb, the global JS::VM is called main_thread_vm(),
to distinguish it from future worker VM's.
Diffstat (limited to 'Userland/js.cpp')
-rw-r--r-- | Userland/js.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Userland/js.cpp b/Userland/js.cpp index f08b336184..08271c95d6 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -552,6 +552,7 @@ int main(int argc, char** argv) bool syntax_highlight = !disable_syntax_highlight; + auto vm = JS::VM::create(); OwnPtr<JS::Interpreter> interpreter; interrupt_interpreter = [&] { @@ -561,7 +562,7 @@ int main(int argc, char** argv) if (script_path == nullptr) { s_print_last_result = true; - interpreter = JS::Interpreter::create<ReplObject>(); + interpreter = JS::Interpreter::create<ReplObject>(*vm); ReplConsoleClient console_client(interpreter->console()); interpreter->console().set_client(console_client); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); @@ -842,7 +843,7 @@ int main(int argc, char** argv) s_editor->on_tab_complete = move(complete); repl(*interpreter); } else { - interpreter = JS::Interpreter::create<JS::GlobalObject>(); + interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm); ReplConsoleClient console_client(interpreter->console()); interpreter->console().set_client(console_client); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); |