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

LibJS: Convert Promise::create() to NonnullGCPtr

This commit is contained in:
Linus Groh 2022-12-13 20:49:50 +00:00
parent ddc6e139a6
commit a4d85cd522
16 changed files with 26 additions and 26 deletions

View file

@ -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.

View file

@ -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());

View file

@ -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;

View file

@ -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 = [&] {

View file

@ -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();
}