diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 7c4ad5ac13..89401762b4 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -3589,7 +3589,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const ModuleRequest request { specifier_string, assertions }; // 12. Perform HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability). - interpreter.vm().host_import_module_dynamically(referencing_script_or_module, move(request), promise_capability); + MUST_OR_THROW_OOM(interpreter.vm().host_import_module_dynamically(referencing_script_or_module, move(request), promise_capability)); // 13. Return promiseCapability.[[Promise]]. return Value { promise_capability->promise() }; diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 9532ece836..3a40280c50 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -222,7 +222,7 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, DeprecatedString spec TRY(vm.push_execution_context(eval_context, {})); // 6. Perform HostImportModuleDynamically(null, specifierString, innerCapability). - vm.host_import_module_dynamically(Empty {}, ModuleRequest { move(specifier_string) }, inner_capability); + MUST_OR_THROW_OOM(vm.host_import_module_dynamically(Empty {}, ModuleRequest { move(specifier_string) }, inner_capability)); // 7. Suspend evalContext and remove it from the execution context stack. // NOTE: We don't support this concept yet. diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index b85f6e6f16..8291c936d2 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -81,7 +81,7 @@ VM::VM(OwnPtr custom_data) return resolve_imported_module(move(referencing_script_or_module), specifier); }; - host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability const& promise_capability) { + host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability const& promise_capability) -> ThrowCompletionOr { // By default, we throw on dynamic imports this is to prevent arbitrary file access by scripts. VERIFY(current_realm()); auto& realm = *current_realm(); @@ -90,7 +90,7 @@ VM::VM(OwnPtr custom_data) // 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 // vm.enable_default_host_import_module_dynamically_hook(). - promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()).release_allocated_value_but_fixme_should_propagate_errors()); + promise->reject(MUST_OR_THROW_OOM(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()))); promise->perform_then( NativeFunction::create(realm, "", [](auto&) -> ThrowCompletionOr { @@ -106,6 +106,8 @@ VM::VM(OwnPtr custom_data) return js_undefined(); }), {}); + + return {}; }; host_finish_dynamic_import = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability const& promise_capability, Promise* promise) { @@ -971,7 +973,7 @@ ThrowCompletionOr> 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 const& promise_capability) +ThrowCompletionOr VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability) { auto& realm = *current_realm(); @@ -1001,8 +1003,8 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, // If there is no ScriptOrModule in any of the execution contexts if (referencing_script_or_module.has()) { // Throw an error for now - promise->reject(InternalError::create(realm, String::formatted(ErrorType::ModuleNotFoundNoReferencingScript.message(), module_request.module_specifier).release_value_but_fixme_should_propagate_errors())); - return; + promise->reject(InternalError::create(realm, TRY_OR_THROW_OOM(*this, String::formatted(ErrorType::ModuleNotFoundNoReferencingScript.message(), module_request.module_specifier)))); + return {}; } } @@ -1026,6 +1028,7 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, // It must return unused. // Note: Just return void always since the resulting value cannot be accessed by user code. + return {}; } // 16.2.1.9 FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, innerPromise ), https://tc39.es/ecma262/#sec-finishdynamicimport diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 4ba4b8ce5b..ea76277062 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -250,7 +250,7 @@ public: ScriptOrModule get_active_script_or_module() const; Function>(ScriptOrModule, ModuleRequest const&)> host_resolve_imported_module; - Function host_import_module_dynamically; + Function(ScriptOrModule, ModuleRequest, PromiseCapability const&)> host_import_module_dynamically; Function host_finish_dynamic_import; Function(SourceTextModule const&)> host_get_import_meta_properties; @@ -277,7 +277,7 @@ private: ThrowCompletionOr> resolve_imported_module(ScriptOrModule referencing_script_or_module, ModuleRequest const& module_request); ThrowCompletionOr link_and_eval_module(Module& module); - void import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability); + ThrowCompletionOr import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability); void finish_dynamic_import(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability const& promise_capability, Promise* inner_promise); HashMap m_string_cache;