1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:45:07 +00:00

Revert "LibJS: Remove "uprooting" mechanism from garbage collector"

This reverts commit 6232ad3a0d.

Unfortunately this introduced some flakiness on CI, so it wasn't
quite this simple.
This commit is contained in:
Andreas Kling 2023-07-22 06:53:22 +02:00
parent a2955501d3
commit 1768d70823
6 changed files with 65 additions and 28 deletions

View file

@ -49,6 +49,34 @@ 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);