diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/VM.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 1b15a1571d..40a17de1c1 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -70,7 +70,7 @@ VM::VM(OwnPtr<CustomData> custom_data) return resolve_imported_module(move(referencing_script_or_module), specifier); }; - host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability promise_capability) { + host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability const& promise_capability) { // By default, we throw on dynamic imports this is to prevent arbitrary file access by scripts. VERIFY(current_realm()); auto& realm = *current_realm(); @@ -85,11 +85,11 @@ VM::VM(OwnPtr<CustomData> custom_data) NativeFunction::create(realm, "", [](auto&) -> ThrowCompletionOr<Value> { VERIFY_NOT_REACHED(); }), - NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm) -> ThrowCompletionOr<Value> { + NativeFunction::create(realm, "", [&promise_capability](auto& vm) -> ThrowCompletionOr<Value> { auto error = vm.argument(0); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »). - MUST(call(vm, reject.cell(), js_undefined(), error)); + MUST(call(vm, *promise_capability.reject(), js_undefined(), error)); // b. Return undefined. return js_undefined(); @@ -97,7 +97,7 @@ VM::VM(OwnPtr<CustomData> custom_data) {}); }; - host_finish_dynamic_import = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability, Promise* promise) { + host_finish_dynamic_import = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability const& promise_capability, Promise* promise) { return finish_dynamic_import(move(referencing_script_or_module), specifier, promise_capability, promise); }; @@ -146,7 +146,7 @@ VM::VM(OwnPtr<CustomData> custom_data) void VM::enable_default_host_import_module_dynamically_hook() { - host_import_module_dynamically = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability) { + host_import_module_dynamically = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability const& promise_capability) { return import_module_dynamically(move(referencing_script_or_module), specifier, promise_capability); }; } @@ -976,7 +976,7 @@ ThrowCompletionOr<NonnullGCPtr<Module>> VM::resolve_imported_module(ScriptOrModu } // 16.2.1.8 HostImportModuleDynamically ( referencingScriptOrModule, specifier, promiseCapability ), https://tc39.es/ecma262/#sec-hostimportmoduledynamically -void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability promise_capability) +void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability) { auto& realm = *current_realm(); @@ -995,7 +995,7 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, auto* promise = Promise::create(realm); ScopeGuard finish_dynamic_import = [&] { - host_finish_dynamic_import(referencing_script_or_module, move(module_request), promise_capability, promise); + host_finish_dynamic_import(referencing_script_or_module, module_request, promise_capability, promise); }; // Generally within ECMA262 we always get a referencing_script_or_moulde. However, ShadowRealm gives an explicit null. @@ -1034,14 +1034,14 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, } // 16.2.1.9 FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, innerPromise ), https://tc39.es/ecma262/#sec-finishdynamicimport -void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability promise_capability, Promise* inner_promise) +void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability, Promise* inner_promise) { dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] finish_dynamic_import on {}", module_request.module_specifier); auto& realm = *current_realm(); // 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called: - auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr<Value> { + auto fulfilled_closure = [referencing_script_or_module = move(referencing_script_or_module), module_request = move(module_request), &promise_capability](VM& vm) -> ThrowCompletionOr<Value> { auto result = vm.argument(0); // a. Assert: result is undefined. VERIFY(result.is_undefined()); @@ -1057,12 +1057,12 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu // e. If namespace is an abrupt completion, then if (namespace_.is_throw_completion()) { // i. Perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »). - MUST(call(vm, reject_function.cell(), js_undefined(), *namespace_.throw_completion().value())); + MUST(call(vm, *promise_capability.reject(), js_undefined(), *namespace_.throw_completion().value())); } // f. Else, else { // i. Perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). - MUST(call(vm, resolve_function.cell(), js_undefined(), namespace_.release_value())); + MUST(call(vm, *promise_capability.resolve(), js_undefined(), namespace_.release_value())); } // g. Return unused. // NOTE: We don't support returning an empty/optional/unused value here. @@ -1073,10 +1073,10 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, ""); // 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called: - auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr<Value> { + auto rejected_closure = [&promise_capability](VM& vm) -> ThrowCompletionOr<Value> { auto error = vm.argument(0); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »). - MUST(call(vm, rejected_function.cell(), js_undefined(), error)); + MUST(call(vm, *promise_capability.reject(), js_undefined(), error)); // b. Return unused. // NOTE: We don't support returning an empty/optional/unused value here. |