|
@@ -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);
|