Skip to content

Commit e65cd58

Browse files
authored
[browser][mono] simplify internal testing switches (#122616)
1 parent a61c6f8 commit e65cd58

File tree

25 files changed

+55
-193
lines changed

25 files changed

+55
-193
lines changed

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export async function runSecondRuntimeAndTestStaticState(guid) {
22
const { dotnet: dotnet2 } = await import('./_framework/dotnet.js?instance=2-' + guid);
33
const runtime2 = await dotnet2
44
.withConfig({
5-
forwardConsoleLogsToWS: false,
5+
forwardConsole: false,
66
diagnosticTracing: false,
77
appendElementOnExit: false,
88
logExitCode: false,

src/libraries/sendtohelix-browser.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
<ItemGroup>
247247
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnV8'" Include="$(TestArchiveRoot)runonly/**/*.Console.V8.*.Sample.zip" />
248248
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnChrome'" Include="$(TestArchiveRoot)runonly/**/*.Browser.*.Sample.zip" />
249-
<!-- xharness -> selenium -> firefox doesn't support forwarding console without dotnet.withConsoleForwarding()
249+
<!-- xharness -> selenium -> firefox doesn't support forwarding console without forwardConsole
250250
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnFirefox'" Include="$(TestArchiveRoot)runonly/**/*.Browser.*.Sample.zip" />
251251
-->
252252

src/mono/browser/runtime/interp-pgo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export async function getCacheKey (prefix: string): Promise<string | null> {
190190
// timezone is part of env variables, so it is already in the hash
191191

192192
// some things are not relevant for config hash
193-
delete inputs.forwardConsoleLogsToWS;
193+
delete inputs.forwardConsole;
194194
delete inputs.diagnosticTracing;
195195
delete inputs.appendElementOnExit;
196196
delete inputs.interopCleanupOnExit;

src/mono/browser/runtime/loader/exit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ function logOnExit (exit_code: number, reason: any) {
279279
}
280280
if (!ENVIRONMENT_IS_WORKER && loaderHelpers.config) {
281281
if (loaderHelpers.config.logExitCode) {
282-
if (loaderHelpers.config.forwardConsoleLogsToWS) {
282+
if (loaderHelpers.config.forwardConsole) {
283283
teardown_proxy_console("WASM EXIT " + exit_code);
284284
} else {
285285
mono_log_info_no_prefix("WASM EXIT " + exit_code);
286286
}
287-
} else if (loaderHelpers.config.forwardConsoleLogsToWS) {
287+
} else if (loaderHelpers.config.forwardConsole) {
288288
teardown_proxy_console();
289289
}
290290
}

src/mono/browser/runtime/loader/run.ts

Lines changed: 4 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -32,125 +32,6 @@ export class HostBuilder implements DotnetHostBuilder {
3232
}
3333
}
3434

35-
// internal
36-
withOnConfigLoaded (onConfigLoaded: (config: MonoConfig) => void | Promise<void>): DotnetHostBuilder {
37-
try {
38-
deep_merge_module(emscriptenModule, {
39-
onConfigLoaded
40-
});
41-
return this;
42-
} catch (err) {
43-
mono_exit(1, err);
44-
throw err;
45-
}
46-
}
47-
48-
// internal
49-
withConsoleForwarding (): DotnetHostBuilder {
50-
try {
51-
deep_merge_config(monoConfig, {
52-
forwardConsoleLogsToWS: true
53-
});
54-
return this;
55-
} catch (err) {
56-
mono_exit(1, err);
57-
throw err;
58-
}
59-
}
60-
61-
// internal
62-
withExitOnUnhandledError (): DotnetHostBuilder {
63-
try {
64-
deep_merge_config(monoConfig, {
65-
exitOnUnhandledError: true
66-
});
67-
installUnhandledErrorHandler();
68-
return this;
69-
} catch (err) {
70-
mono_exit(1, err);
71-
throw err;
72-
}
73-
}
74-
75-
// internal
76-
withAsyncFlushOnExit (): DotnetHostBuilder {
77-
try {
78-
deep_merge_config(monoConfig, {
79-
asyncFlushOnExit: true
80-
});
81-
return this;
82-
} catch (err) {
83-
mono_exit(1, err);
84-
throw err;
85-
}
86-
}
87-
88-
// internal
89-
withExitCodeLogging (): DotnetHostBuilder {
90-
try {
91-
deep_merge_config(monoConfig, {
92-
logExitCode: true
93-
});
94-
return this;
95-
} catch (err) {
96-
mono_exit(1, err);
97-
throw err;
98-
}
99-
}
100-
101-
// internal
102-
withElementOnExit (): DotnetHostBuilder {
103-
try {
104-
deep_merge_config(monoConfig, {
105-
appendElementOnExit: true
106-
});
107-
return this;
108-
} catch (err) {
109-
mono_exit(1, err);
110-
throw err;
111-
}
112-
}
113-
114-
// internal
115-
withInteropCleanupOnExit (): DotnetHostBuilder {
116-
try {
117-
deep_merge_config(monoConfig, {
118-
interopCleanupOnExit: true
119-
});
120-
return this;
121-
} catch (err) {
122-
mono_exit(1, err);
123-
throw err;
124-
}
125-
}
126-
127-
// internal
128-
withDumpThreadsOnNonZeroExit (): DotnetHostBuilder {
129-
try {
130-
deep_merge_config(monoConfig, {
131-
dumpThreadsOnNonZeroExit: true
132-
});
133-
return this;
134-
} catch (err) {
135-
mono_exit(1, err);
136-
throw err;
137-
}
138-
}
139-
140-
// internal
141-
// todo fallback later by debugLevel
142-
withWaitingForDebugger (level: number): DotnetHostBuilder {
143-
try {
144-
deep_merge_config(monoConfig, {
145-
waitForDebugger: level
146-
});
147-
return this;
148-
} catch (err) {
149-
mono_exit(1, err);
150-
throw err;
151-
}
152-
}
153-
15435
withInterpreterPgo (value: boolean, autoSaveDelay?: number): DotnetHostBuilder {
15536
try {
15637
deep_merge_config(monoConfig, {
@@ -393,7 +274,7 @@ async function prepareEmscripten (moduleFactory: DotnetModuleConfig | ((api: Run
393274
return;
394275
}
395276
emscriptenPrepared = true;
396-
if (ENVIRONMENT_IS_WEB && loaderHelpers.config.forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
277+
if (ENVIRONMENT_IS_WEB && loaderHelpers.config.forwardConsole && typeof globalThis.WebSocket != "undefined") {
397278
setup_proxy_console("main", globalThis.console, globalThis.location.origin);
398279
}
399280
mono_assert(emscriptenModule, "Null moduleConfig");
@@ -423,6 +304,9 @@ export async function createEmscripten (moduleFactory: DotnetModuleConfig | ((ap
423304
mono_log_info(`starting script ${loaderHelpers.scriptUrl}`);
424305
mono_log_info(`starting in ${loaderHelpers.scriptDirectory}`);
425306
}
307+
if (loaderHelpers.config.exitOnUnhandledError) {
308+
installUnhandledErrorHandler();
309+
}
426310

427311
registerEmscriptenExitHandlers();
428312

src/mono/browser/runtime/loader/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function onMonoConfigReceived (config: MonoConfigInternal, monoThreadInfo: PThre
4343
workerMonoConfigReceived = true;
4444
loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config);
4545

46-
if (ENVIRONMENT_IS_WEB && config.forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
46+
if (ENVIRONMENT_IS_WEB && config.forwardConsole && typeof globalThis.WebSocket != "undefined") {
4747
loaderHelpers.setup_proxy_console("worker-idle", console, globalThis.location.origin);
4848
}
4949
}

src/mono/browser/runtime/pthreads/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function update_thread_info (): void {
5252
monoThreadInfo.threadPrefix = `${hexPrefix}${hexPtr}-${threadType}`;
5353

5454
loaderHelpers.set_thread_prefix(monoThreadInfo.threadPrefix!);
55-
if (!loaderHelpers.config.forwardConsoleLogsToWS) {
55+
if (!loaderHelpers.config.forwardConsole) {
5656
set_thread_prefix(monoThreadInfo.threadPrefix!);
5757
}
5858

src/mono/browser/runtime/types/internal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export function coerceNull<T extends ManagedPointer | NativePointer> (ptr: T | n
7373

7474
// when adding new fields, please consider if it should be impacting the config hash. If not, please drop it in the getCacheKey()
7575
export type MonoConfigInternal = MonoConfig & {
76-
linkerEnabled?: boolean,
7776
assets?: AssetEntryInternal[],
7877
runtimeOptions?: string[], // array of runtime options as strings
7978
aotProfilerOptions?: AOTProfilerOptions, // dictionary-style Object. If omitted, aot profiler will not be initialized.
@@ -83,7 +82,7 @@ export type MonoConfigInternal = MonoConfig & {
8382
interopCleanupOnExit?: boolean
8483
dumpThreadsOnNonZeroExit?: boolean
8584
logExitCode?: boolean
86-
forwardConsoleLogsToWS?: boolean,
85+
forwardConsole?: boolean,
8786
asyncFlushOnExit?: boolean
8887
exitOnUnhandledError?: boolean
8988
loadAllSatelliteResources?: boolean

src/mono/browser/test-main.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,20 @@ function configureRuntime(dotnet, runArgs) {
256256
.withVirtualWorkingDirectory(runArgs.workingDirectory)
257257
.withEnvironmentVariables(runArgs.environmentVariables)
258258
.withDiagnosticTracing(runArgs.diagnosticTracing)
259-
.withExitOnUnhandledError()
260-
.withExitCodeLogging()
261-
.withElementOnExit()
262-
.withInteropCleanupOnExit()
263-
.withDumpThreadsOnNonZeroExit()
264259
.withConfig({
260+
appendElementOnExit: true,
261+
logExitCode: true,
262+
exitOnUnhandledError: true,
263+
forwardConsole: runArgs.forwardConsole,
264+
asyncFlushOnExit: ENVIRONMENT_IS_NODE,
265+
interopCleanupOnExit: true,
266+
dumpThreadsOnNonZeroExit: true,
265267
loadAllSatelliteResources: true,
266268
jsThreadBlockingMode: "ThrowWhenBlockingWait",
267269
});
268270

269271
if (ENVIRONMENT_IS_NODE) {
270-
dotnet
271-
.withEnvironmentVariable("NodeJSPlatform", process.platform)
272-
.withAsyncFlushOnExit();
272+
dotnet.withEnvironmentVariable("NodeJSPlatform", process.platform);
273273

274274
const modulesToLoad = runArgs.environmentVariables["NPM_MODULES"];
275275
if (modulesToLoad) {
@@ -296,10 +296,9 @@ function configureRuntime(dotnet, runArgs) {
296296
}
297297
if (runArgs.debugging) {
298298
dotnet.withDebugging(-1);
299-
dotnet.withWaitingForDebugger(-1);
300-
}
301-
if (runArgs.forwardConsole) {
302-
dotnet.withConsoleForwarding();
299+
dotnet.withConfig({
300+
waitForDebugger: -1
301+
});
303302
}
304303
}
305304

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ Copyright (c) .NET Foundation. All rights reserved.
451451
Endpoints="@(_WasmResolvedEndpoints)"
452452
DebugBuild="true"
453453
DebugLevel="$(WasmDebugLevel)"
454-
LinkerEnabled="false"
455454
CacheBootResources="$(_BlazorCacheBootResources)"
456455
MergeWith="@(_WasmDotnetJsForBuild)"
457456
OutputPath="$(_WasmBuildBootJsonPath)"
@@ -865,7 +864,6 @@ Copyright (c) .NET Foundation. All rights reserved.
865864
Endpoints="@(_WasmResolvedEndpointsForPublish)"
866865
DebugBuild="false"
867866
DebugLevel="$(WasmDebugLevel)"
868-
LinkerEnabled="$(PublishTrimmed)"
869867
CacheBootResources="$(_BlazorCacheBootResources)"
870868
MergeWith="@(_WasmDotnetJsForPublish)"
871869
OutputPath="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"

0 commit comments

Comments
 (0)