diff --git a/src/mono/wasm/runtime/assets.ts b/src/mono/wasm/runtime/assets.ts index 8ddc4ecda006ce..cd89212e7c6e02 100644 --- a/src/mono/wasm/runtime/assets.ts +++ b/src/mono/wasm/runtime/assets.ts @@ -19,7 +19,6 @@ let actual_instantiated_assets_count = 0; let expected_downloaded_assets_count = 0; let expected_instantiated_assets_count = 0; const loaded_files: { url: string, file: string }[] = []; -const loaded_assets: { [id: string]: [VoidPtr, number] } = Object.create(null); // in order to prevent net::ERR_INSUFFICIENT_RESOURCES if we start downloading too many files at same time let parallel_count = 0; let throttlingPromise: PromiseAndController | undefined; @@ -29,6 +28,7 @@ const skipDownloadsByAssetTypes: { [k: string]: boolean } = { "js-module-threads": true, + "dotnetwasm": true, }; // `response.arrayBuffer()` can't be called twice. Some usecases are calling it on response in the instantiation. @@ -372,7 +372,6 @@ function _instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Array) { case "heap": case "icu": offset = mono_wasm_load_bytes_into_heap(bytes); - loaded_assets[virtualName] = [offset, bytes.length]; break; case "vfs": { diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js index 6c511fe49347f2..04bc10482b4471 100644 --- a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js +++ b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js @@ -97,9 +97,6 @@ let linked_functions = [ "mono_wasm_invoke_import", "mono_wasm_bind_cs_function", "mono_wasm_marshal_promise", - - // pal_icushim_static.c - "mono_wasm_load_icu_data", ]; if (monoWasmThreads) { diff --git a/src/mono/wasm/runtime/exports-linker.ts b/src/mono/wasm/runtime/exports-linker.ts index dbfa140f47c3bc..f5f55de63f128e 100644 --- a/src/mono/wasm/runtime/exports-linker.ts +++ b/src/mono/wasm/runtime/exports-linker.ts @@ -5,7 +5,6 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import WasmEnableLegacyJsInterop from "consts:WasmEnableLegacyJsInterop"; import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug"; import { mono_wasm_release_cs_owned_object } from "./gc-handles"; -import { mono_wasm_load_icu_data } from "./icu"; import { mono_wasm_bind_cs_function } from "./invoke-cs"; import { mono_wasm_bind_js_function, mono_wasm_invoke_bound_function, mono_wasm_invoke_import } from "./invoke-js"; import { mono_interp_tier_prepare_jiterpreter } from "./jiterpreter"; @@ -95,9 +94,6 @@ export function export_linker(): any { mono_wasm_bind_cs_function, mono_wasm_marshal_promise, - // pal_icushim_static.c - mono_wasm_load_icu_data, - // threading exports, if threading is enabled ...mono_wasm_threads_exports, // legacy interop exports, if enabled diff --git a/src/mono/wasm/runtime/imports.ts b/src/mono/wasm/runtime/imports.ts index fe2c2561747050..e15015cc8b91e1 100644 --- a/src/mono/wasm/runtime/imports.ts +++ b/src/mono/wasm/runtime/imports.ts @@ -51,7 +51,6 @@ export function set_emscripten_entrypoint( const initialRuntimeHelpers: Partial = { javaScriptExports: {} as any, - mono_wasm_load_runtime_done: false, mono_wasm_bindings_is_ready: false, maxParallelDownloads: 16, enableDownloadRetry: true, diff --git a/src/mono/wasm/runtime/pthreads/worker/index.ts b/src/mono/wasm/runtime/pthreads/worker/index.ts index ba411a70870f14..da4c780804c55b 100644 --- a/src/mono/wasm/runtime/pthreads/worker/index.ts +++ b/src/mono/wasm/runtime/pthreads/worker/index.ts @@ -69,7 +69,6 @@ export function setupPreloadChannelToMainThread() { const mainPort = channel.port2; workerPort.addEventListener("message", (event) => { const config = JSON.parse(event.data.config) as MonoConfig; - console.debug("MONO_WASM: applying mono config from main", event.data.config); onMonoConfigReceived(config); workerPort.close(); mainPort.close(); diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts index 75b1b17f111ee1..b98911b7367337 100644 --- a/src/mono/wasm/runtime/startup.ts +++ b/src/mono/wasm/runtime/startup.ts @@ -209,9 +209,6 @@ async function preRunAsync(userPreRun: (() => void)[]) { if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: preRunAsync"); const mark = startMeasure(); try { - if (MonoWasmThreads) { - await instantiateWasmPThreadWorkerPool(); - } // all user Module.preRun callbacks userPreRun.map(fn => fn()); endMeasure(mark, MeasuredBlock.preRun); @@ -234,12 +231,23 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) { beforeOnRuntimeInitialized.promise_control.resolve(); try { await wait_for_all_assets(); - // load runtime + + // load runtime and apply environment settings (if necessary) await mono_wasm_before_user_runtime_initialized(); - if (config.runtimeOptions) { - mono_wasm_set_runtime_options(config.runtimeOptions); + if (MonoWasmThreads) { + await instantiateWasmPThreadWorkerPool(); } + + bindings_init(); + if (!runtimeHelpers.mono_wasm_runtime_is_ready) mono_wasm_runtime_ready(); + if (!runtimeHelpers.mono_wasm_symbols_are_ready) readSymbolMapFile("dotnet.js.symbols"); + + setTimeout(() => { + // when there are free CPU cycles + string_decoder.init_fields(); + }); + // call user code try { userOnRuntimeInitialized(); @@ -266,6 +274,11 @@ async function postRunAsync(userpostRun: (() => void)[]) { if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: postRunAsync"); try { const mark = startMeasure(); + + // create /usr/share folder which is SpecialFolder.CommonApplicationData + Module["FS_createPath"]("/", "usr", true, true); + Module["FS_createPath"]("/", "usr/share", true, true); + // all user Module.postRun callbacks userpostRun.map(fn => fn()); endMeasure(mark, MeasuredBlock.postRun); @@ -339,27 +352,6 @@ async function mono_wasm_pre_init_full(): Promise { Module.removeRunDependency("mono_wasm_pre_init_full"); } -async function mono_wasm_before_user_runtime_initialized(): Promise { - if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: mono_wasm_before_user_runtime_initialized"); - - try { - await _apply_configuration_from_args(); - mono_wasm_globalization_init(); - - if (!runtimeHelpers.mono_wasm_load_runtime_done) mono_wasm_load_runtime("unused", config.debugLevel); - if (!runtimeHelpers.mono_wasm_runtime_is_ready) mono_wasm_runtime_ready(); - if (!runtimeHelpers.mono_wasm_symbols_are_ready) readSymbolMapFile("dotnet.js.symbols"); - - setTimeout(() => { - // when there are free CPU cycles - string_decoder.init_fields(); - }); - } catch (err: any) { - _print_error("MONO_WASM: Error in mono_wasm_before_user_runtime_initialized", err); - throw err; - } -} - async function mono_wasm_after_user_runtime_initialized(): Promise { if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: mono_wasm_after_user_runtime_initialized"); try { @@ -451,7 +443,6 @@ async function instantiate_wasm_module( ): Promise { // this is called so early that even Module exports like addRunDependency don't exist yet try { - replace_linker_placeholders(imports, export_linker()); await mono_wasm_load_config(Module.configSrc); if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: instantiate_wasm_module"); const assetToLoad = resolve_asset_path("dotnetwasm"); @@ -459,6 +450,8 @@ async function instantiate_wasm_module( await start_asset_download(assetToLoad); await beforePreInit.promise; Module.addRunDependency("instantiate_wasm_module"); + + replace_linker_placeholders(imports, export_linker()); await instantiate_wasm_asset(assetToLoad, imports, successCallback); assetToLoad.pendingDownloadInternal = null as any; // GC assetToLoad.pendingDownload = null as any; // GC @@ -474,10 +467,8 @@ async function instantiate_wasm_module( Module.removeRunDependency("instantiate_wasm_module"); } -async function _apply_configuration_from_args() { - // create /usr/share folder which is SpecialFolder.CommonApplicationData - Module["FS_createPath"]("/", "usr", true, true); - Module["FS_createPath"]("/", "usr/share", true, true); +async function mono_wasm_before_user_runtime_initialized() { + mono_wasm_globalization_init(); for (const k in config.environmentVariables) { const v = config.environmentVariables![k]; @@ -500,14 +491,13 @@ async function _apply_configuration_from_args() { if (MonoWasmThreads) { await mono_wasm_init_diagnostics(); } + + mono_wasm_load_runtime("unused", config.debugLevel); + } export function mono_wasm_load_runtime(unused?: string, debugLevel?: number): void { if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: mono_wasm_load_runtime"); - if (runtimeHelpers.mono_wasm_load_runtime_done) { - return; - } - runtimeHelpers.mono_wasm_load_runtime_done = true; try { const mark = startMeasure(); if (debugLevel == undefined) { @@ -519,7 +509,6 @@ export function mono_wasm_load_runtime(unused?: string, debugLevel?: number): vo cwraps.mono_wasm_load_runtime(unused || "unused", debugLevel); endMeasure(mark, MeasuredBlock.loadRuntime); - if (!runtimeHelpers.mono_wasm_bindings_is_ready) bindings_init(); } catch (err: any) { _print_error("MONO_WASM: mono_wasm_load_runtime () failed", err); diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts index 819f18ca6df5e0..718cb95bc5186d 100644 --- a/src/mono/wasm/runtime/types.ts +++ b/src/mono/wasm/runtime/types.ts @@ -209,7 +209,6 @@ export type RuntimeHelpers = { runtime_interop_exports_class: MonoClass; _i52_error_scratch_buffer: Int32Ptr; - mono_wasm_load_runtime_done: boolean; mono_wasm_runtime_is_ready: boolean; mono_wasm_bindings_is_ready: boolean; mono_wasm_symbols_are_ready: boolean;