-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[browser] mono_exit improvements (#88387)
- Loading branch information
1 parent
c93336a
commit 7980421
Showing
64 changed files
with
615 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TOP=../../../../.. | ||
|
||
include ../wasm.mk | ||
|
||
ifneq ($(AOT),) | ||
override MSBUILD_ARGS+=/p:RunAOTCompilation=true | ||
endif | ||
|
||
PROJECT_NAME=Wasm.Browser.Shutdown.Sample.csproj | ||
|
||
run: run-browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices.JavaScript; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Sample | ||
{ | ||
public partial class Test | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
return 0; | ||
} | ||
|
||
[JSExport()] | ||
public static void DoNothing () | ||
{ | ||
Console.WriteLine("You got it, boss! Doing nothing!"); | ||
} | ||
|
||
[JSExport()] | ||
public static void ThrowManagedException () | ||
{ | ||
throw new Exception("I'll make an exception to the rules just this once... and throw one."); | ||
} | ||
|
||
[JSExport()] | ||
public static void CallFailFast () | ||
{ | ||
System.Environment.FailFast("User requested FailFast"); | ||
} | ||
|
||
[JSImport("timerTick", "main.js")] | ||
public static partial void TimerTick (int i); | ||
|
||
[JSExport()] | ||
public static void StartTimer () | ||
{ | ||
int i = 0; | ||
var timer = new System.Timers.Timer(1000); | ||
timer.Elapsed += (s, e) => { | ||
TimerTick(i); | ||
i += 1; | ||
}; | ||
timer.AutoReset = true; | ||
timer.Enabled = true; | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/mono/sample/wasm/browser-shutdown/Wasm.Browser.Shutdown.Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\DefaultBrowserSample.targets" /> | ||
<ItemGroup> | ||
<WasmExtraFilesToDeploy Include="main.js" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
<!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
<html> | ||
|
||
<head> | ||
<title>Wasm Browser Shutdown Sample</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h3 id="header">Wasm Browser Shutdown Sample</h3> | ||
<button id="throw-managed-exc">Throw Managed Exception</button> | ||
<button id="trigger-native-assert">Trigger Native Assert</button> | ||
<button id="trigger-failfast">Trigger Environment.FailFast</button> | ||
<button id="call-jsexport">Call Harmless JSExport</button> | ||
<button id="call-exit">Call exit</button> | ||
<button id="start-timer">Start Timer</button><br> | ||
Timer Value: <span id="timer-value"></span> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import { dotnet, exit } from './_framework/dotnet.js' | ||
|
||
let exports = undefined, | ||
setenv = undefined; | ||
|
||
window.addEventListener("load", onLoad); | ||
|
||
try { | ||
const { setModuleImports, getAssemblyExports, setEnvironmentVariable, getConfig } = await dotnet | ||
.withModuleConfig() | ||
.withExitOnUnhandledError() | ||
.withExitCodeLogging() | ||
.withElementOnExit() | ||
.withAssertAfterExit() | ||
.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"); | ||
} | ||
}) | ||
.create(); | ||
|
||
setModuleImports("main.js", { | ||
timerTick: (i) => { | ||
document.querySelector("#timer-value").textContent = i; | ||
}, | ||
}); | ||
|
||
setenv = setEnvironmentVariable; | ||
const config = getConfig(); | ||
exports = await getAssemblyExports(config.mainAssemblyName); | ||
} | ||
catch (err) { | ||
exit(2, err); | ||
} | ||
|
||
function onLoad() { | ||
document.querySelector("#throw-managed-exc").addEventListener("click", () => { | ||
try { | ||
exports.Sample.Test.ThrowManagedException(); | ||
alert("No JS exception was thrown!"); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
document.querySelector("#trigger-failfast").addEventListener("click", () => { | ||
try { | ||
exports.Sample.Test.CallFailFast(); | ||
alert("No JS exception was thrown!"); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
document.querySelector("#start-timer").addEventListener("click", () => { | ||
try { | ||
exports.Sample.Test.StartTimer(); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
document.querySelector("#trigger-native-assert").addEventListener("click", () => { | ||
try { | ||
setenv(null, null); | ||
alert("No JS exception was thrown!"); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
document.querySelector("#call-jsexport").addEventListener("click", () => { | ||
try { | ||
exports.Sample.Test.DoNothing(); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
document.querySelector("#call-exit").addEventListener("click", () => { | ||
try { | ||
exit(7, "User clicked exit"); | ||
} catch (exc) { | ||
alert(exc); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.