LibWeb: Hang on to the internal realm with a JS::Handle

This fixes an issue where GC would kill the internal realm if it ran at
the wrong time during startup. Found by aggressively GC'ing between
every allocation.
This commit is contained in:
Andreas Kling 2022-10-17 10:55:16 +02:00
parent 6e0f80fbe0
commit 2898701459
Notes: sideshowbarker 2024-07-17 05:17:20 +09:00
2 changed files with 3 additions and 0 deletions

View file

@ -375,6 +375,7 @@ JS::VM& main_thread_vm()
auto* intrinsics = root_realm->heap().allocate<Intrinsics>(*root_realm, *root_realm);
auto host_defined = make<HostDefined>(nullptr, *intrinsics);
root_realm->set_host_defined(move(host_defined));
custom_data.internal_realm = root_realm;
// NOTE: We make sure the internal realm has all the Window intrinsics initialized.
// The DeferGC is a hack to avoid nested GC allocations due to lazy ensure_web_prototype()

View file

@ -32,6 +32,8 @@ struct WebEngineCustomData final : public JS::VM::CustomData {
// FIXME: This should be a set.
Vector<JS::Handle<DOM::MutationObserver>> mutation_observers;
JS::Handle<JS::Realm> internal_realm;
OwnPtr<JS::ExecutionContext> root_execution_context;
};