[browser][wasm] Fix CoreCLR Emscripten out/err override#127315
[browser][wasm] Fix CoreCLR Emscripten out/err override#127315pavelsavara wants to merge 3 commits intodotnet:mainfrom
Conversation
Bridge user-provided out/err overrides to Emscripten's print/printErr in the CoreCLR loader, matching Mono's existing behavior. - Add print/printErr to EmscriptenModuleInternal type - Wire Module.out/err to Module.print/printErr before native module loads - Enable OutErrOverrideWorks test for CoreCLR Fixes dotnet#124945
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
There was a problem hiding this comment.
Pull request overview
Bridges user-supplied Module.out/Module.err overrides to Emscripten’s print/printErr in the CoreCLR browser WASM loader so custom output handlers are honored during Emscripten initialization (matching Mono behavior).
Changes:
- Extend CoreCLR loader’s internal Emscripten module typing to include
print/printErr. - In CoreCLR loader startup, map
Module.out→Module.printandModule.err→Module.printErrbefore the native module initializes. - Enable the existing
OutErrOverrideWorksWASM build test for CoreCLR by removing the Mono-only conditional.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/native/libs/Common/JavaScript/types/internal.ts | Adds print/printErr to the internal module type to support bridging code. |
| src/native/libs/Common/JavaScript/loader/run.ts | Wires out/err to print/printErr before native module load so Emscripten picks them up. |
| src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs | Runs OutErrOverrideWorks for CoreCLR as well (no longer Mono-only). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a behavioral gap in the CoreCLR browser WASM loader by ensuring user-provided out / err overrides (passed via dotnet.withModuleConfig) are forwarded to Emscripten’s print / printErr, aligning CoreCLR behavior with the existing Mono runtime behavior.
Changes:
- Extend CoreCLR’s internal Emscripten module typing to include
print/printErr. - In the CoreCLR JS loader, map
Module.out/Module.errtoModule.print/Module.printErrbefore the native module initializes. - Enable the existing
OutErrOverrideWorksWASM build test to run for CoreCLR (not Mono-only).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/native/libs/Common/JavaScript/types/internal.ts | Adds internal typing for print / printErr on the Emscripten module shape. |
| src/native/libs/Common/JavaScript/loader/run.ts | Bridges out/err to print/printErr early during runtime creation. |
| src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs | Removes Mono-only guard so the out/err override test executes for CoreCLR too. |
| if (!Module.out) { | ||
| // eslint-disable-next-line no-console | ||
| Module.out = console.log.bind(console); | ||
| } | ||
| if (!Module.err) { | ||
| // eslint-disable-next-line no-console | ||
| Module.err = console.error.bind(console); | ||
| } | ||
| if (!Module.print) { | ||
| Module.print = Module.out; | ||
| } | ||
| if (!Module.printErr) { |
Summary
Bridge user-provided
out/erroverrides to Emscripten'sprint/printErrin the CoreCLR browser WASM loader, matching Mono's existing behavior.Note
This PR was AI/Copilot-generated.
Problem
When using
dotnet.withModuleConfig({ out: fn, err: fn })with the CoreCLR runtime on browser WASM, the custom output handlers were not being called. The Mono runtime handled this correctly viaconfigureRuntimeStartup()instartup.ts, but the CoreCLR loader had no equivalent bridging logic.Changes
src/native/libs/Common/JavaScript/types/internal.ts: AddedprintandprintErrtoEmscriptenModuleInternaltypesrc/native/libs/Common/JavaScript/loader/run.ts: WireModule.out/Module.errtoModule.print/Module.printErrbefore the native module loads, so Emscripten picks them up during initializationsrc/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs: Removed Mono-only restriction fromOutErrOverrideWorkstest so it also runs for CoreCLRTesting
Wasm.Build.Tests.ModuleConfigTests— Total: 5, Errors: 0, Failed: 0, Skipped: 0 (withRuntimeFlavor=CoreCLR)Fixes #124945