1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 17:25:06 +00:00

LibJS: Remove "uprooting" mechanism from garbage collector

The Heap::uproot_cell() API was used to implement markAsGarbage() which
was used in 3 tests to forcibly destroy a value, even if it had
references on the stack or elsewhere.

This patch rewrites the 3 tests that used this mechanism to be
structured in a way that allows garbage collection to collect the values
as intended without hacks. And now that the uprooting mechanism is no
longer needed, it's uprooted as well.

This fixes 3 test-js tests in bytecode mode. :^)
This commit is contained in:
Andreas Kling 2023-07-21 10:09:22 +02:00
parent 9054b1bc14
commit 6232ad3a0d
6 changed files with 28 additions and 65 deletions

View file

@ -49,34 +49,6 @@ TESTJS_GLOBAL_FUNCTION(get_weak_map_size, getWeakMapSize)
return JS::Value(weak_map.values().size());
}
TESTJS_GLOBAL_FUNCTION(mark_as_garbage, markAsGarbage)
{
auto argument = vm.argument(0);
if (!argument.is_string())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAString, TRY_OR_THROW_OOM(vm, argument.to_string_without_side_effects()));
auto& variable_name = argument.as_string();
// In native functions we don't have a lexical environment so get the outer via the execution stack.
auto outer_environment = vm.execution_context_stack().last_matching([&](auto& execution_context) {
return execution_context->lexical_environment != nullptr;
});
if (!outer_environment.has_value())
return vm.throw_completion<JS::ReferenceError>(JS::ErrorType::UnknownIdentifier, TRY(variable_name.deprecated_string()));
auto reference = TRY(vm.resolve_binding(TRY(variable_name.deprecated_string()), outer_environment.value()->lexical_environment));
auto value = TRY(reference.get_value(vm));
if (!can_be_held_weakly(value))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::CannotBeHeldWeakly, DeprecatedString::formatted("Variable with name {}", TRY(variable_name.deprecated_string())));
vm.heap().uproot_cell(&value.as_cell());
TRY(reference.delete_(vm));
return JS::js_undefined();
}
TESTJS_GLOBAL_FUNCTION(detach_array_buffer, detachArrayBuffer)
{
auto array_buffer = vm.argument(0);