Skip to content

Commit 3ba6299

Browse files
committed
- diagnosticTracing reduce noise
- rename loaderConfig
1 parent 590c414 commit 3ba6299

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/native/corehost/browserhost/loader/host-builder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import type { DotnetHostBuilder, LoaderConfig, RuntimeAPI, LoadBootResourceCallback, DotnetModuleConfig } from "./types";
55

66
import { Module, dotnetApi } from "./cross-module";
7-
import { getLoaderConfig, mergeLoaderConfig, validateLoaderConfig } from "./config";
7+
import { loaderConfig, mergeLoaderConfig, validateLoaderConfig } from "./config";
88
import { createRuntime } from "./run";
99
import { exit } from "./exit";
1010
import { setLoadBootResourceCallback } from "./assets";
@@ -134,8 +134,7 @@ export class HostBuilder implements DotnetHostBuilder {
134134
await this.create();
135135
}
136136
validateLoaderConfig();
137-
const config = getLoaderConfig();
138-
return this.dotnetApi!.runMain(config.mainAssemblyName, applicationArguments);
137+
return this.dotnetApi!.runMain(loaderConfig.mainAssemblyName, applicationArguments);
139138
} catch (err) {
140139
exit(1, err);
141140
throw err;
@@ -148,8 +147,7 @@ export class HostBuilder implements DotnetHostBuilder {
148147
await this.create();
149148
}
150149
validateLoaderConfig();
151-
const config = getLoaderConfig();
152-
return this.dotnetApi!.runMainAndExit(config.mainAssemblyName, applicationArguments);
150+
return this.dotnetApi!.runMainAndExit(loaderConfig.mainAssemblyName, applicationArguments);
153151
} catch (err) {
154152
exit(1, err);
155153
throw err;

src/native/corehost/browserhost/loader/logging.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
import { loaderConfig } from "./config";
5+
46
export function check(condition: unknown, message: string): asserts condition {
57
if (!condition) {
68
throw new Error(`dotnetAssert failed: ${message}`);
@@ -22,6 +24,9 @@ export function fastCheck(condition: unknown, messageFactory: (() => string)): a
2224
const prefix = "DOTNET: ";
2325

2426
export function debug(msg: string | (() => string), ...data: any) {
27+
if (!loaderConfig.diagnosticTracing) {
28+
return;
29+
}
2530
if (typeof msg === "function") {
2631
msg = msg();
2732
}

src/native/libs/System.Native.Browser/diagnostics/console-proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const methods = ["log", "debug", "info", "warn", "error", "trace"];
1111
let originalConsoleMethods: { [key: string]: any } = {};
1212

1313
export function installLoggingProxy() {
14-
const config = dotnetApi.getConfig() as LoaderConfigInternal;
15-
if (ENVIRONMENT_IS_WEB && config.forwardConsole && typeof globalThis.WebSocket != "undefined") {
14+
const loaderConfig = dotnetApi.getConfig() as LoaderConfigInternal;
15+
if (ENVIRONMENT_IS_WEB && loaderConfig.forwardConsole && typeof globalThis.WebSocket != "undefined") {
1616
setupProxyConsole(globalThis.console, globalThis.location.origin);
1717
}
1818
}

src/native/libs/System.Native.Browser/diagnostics/exit.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_WEB } from "./per-module";
77
import { teardownProxyConsole } from "./console-proxy";
88
import { symbolicateStackTrace } from "./symbolicate";
99

10-
let config: LoaderConfigInternal = null as any;
10+
let loaderConfig: LoaderConfigInternal = null as any;
1111
export function registerExit() {
1212
if (!dotnetApi || !dotnetApi.getConfig || !dotnetLoaderExports) {
1313
return;
1414
}
15-
config = dotnetApi.getConfig() as LoaderConfigInternal;
16-
if (!config) {
15+
loaderConfig = dotnetApi.getConfig() as LoaderConfigInternal;
16+
if (!loaderConfig) {
1717
return;
1818
}
1919
installUnhandledErrorHandler();
@@ -22,21 +22,21 @@ export function registerExit() {
2222
}
2323

2424
function onExit(exitCode: number, reason: any, silent: boolean): boolean {
25-
if (!config) {
25+
if (!loaderConfig) {
2626
return true;
2727
}
2828
uninstallUnhandledErrorHandler();
29-
if (config.logExitCode) {
29+
if (loaderConfig.logExitCode) {
3030
if (!silent) {
3131
logExitReason(exitCode, reason);
3232
}
3333
logExitCode(exitCode);
3434
}
35-
if (ENVIRONMENT_IS_WEB && config.appendElementOnExit) {
35+
if (ENVIRONMENT_IS_WEB && loaderConfig.appendElementOnExit) {
3636
appendElementOnExit(exitCode);
3737
}
3838

39-
if (ENVIRONMENT_IS_NODE && config.asyncFlushOnExit && exitCode === 0) {
39+
if (ENVIRONMENT_IS_NODE && loaderConfig.asyncFlushOnExit && exitCode === 0) {
4040
// this would NOT call Node's exit() immediately, it's a hanging promise
4141
(async function flush() {
4242
try {
@@ -78,10 +78,10 @@ function isExitStatus(reason: any): boolean {
7878
}
7979

8080
function logExitCode(exitCode: number): void {
81-
const message = config.logExitCode
81+
const message = loaderConfig.logExitCode
8282
? "WASM EXIT " + exitCode
8383
: undefined;
84-
if (config.forwardConsole) {
84+
if (loaderConfig.forwardConsole) {
8585
teardownProxyConsole(message);
8686
} else if (message) {
8787
// eslint-disable-next-line no-console
@@ -101,7 +101,7 @@ function appendElementOnExit(exitCode: number): void {
101101

102102
function installUnhandledErrorHandler() {
103103
// it seems that emscripten already does the right thing for NodeJs and that there is no good solution for V8 shell.
104-
if (ENVIRONMENT_IS_WEB && config.exitOnUnhandledError) {
104+
if (ENVIRONMENT_IS_WEB && loaderConfig.exitOnUnhandledError) {
105105
globalThis.addEventListener("unhandledrejection", unhandledRejectionHandler);
106106
globalThis.addEventListener("error", errorHandler);
107107
}

0 commit comments

Comments
 (0)