LibJS: Convert Realm::create() to NonnullGCPtr

This commit is contained in:
Linus Groh 2022-12-13 20:49:50 +00:00
parent e0818bf21e
commit bfb8d83535
Notes: sideshowbarker 2024-07-17 03:17:00 +09:00
4 changed files with 6 additions and 7 deletions

View file

@ -58,8 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::clear_kept_objects)
JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
{
auto* realm = Realm::create(vm);
VERIFY(realm);
auto realm = Realm::create(vm);
auto* realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
VERIFY(realm_global_object);
realm->set_global_object(realm_global_object, nullptr);

View file

@ -15,7 +15,7 @@
namespace JS {
// 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm
Realm* Realm::create(VM& vm)
NonnullGCPtr<Realm> Realm::create(VM& vm)
{
// 1. Let realmRec be a new Realm Record.
auto* realm = vm.heap().allocate_without_realm<Realm>();
@ -28,7 +28,7 @@ Realm* Realm::create(VM& vm)
// 5. Set realmRec.[[TemplateMap]] to a new empty List.
// 6. Return realmRec.
return realm;
return *realm;
}
// 9.6 InitializeHostDefinedRealm ( ), https://tc39.es/ecma262/#sec-initializehostdefinedrealm
@ -37,7 +37,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
DeferGC defer_gc(vm.heap());
// 1. Let realm be CreateRealm().
auto* realm = Realm::create(vm);
auto realm = Realm::create(vm);
// 2. Let newContext be a new execution context.
auto new_context = make<ExecutionContext>(vm.heap());

View file

@ -29,7 +29,7 @@ public:
virtual void visit_edges(Cell::Visitor&) { }
};
static Realm* create(VM&);
static NonnullGCPtr<Realm> create(VM&);
static ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> initialize_host_defined_realm(VM&, Function<Object*(Realm&)> create_global_object, Function<Object*(Realm&)> create_global_this_value);
void set_global_object(Object* global_object, Object* this_value);

View file

@ -42,7 +42,7 @@ ThrowCompletionOr<Object*> ShadowRealmConstructor::construct(FunctionObject& new
auto& vm = this->vm();
// 3. Let realmRec be CreateRealm().
auto* realm = Realm::create(vm);
auto realm = Realm::create(vm);
// 5. Let context be a new execution context.
auto context = ExecutionContext { vm.heap() };