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

LibJS: Add MarkedValueList and use it for argument passing

A MarkedValueList is basically a Vector<JS::Value> that registers with
the Heap and makes sure that the stored values don't get GC'd.

Before this change, we were unsafely keeping Vector<JS::Value> in some
places, which is out-of-reach for the live reference finding logic
since Vector puts its elements on the heap by default.

We now pass all the JavaScript tests even when running with "js -g",
which does a GC on every heap allocation.
This commit is contained in:
Andreas Kling 2020-04-19 17:24:56 +02:00
parent cb3cf589ed
commit f7a1696087
13 changed files with 178 additions and 16 deletions

View file

@ -30,6 +30,7 @@
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/LexicalEnvironment.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Shape.h>
@ -177,12 +178,13 @@ void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
}
}
Value Interpreter::call(Function* function, Value this_value, const Vector<Value>& arguments)
Value Interpreter::call(Function* function, Value this_value, Optional<MarkedValueList> arguments)
{
auto& call_frame = push_call_frame();
call_frame.function_name = function->name();
call_frame.this_value = this_value;
call_frame.arguments = arguments;
if (arguments.has_value())
call_frame.arguments = arguments.value().values();
call_frame.environment = function->create_environment();
auto result = function->call(*this);
pop_call_frame();