mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
LibJS: Convert Promise::create() to NonnullGCPtr
This commit is contained in:
parent
ddc6e139a6
commit
a4d85cd522
16 changed files with 26 additions and 26 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
Handle,
|
||||
};
|
||||
|
||||
static Promise* create(Realm&);
|
||||
static NonnullGCPtr<Promise> create(Realm&);
|
||||
|
||||
virtual ~Promise() = default;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue