summaryrefslogtreecommitdiff
path: root/Userland/Libraries
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
parentddc6e139a612154611e82493ef2bbe886a73814b (diff)
downloadserenity-a4d85cd522e22750ff6449d21f3fbb9c9f86c7c1.zip
LibJS: Convert Promise::create() to NonnullGCPtr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Module.cpp2
-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
-rw-r--r--Userland/Libraries/LibJS/SyntheticModule.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp6
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/Blob.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp2
-rw-r--r--Userland/Libraries/LibWeb/WebIDL/Promise.cpp4
15 files changed, 25 insertions, 25 deletions
diff --git a/Userland/Libraries/LibJS/Module.cpp b/Userland/Libraries/LibJS/Module.cpp
index e0315a8b0d..986c070d79 100644
--- a/Userland/Libraries/LibJS/Module.cpp
+++ b/Userland/Libraries/LibJS/Module.cpp
@@ -47,7 +47,7 @@ ThrowCompletionOr<u32> Module::inner_module_evaluation(VM& vm, Vector<Module*>&,
{
// 1. If module is not a Cyclic Module Record, then
// a. Let promise be ! module.Evaluate().
- auto* promise = TRY(evaluate(vm));
+ auto promise = TRY(evaluate(vm));
// b. Assert: promise.[[PromiseState]] is not pending.
VERIFY(promise->state() != Promise::State::Pending);
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);
diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp
index c446f93ca5..c9802a25a6 100644
--- a/Userland/Libraries/LibJS/SyntheticModule.cpp
+++ b/Userland/Libraries/LibJS/SyntheticModule.cpp
@@ -107,7 +107,7 @@ ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm)
// 12. Return Completion(result).
// Note: Because we expect it to return a promise we convert this here.
- auto* promise = Promise::create(realm());
+ auto promise = Promise::create(realm());
if (result.is_error()) {
VERIFY(result.throw_completion().value().has_value());
promise->reject(*result.throw_completion().value());
@@ -115,7 +115,7 @@ ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm)
// Note: This value probably isn't visible to JS code? But undefined is fine anyway.
promise->fulfill(js_undefined());
}
- return promise;
+ return promise.ptr();
}
// 1.2.2 SetSyntheticModuleExport ( module, exportName, exportValue ), https://tc39.es/proposal-json-modules/#sec-setsyntheticmoduleexport
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
index 37edb0b28c..ef0f18e829 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
@@ -38,7 +38,7 @@ JS::Promise* SubtleCrypto::digest(DeprecatedString const& algorithm, JS::Handle<
auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*data.cell());
if (data_buffer_or_error.is_error()) {
auto error = WebIDL::OperationError::create(realm, "Failed to copy bytes from ArrayBuffer");
- auto* promise = JS::Promise::create(realm);
+ auto promise = JS::Promise::create(realm);
promise->reject(error.ptr());
return promise;
}
@@ -59,13 +59,13 @@ JS::Promise* SubtleCrypto::digest(DeprecatedString const& algorithm, JS::Handle<
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
else {
auto error = WebIDL::NotSupportedError::create(realm, DeprecatedString::formatted("Invalid hash function '{}'", algorithm));
- auto* promise = JS::Promise::create(realm);
+ auto promise = JS::Promise::create(realm);
promise->reject(error.ptr());
return promise;
}
// 5. Let promise be a new Promise.
- auto* promise = JS::Promise::create(realm);
+ auto promise = JS::Promise::create(realm);
// 6. Return promise and perform the remaining steps in parallel.
// FIXME: We don't have a good abstraction for this yet, so we do it in sync.
diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
index 485ec4d364..fbff037466 100644
--- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
@@ -244,7 +244,7 @@ JS::Promise* Blob::text()
// FIXME: We still need to implement ReadableStream for this step to be fully valid.
// 3. Let promise be the result of reading all bytes from stream with reader
- auto* promise = JS::Promise::create(realm());
+ auto promise = JS::Promise::create(realm());
auto result = JS::PrimitiveString::create(vm(), DeprecatedString { m_byte_buffer.bytes() });
// 4. Return the result of transforming promise by a fulfillment handler that returns the result of running UTF-8 decode on its first argument.
@@ -260,7 +260,7 @@ JS::Promise* Blob::array_buffer()
// FIXME: We still need to implement ReadableStream for this step to be fully valid.
// 3. Let promise be the result of reading all bytes from stream with reader.
- auto* promise = JS::Promise::create(realm());
+ auto promise = JS::Promise::create(realm());
auto buffer_result = JS::ArrayBuffer::create(realm(), m_byte_buffer.size());
if (buffer_result.is_error()) {
promise->reject(buffer_result.release_error().value().release_value());
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
index b0536be3b7..dfc380302a 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.cpp
@@ -112,7 +112,7 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
// 2. Check if we can run script with settings. If this returns "do not run", then return a promise resolved with undefined.
if (settings.can_run_script() == RunScriptDecision::DoNotRun) {
- auto* promise = JS::Promise::create(settings.realm());
+ auto promise = JS::Promise::create(settings.realm());
promise->fulfill(JS::js_undefined());
return promise;
}
@@ -140,7 +140,7 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
// If Evaluate fails to complete as a result of the user agent aborting the running script,
// then set evaluationPromise to a promise rejected with a new "QuotaExceededError" DOMException.
if (elevation_promise_or_error.is_error()) {
- auto* promise = JS::Promise::create(settings_object().realm());
+ auto promise = JS::Promise::create(settings_object().realm());
promise->reject(WebIDL::QuotaExceededError::create(settings_object().realm(), "Failed to evaluate module script").ptr());
evaluation_promise = promise;
diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
index 350a4d415a..1f4744f35d 100644
--- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp
@@ -315,7 +315,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
auto start = Time::now_monotonic();
// 4. Let promise be a new Promise.
- auto* promise = JS::Promise::create(realm);
+ auto promise = JS::Promise::create(realm);
// FIXME: 5 Run the following substeps in parallel:
auto result = [&] {
diff --git a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
index bf98fcda24..4a8c74a2ba 100644
--- a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
+++ b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp
@@ -135,7 +135,7 @@ JS::NonnullGCPtr<JS::Promise> react_to_promise(JS::PromiseCapability const& prom
auto new_capability = MUST(JS::new_promise_capability(vm, constructor));
// 7. Return PerformPromiseThen(promise.[[Promise]], onFulfilled, onRejected, newCapability).
- auto* promise = verify_cast<JS::Promise>(promise_capability.promise().ptr());
+ auto promise = verify_cast<JS::Promise>(promise_capability.promise().ptr());
auto value = promise->perform_then(on_fulfilled, on_rejected, new_capability);
return verify_cast<JS::Promise>(value.as_object());
}
@@ -173,7 +173,7 @@ JS::NonnullGCPtr<JS::Promise> upon_rejection(JS::PromiseCapability const& promis
void mark_promise_as_handled(JS::PromiseCapability const& promise_capability)
{
// To mark as handled a Promise<T> promise, set promise.[[Promise]].[[PromiseIsHandled]] to true.
- auto* promise = verify_cast<JS::Promise>(promise_capability.promise().ptr());
+ auto promise = verify_cast<JS::Promise>(promise_capability.promise().ptr());
promise->set_is_handled();
}