Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export async function runSecondRuntimeAndTestStaticState(guid) {
const { dotnet: dotnet2 } = await import('./_framework/dotnet.js?instance=2-' + guid);
const runtime2 = await dotnet2
.withConfig({
forwardConsoleLogsToWS: false,
forwardConsole: false,
diagnosticTracing: false,
appendElementOnExit: false,
logExitCode: false,
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/sendtohelix-browser.targets
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<ItemGroup>
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnV8'" Include="$(TestArchiveRoot)runonly/**/*.Console.V8.*.Sample.zip" />
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnChrome'" Include="$(TestArchiveRoot)runonly/**/*.Browser.*.Sample.zip" />
<!-- xharness -> selenium -> firefox doesn't support forwarding console without dotnet.withConsoleForwarding()
<!-- xharness -> selenium -> firefox doesn't support forwarding console without forwardConsole
<_WasmSampleZipFile Condition="'$(Scenario)' == 'WasmTestOnFirefox'" Include="$(TestArchiveRoot)runonly/**/*.Browser.*.Sample.zip" />
-->

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/interp-pgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export async function getCacheKey (prefix: string): Promise<string | null> {
// timezone is part of env variables, so it is already in the hash

// some things are not relevant for config hash
delete inputs.forwardConsoleLogsToWS;
delete inputs.forwardConsole;
delete inputs.diagnosticTracing;
delete inputs.appendElementOnExit;
delete inputs.interopCleanupOnExit;
Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/loader/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ function logOnExit (exit_code: number, reason: any) {
}
if (!ENVIRONMENT_IS_WORKER && loaderHelpers.config) {
if (loaderHelpers.config.logExitCode) {
if (loaderHelpers.config.forwardConsoleLogsToWS) {
if (loaderHelpers.config.forwardConsole) {
teardown_proxy_console("WASM EXIT " + exit_code);
} else {
mono_log_info_no_prefix("WASM EXIT " + exit_code);
}
} else if (loaderHelpers.config.forwardConsoleLogsToWS) {
} else if (loaderHelpers.config.forwardConsole) {
teardown_proxy_console();
}
}
Expand Down
124 changes: 4 additions & 120 deletions src/mono/browser/runtime/loader/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,125 +32,6 @@ export class HostBuilder implements DotnetHostBuilder {
}
}

// internal
withOnConfigLoaded (onConfigLoaded: (config: MonoConfig) => void | Promise<void>): DotnetHostBuilder {
try {
deep_merge_module(emscriptenModule, {
onConfigLoaded
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withConsoleForwarding (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
forwardConsoleLogsToWS: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withExitOnUnhandledError (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
exitOnUnhandledError: true
});
installUnhandledErrorHandler();
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withAsyncFlushOnExit (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
asyncFlushOnExit: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withExitCodeLogging (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
logExitCode: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withElementOnExit (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
appendElementOnExit: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withInteropCleanupOnExit (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
interopCleanupOnExit: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
withDumpThreadsOnNonZeroExit (): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
dumpThreadsOnNonZeroExit: true
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

// internal
// todo fallback later by debugLevel
withWaitingForDebugger (level: number): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
waitForDebugger: level
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}

withInterpreterPgo (value: boolean, autoSaveDelay?: number): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
Expand Down Expand Up @@ -393,7 +274,7 @@ async function prepareEmscripten (moduleFactory: DotnetModuleConfig | ((api: Run
return;
}
emscriptenPrepared = true;
if (ENVIRONMENT_IS_WEB && loaderHelpers.config.forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
if (ENVIRONMENT_IS_WEB && loaderHelpers.config.forwardConsole && typeof globalThis.WebSocket != "undefined") {
setup_proxy_console("main", globalThis.console, globalThis.location.origin);
}
mono_assert(emscriptenModule, "Null moduleConfig");
Expand Down Expand Up @@ -423,6 +304,9 @@ export async function createEmscripten (moduleFactory: DotnetModuleConfig | ((ap
mono_log_info(`starting script ${loaderHelpers.scriptUrl}`);
mono_log_info(`starting in ${loaderHelpers.scriptDirectory}`);
}
if (loaderHelpers.config.exitOnUnhandledError) {
installUnhandledErrorHandler();
}

registerEmscriptenExitHandlers();

Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/loader/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function onMonoConfigReceived (config: MonoConfigInternal, monoThreadInfo: PThre
workerMonoConfigReceived = true;
loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config);

if (ENVIRONMENT_IS_WEB && config.forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
if (ENVIRONMENT_IS_WEB && config.forwardConsole && typeof globalThis.WebSocket != "undefined") {
loaderHelpers.setup_proxy_console("worker-idle", console, globalThis.location.origin);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/pthreads/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function update_thread_info (): void {
monoThreadInfo.threadPrefix = `${hexPrefix}${hexPtr}-${threadType}`;

loaderHelpers.set_thread_prefix(monoThreadInfo.threadPrefix!);
if (!loaderHelpers.config.forwardConsoleLogsToWS) {
if (!loaderHelpers.config.forwardConsole) {
set_thread_prefix(monoThreadInfo.threadPrefix!);
}

Expand Down
3 changes: 1 addition & 2 deletions src/mono/browser/runtime/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export function coerceNull<T extends ManagedPointer | NativePointer> (ptr: T | n

// when adding new fields, please consider if it should be impacting the config hash. If not, please drop it in the getCacheKey()
export type MonoConfigInternal = MonoConfig & {
linkerEnabled?: boolean,
assets?: AssetEntryInternal[],
runtimeOptions?: string[], // array of runtime options as strings
aotProfilerOptions?: AOTProfilerOptions, // dictionary-style Object. If omitted, aot profiler will not be initialized.
Expand All @@ -83,7 +82,7 @@ export type MonoConfigInternal = MonoConfig & {
interopCleanupOnExit?: boolean
dumpThreadsOnNonZeroExit?: boolean
logExitCode?: boolean
forwardConsoleLogsToWS?: boolean,
forwardConsole?: boolean,
asyncFlushOnExit?: boolean
exitOnUnhandledError?: boolean
loadAllSatelliteResources?: boolean
Expand Down
25 changes: 12 additions & 13 deletions src/mono/browser/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function initRunArgs(runArgs) {
runArgs.debugging = runArgs.debugging === undefined ? false : runArgs.debugging;
runArgs.configSrc = runArgs.configSrc === undefined ? './_framework/dotnet.boot.js' : runArgs.configSrc;
// default'ing to true for tests, unless debugging
runArgs.forwardConsole = runArgs.forwardConsole === undefined ? !runArgs.debugging : runArgs.forwardConsole;
runArgs.forwardConsole = runArgs.forwardConsole === undefined ? isFirefox && !runArgs.debugging : runArgs.forwardConsole;
runArgs.interpreterPgo = runArgs.interpreterPgo === undefined ? false : runArgs.interpreterPgo;

return runArgs;
Expand Down Expand Up @@ -256,20 +256,20 @@ function configureRuntime(dotnet, runArgs) {
.withVirtualWorkingDirectory(runArgs.workingDirectory)
.withEnvironmentVariables(runArgs.environmentVariables)
.withDiagnosticTracing(runArgs.diagnosticTracing)
.withExitOnUnhandledError()
.withExitCodeLogging()
.withElementOnExit()
.withInteropCleanupOnExit()
.withDumpThreadsOnNonZeroExit()
.withConfig({
appendElementOnExit: true,
logExitCode: true,
exitOnUnhandledError: true,
forwardConsole: runArgs.forwardConsole,
asyncFlushOnExit: ENVIRONMENT_IS_NODE,
interopCleanupOnExit: true,
dumpThreadsOnNonZeroExit: true,
loadAllSatelliteResources: true,
jsThreadBlockingMode: "ThrowWhenBlockingWait",
});

if (ENVIRONMENT_IS_NODE) {
dotnet
.withEnvironmentVariable("NodeJSPlatform", process.platform)
.withAsyncFlushOnExit();
dotnet.withEnvironmentVariable("NodeJSPlatform", process.platform);

const modulesToLoad = runArgs.environmentVariables["NPM_MODULES"];
if (modulesToLoad) {
Expand All @@ -296,10 +296,9 @@ function configureRuntime(dotnet, runArgs) {
}
if (runArgs.debugging) {
dotnet.withDebugging(-1);
dotnet.withWaitingForDebugger(-1);
}
if (runArgs.forwardConsole) {
dotnet.withConsoleForwarding();
dotnet.withConfig({
waitForDebugger: -1
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ Copyright (c) .NET Foundation. All rights reserved.
Endpoints="@(_WasmResolvedEndpoints)"
DebugBuild="true"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="false"
CacheBootResources="$(_BlazorCacheBootResources)"
MergeWith="@(_WasmDotnetJsForBuild)"
OutputPath="$(_WasmBuildBootJsonPath)"
Expand Down Expand Up @@ -860,7 +859,6 @@ Copyright (c) .NET Foundation. All rights reserved.
Endpoints="@(_WasmResolvedEndpointsForPublish)"
DebugBuild="false"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="$(PublishTrimmed)"
CacheBootResources="$(_BlazorCacheBootResources)"
MergeWith="@(_WasmDotnetJsForPublish)"
OutputPath="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-advanced/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ try {
return originalFetch(url, fetchArgs);
};
dotnet
.withElementOnExit()
// 'withModuleConfig' is internal lower level API
// here we show how emscripten could be further configured
// It is preferred to use specific 'with***' methods instead in all other cases.
.withConfig({
appendElementOnExit: true,
maxParallelDownloads: 1,
resources: {
modulesAfterConfigLoaded: [{
Expand Down
3 changes: 1 addition & 2 deletions src/mono/sample/wasm/browser-bench/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ try {
// console to see statistics on how much code it generated and whether any new opcodes
// are causing traces to fail to compile
.withRuntimeOptions(["--jiterpreter-stats-enabled"])
.withElementOnExit()
.withExitCodeLogging()
.withConfig({ exitOnUnhandledError: true, logExitCode: true, appendElementOnExit: true })
.create();

await mainApp.init(runtime);
Expand Down
3 changes: 1 addition & 2 deletions src/mono/sample/wasm/browser-eventpipe/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ try {
"--no-jiterpreter-interp-entry-enabled",
"--no-jiterpreter-jit-call-enabled",
])*/
.withElementOnExit()
.withExitOnUnhandledError()
.withConfig({ appendElementOnExit: true, exitOnUnhandledError: true })
.create();

setModuleImports("main.js", {
Expand Down
9 changes: 5 additions & 4 deletions src/mono/sample/wasm/browser-logprofile/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function saveProfile(Module) {
}

function readProfileFile(Module) {
let profileFilePath="output.mlpd";
let profileFilePath = "output.mlpd";

var stat = Module.FS.stat(profileFilePath);

Expand All @@ -33,10 +33,11 @@ function readProfileFile(Module) {
}

try {
const { INTERNAL, Module, getAssemblyExports: getAssemblyExports } = await dotnet
.withElementOnExit()
.withExitCodeLogging()
const { Module, getAssemblyExports: getAssemblyExports } = await dotnet
.withConfig({
appendElementOnExit: true,
exitOnUnhandledError: true,
logExitCode: true,
logProfilerOptions: {
takeHeapshot: "Sample.Test::TakeHeapshot",
configuration: "log:alloc,output=output.mlpd"
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/browser-profile/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function saveProfile(aotProfileData) {
}
try {
const { INTERNAL, getAssemblyExports: getAssemblyExports } = await dotnet
.withElementOnExit()
.withExitCodeLogging()
.withConfig({
appendElementOnExit: true,
logExitCode: true,
aotProfilerOptions: {
writeAt: "Sample.Test::StopProfile",
sendTo: "System.Runtime.InteropServices.JavaScript.JavaScriptExports::DumpAotProfileData"
Expand Down
16 changes: 8 additions & 8 deletions src/mono/sample/wasm/browser-shutdown/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ window.addEventListener("load", onLoad);
try {
const { setModuleImports, getAssemblyExports, setEnvironmentVariable, getConfig } = await dotnet
.withModuleConfig()
.withExitOnUnhandledError()
.withExitCodeLogging()
.withElementOnExit()
.withOnConfigLoaded(() => {
// you can test abort of the startup by opening http://localhost:8000/?throwError=true
const params = new URLSearchParams(location.search);
if (params.get("throwError") === "true") {
throw new Error("Error thrown from OnConfigLoaded");
.withConfig({ appendElementOnExit: true, exitOnUnhandledError: true, logExitCode: true })
.withModuleConfig({
onConfigLoaded: () => {
// you can test abort of the startup by opening http://localhost:8000/?throwError=true
const params = new URLSearchParams(location.search);
if (params.get("throwError") === "true") {
throw new Error("Error thrown from OnConfigLoaded");
}
}
})
.create();
Expand Down
6 changes: 3 additions & 3 deletions src/mono/sample/wasm/browser-threads/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ try {

const { setModuleImports, getAssemblyExports, runMain } = await dotnet
.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
.withElementOnExit()
.withExitCodeLogging()
.withExitOnUnhandledError()
.withConfig({
appendElementOnExit: true,
exitOnUnhandledError: true,
logExitCode: true,
jsThreadBlockingMode: "WarnWhenBlockingWait",
})
.create();
Expand Down
Loading
Loading