1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

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.
This commit is contained in:
Linus Groh 2022-08-28 17:37:04 +01:00
parent 040e3abb1d
commit d53a369e7f

View file

@ -62,15 +62,13 @@ ThrowCompletionOr<Object*> ShadowRealmConstructor::construct(FunctionObject& new
auto* object = TRY(ordinary_create_from_constructor<ShadowRealm>(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<GlobalObject>(*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;