From d53a369e7f05394496a1c2b19e33c86f436e4f86 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 28 Aug 2022 17:37:04 +0100 Subject: [PATCH] LibJS: Implement ShadowRealmConstructor::construct() closer to spec Defer creation of the global object to Realm::set_global_object(), and use the newly added set_default_global_bindings() AO as intended. --- .../LibJS/Runtime/ShadowRealmConstructor.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp index 2ea3f75bd7..f6aeec9743 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp @@ -62,15 +62,13 @@ ThrowCompletionOr ShadowRealmConstructor::construct(FunctionObject& new auto* object = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::shadow_realm_prototype, *realm, move(context))); // 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined). - auto* new_global_object = vm.heap().allocate_without_realm(*realm); - realm->set_global_object(new_global_object, nullptr); - new_global_object->initialize(*realm); + realm->set_global_object(nullptr, nullptr); - // TODO: I don't think we should have these exactly like this, that doesn't work well with how - // we create global objects. Still, it should be possible to make a ShadowRealm with a - // non-LibJS GlobalObject somehow. // 11. Perform ? SetDefaultGlobalBindings(O.[[ShadowRealm]]). - // 12. Perform ? HostInitializeShadowRealm(O.[[ShadowRealm]]). + auto& global_object = set_default_global_bindings(object->shadow_realm()); + + // FIXME: 12. Perform ? HostInitializeShadowRealm(O.[[ShadowRealm]]). + global_object.initialize(object->shadow_realm()); // 13. Return O. return object;