summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-13 20:49:50 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-14 09:59:45 +0000
commita4d85cd522e22750ff6449d21f3fbb9c9f86c7c1 (patch)
tree3051581a27b1e26a06f8f1e9758bb1087012ef84 /Userland/Libraries/LibJS/Runtime
parentddc6e139a612154611e82493ef2bbe886a73814b (diff)
downloadserenity-a4d85cd522e22750ff6449d21f3fbb9c9f86c7c1.zip
LibJS: Convert Promise::create() to NonnullGCPtr
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp4
8 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
index 36c93b2c41..e3afe6ec5c 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
@@ -56,7 +56,7 @@ ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_complet
return promise;
}
- auto* promise = static_cast<Promise*>(&promise_value.as_object());
+ auto promise = static_cast<Promise*>(&promise_value.as_object());
if (TRY(result.get(vm, vm.names.done)).to_boolean())
return promise;
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp
index 3b1db9a70b..f5f5b94df4 100644
--- a/Userland/Libraries/LibJS/Runtime/Completion.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp
@@ -89,7 +89,7 @@ ThrowCompletionOr<Value> await(VM& vm, Value value)
auto on_rejected = NativeFunction::create(realm, move(rejected_closure), 1, "");
// 7. Perform PerformPromiseThen(promise, onFulfilled, onRejected).
- auto* promise = verify_cast<Promise>(promise_object);
+ auto promise = verify_cast<Promise>(promise_object);
promise->perform_then(on_fulfilled, on_rejected, {});
// FIXME: Since we don't support context suspension, we attempt to "wait" for the promise to resolve
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp
index 3d62d1fa42..8fff28c048 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp
@@ -42,9 +42,9 @@ ThrowCompletionOr<Object*> promise_resolve(VM& vm, Object& constructor, Value va
return promise_capability->promise().ptr();
}
-Promise* Promise::create(Realm& realm)
+NonnullGCPtr<Promise> Promise::create(Realm& realm)
{
- return realm.heap().allocate<Promise>(realm, *realm.intrinsics().promise_prototype());
+ return *realm.heap().allocate<Promise>(realm, *realm.intrinsics().promise_prototype());
}
// 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.h b/Userland/Libraries/LibJS/Runtime/Promise.h
index 790e3482e4..8ec2a87000 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.h
+++ b/Userland/Libraries/LibJS/Runtime/Promise.h
@@ -27,7 +27,7 @@ public:
Handle,
};
- static Promise* create(Realm&);
+ static NonnullGCPtr<Promise> create(Realm&);
virtual ~Promise() = default;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp b/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
index 0d57ea1f08..7a4f1565c5 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseCapability.cpp
@@ -78,7 +78,7 @@ ThrowCompletionOr<NonnullGCPtr<PromiseCapability>> new_promise_capability(VM& vm
auto executor = NativeFunction::create(realm, move(executor_closure), 2, "");
// 6. Let promise be ? Construct(C, ยซ executor ยป).
- auto* promise = TRY(construct(vm, constructor.as_function(), executor));
+ auto promise = TRY(construct(vm, constructor.as_function(), executor));
// 7. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
// NOTE: We only assign a value in the executor closure if it is a function.
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index 7aab263eb6..ad87333c1d 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -290,7 +290,7 @@ ThrowCompletionOr<Object*> PromiseConstructor::construct(FunctionObject& new_tar
// 5. Set promise.[[PromiseFulfillReactions]] to a new empty List.
// 6. Set promise.[[PromiseRejectReactions]] to a new empty List.
// 7. Set promise.[[PromiseIsHandled]] to false.
- auto* promise = TRY(ordinary_create_from_constructor<Promise>(vm, new_target, &Intrinsics::promise_prototype));
+ auto promise = TRY(ordinary_create_from_constructor<Promise>(vm, new_target, &Intrinsics::promise_prototype));
// 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
auto [resolve_function, reject_function] = promise->create_resolving_functions();
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
index fd0b05f543..721969639d 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
@@ -45,7 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then)
// 1. Let promise be the this value.
// 2. If IsPromise(promise) is false, throw a TypeError exception.
- auto* promise = TRY(typed_this_object(vm));
+ auto promise = TRY(typed_this_object(vm));
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
auto* constructor = TRY(species_constructor(vm, *promise, *realm.intrinsics().promise_constructor()));
@@ -113,7 +113,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto result = TRY(call(vm, on_finally, js_undefined()));
// ii. Let promise be ? PromiseResolve(C, result).
- auto* promise = TRY(promise_resolve(vm, constructor, result));
+ auto promise = TRY(promise_resolve(vm, constructor, result));
// iii. Let returnValue be a new Abstract Closure with no parameters that captures value and performs the following steps when called:
auto return_value = [value_handle = make_handle(value)](auto&) -> ThrowCompletionOr<Value> {
@@ -142,7 +142,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto result = TRY(call(vm, on_finally, js_undefined()));
// ii. Let promise be ? PromiseResolve(C, result).
- auto* promise = TRY(promise_resolve(vm, constructor, result));
+ auto promise = TRY(promise_resolve(vm, constructor, result));
// iii. Let throwReason be a new Abstract Closure with no parameters that captures reason and performs the following steps when called:
auto throw_reason = [reason_handle = make_handle(reason)](auto&) -> ThrowCompletionOr<Value> {
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index f60e2f07a6..a65f8cbb06 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -75,7 +75,7 @@ VM::VM(OwnPtr<CustomData> custom_data)
// By default, we throw on dynamic imports this is to prevent arbitrary file access by scripts.
VERIFY(current_realm());
auto& realm = *current_realm();
- auto* promise = Promise::create(realm);
+ auto promise = Promise::create(realm);
// If you are here because you want to enable dynamic module importing make sure it won't be a security problem
// by checking the default implementation of HostImportModuleDynamically and creating your own hook or calling
@@ -965,7 +965,7 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module,
// FinishDynamicImport(referencingScriptOrModule, moduleRequest, promiseCapability, promise),
// where promise is a Promise rejected with an error representing the cause of failure.
- auto* promise = Promise::create(realm);
+ auto promise = Promise::create(realm);
ScopeGuard finish_dynamic_import = [&] {
host_finish_dynamic_import(referencing_script_or_module, module_request, promise_capability, promise);