1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +00:00

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.
This commit is contained in:
Andreas Kling 2020-09-20 19:24:44 +02:00
parent c6ae0c41d9
commit 1c43442be4
13 changed files with 218 additions and 27 deletions

View file

@ -43,6 +43,8 @@
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
RefPtr<JS::VM> vm;
static bool collect_on_every_allocation = false;
static String currently_running_test;
@ -273,7 +275,10 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
currently_running_test = test_path;
double start_time = get_time_in_ms();
auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>();
auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>(*vm);
// FIXME: This is a hack while we're refactoring Interpreter/VM stuff.
JS::VM::InterpreterScope scope(*interpreter);
interpreter->heap().set_should_collect_on_every_allocation(collect_on_every_allocation);
@ -603,6 +608,8 @@ int main(int argc, char** argv)
DebugLogStream::set_enabled(false);
}
vm = JS::VM::create();
#ifdef __serenity__
TestRunner("/home/anon/js-tests", print_times).run();
#else
@ -614,5 +621,7 @@ int main(int argc, char** argv)
TestRunner(String::format("%s/Libraries/LibJS/Tests", serenity_root), print_times).run();
#endif
vm = nullptr;
return 0;
}