From 897babc2f5afd6502e14887edc69979834ec824a Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov <2056864+Elringus@users.noreply.github.com> Date: Mon, 11 May 2026 20:27:33 +0300 Subject: [PATCH] allow empty modules --- .../Runtime/InteropServices/JavaScript/JSImportTest.cs | 6 ++++++ .../InteropServices/JavaScript/JavaScriptTestHelper.cs | 3 +++ .../InteropServices/JavaScript/JavaScriptTestHelper.mjs | 5 +++++ src/mono/browser/runtime/invoke-js.ts | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportTest.cs index ee9271e52c2859..d5579849ca201f 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportTest.cs @@ -58,6 +58,12 @@ public async Task MissingImportAsync() Assert.Contains("intentionallyMissingImportAsync must be a Function but was undefined", ex.Message); } + [Fact] + public void EmptyModuleNameImport() + { + Assert.Equal("empty module", JavaScriptTestHelper.EmptyModuleNameEcho("empty module")); + } + #if !FEATURE_WASM_MANAGED_THREADS // because in MT JSHost.ImportAsync is really async, it will finish before the caller could cancel it [Fact] public async Task CancelableImportAsync() diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index d1fffe5517452d..b80e0c43d4b02e 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -46,6 +46,9 @@ public static void ConsoleWriteLine([JSMarshalAs] string message) [JSImport("intentionallyMissingImportAsync", "JavaScriptTestHelper")] public static partial Task IntentionallyMissingImportAsync(); + [JSImport("emptyModuleNameEcho", "")] + public static partial string EmptyModuleNameEcho(string message); + [JSImport("catch1toString", "JavaScriptTestHelper")] public static partial string catch1toString(string message, string functionName); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index 1c91dbdb1dfe6b..ad63b7ee3a7250 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -495,6 +495,11 @@ globalThis.rebound = { export async function setup() { dllExports = await App.runtime.getAssemblyExports("System.Runtime.InteropServices.JavaScript.Tests.dll"); + App.runtime.setModuleImports("", { emptyModuleNameEcho }); +} + +function emptyModuleNameEcho(message) { + return message; } // console.log('JavaScriptTestHelper:' Object.keys(globalThis.JavaScriptTestHelper)); diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index 63e6731f46b909..f1a0710fce568e 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -382,7 +382,7 @@ function mono_wasm_lookup_js_import (function_name: string, js_module_name: stri let scope: any = {}; const parts = function_name.split("."); - if (js_module_name) { + if (js_module_name != null) { scope = importedModules.get(js_module_name); if (WasmEnableThreads) { mono_assert(scope, () => `ES6 module ${js_module_name} was not imported yet, please call JSHost.ImportAsync() on the UI or JSWebWorker thread first in order to invoke ${function_name}.`);