Skip to content

Commit 021af3f

Browse files
committed
wip
1 parent 53a10ea commit 021af3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+487
-124
lines changed

src/libraries/tests.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-webpack\Wasm.Browser.WebPack.Sample.csproj" />
4444
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\node-webpack\Wasm.Node.WebPack.Sample.csproj" />
4545
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-nextjs\Wasm.Browser.NextJs.Sample.csproj" />
46+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-shutdown\Wasm.Browser.Shutdown.Sample.csproj" />
4647

4748
<!-- These tests are completely disabled on wasm -->
4849
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Generators.Tests/System.Text.RegularExpressions.Generators.Tests.csproj" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TOP=../../../../..
2+
3+
include ../wasm.mk
4+
5+
ifneq ($(AOT),)
6+
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
7+
endif
8+
9+
PROJECT_NAME=Wasm.Browser.Shutdown.Sample.csproj
10+
11+
run: run-browser
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.InteropServices.JavaScript;
6+
using System.Runtime.InteropServices;
7+
8+
namespace Sample
9+
{
10+
public partial class Test
11+
{
12+
public static int Main(string[] args)
13+
{
14+
return 0;
15+
}
16+
17+
[JSExport()]
18+
public static void DoNothing ()
19+
{
20+
Console.WriteLine("You got it, boss! Doing nothing!");
21+
}
22+
23+
[JSExport()]
24+
public static void ThrowManagedException ()
25+
{
26+
throw new Exception("I'll make an exception to the rules just this once... and throw one.");
27+
}
28+
29+
[JSExport()]
30+
public static void CallFailFast ()
31+
{
32+
System.Environment.FailFast("User requested FailFast");
33+
}
34+
35+
[JSImport("timerTick", "main.js")]
36+
public static partial void TimerTick (int i);
37+
38+
[JSExport()]
39+
public static void StartTimer ()
40+
{
41+
int i = 0;
42+
var timer = new System.Timers.Timer(1000);
43+
timer.Elapsed += (s, e) => {
44+
TimerTick(i);
45+
i += 1;
46+
};
47+
timer.AutoReset = true;
48+
timer.Enabled = true;
49+
}
50+
}
51+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\DefaultBrowserSample.targets" />
3+
<ItemGroup>
4+
<WasmExtraFilesToDeploy Include="main.js" />
5+
</ItemGroup>
6+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<!-- Licensed to the .NET Foundation under one or more agreements. -->
3+
<!-- The .NET Foundation licenses this file to you under the MIT license. -->
4+
<html>
5+
6+
<head>
7+
<title>Wasm Browser Shutdown Sample</title>
8+
<meta charset="UTF-8">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
<script type='module' src="./main.js"></script>
11+
</head>
12+
13+
<body>
14+
<h3 id="header">Wasm Browser Shutdown Sample</h3>
15+
<button id="throw-managed-exc">Throw Managed Exception</button>
16+
<button id="trigger-native-assert">Trigger Native Assert</button>
17+
<button id="trigger-failfast">Trigger Environment.FailFast</button>
18+
<button id="call-jsexport">Call Harmless JSExport</button>
19+
<button id="call-exit">Call exit</button>
20+
<button id="start-timer">Start Timer</button><br>
21+
Timer Value: <span id="timer-value"></span>
22+
</body>
23+
24+
</html>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import { dotnet, exit } from './_framework/dotnet.js'
5+
6+
let exports = undefined,
7+
setenv = undefined;
8+
9+
window.addEventListener("load", onLoad);
10+
11+
try {
12+
const { setModuleImports, getAssemblyExports, setEnvironmentVariable, getConfig } = await dotnet
13+
.withElementOnExit()
14+
.create();
15+
16+
setModuleImports("main.js", {
17+
timerTick: (i) => {
18+
document.querySelector("#timer-value").textContent = i;
19+
},
20+
});
21+
22+
setenv = setEnvironmentVariable;
23+
const config = getConfig();
24+
exports = await getAssemblyExports(config.mainAssemblyName);
25+
}
26+
catch (err) {
27+
exit(2, err);
28+
}
29+
30+
function onLoad() {
31+
document.querySelector("#throw-managed-exc").addEventListener("click", () => {
32+
try {
33+
exports.Sample.Test.ThrowManagedException();
34+
alert("No JS exception was thrown!");
35+
} catch (exc) {
36+
alert(exc);
37+
}
38+
});
39+
document.querySelector("#trigger-failfast").addEventListener("click", () => {
40+
try {
41+
exports.Sample.Test.CallFailFast();
42+
alert("No JS exception was thrown!");
43+
} catch (exc) {
44+
alert(exc);
45+
}
46+
});
47+
document.querySelector("#start-timer").addEventListener("click", () => {
48+
try {
49+
exports.Sample.Test.StartTimer();
50+
} catch (exc) {
51+
alert(exc);
52+
}
53+
});
54+
document.querySelector("#trigger-native-assert").addEventListener("click", () => {
55+
try {
56+
setenv(null, null);
57+
alert("No JS exception was thrown!");
58+
} catch (exc) {
59+
alert(exc);
60+
}
61+
});
62+
document.querySelector("#call-jsexport").addEventListener("click", () => {
63+
try {
64+
exports.Sample.Test.DoNothing();
65+
} catch (exc) {
66+
alert(exc);
67+
}
68+
});
69+
document.querySelector("#call-exit").addEventListener("click", () => {
70+
try {
71+
exit(7, "User clicked exit");
72+
} catch (exc) {
73+
alert(exc);
74+
}
75+
});
76+
}

src/mono/sample/wasm/browser-threads-minimal/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static async Task<string> FetchBackground(string url)
277277
Console.WriteLine($"smoke: FetchBackground 2 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}");
278278
var x = JSHost.ImportAsync(fetchhelper, "../fetchhelper.js");
279279
Console.WriteLine($"smoke: FetchBackground 3A ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}");
280-
// using var import = await x.ConfigureAwait(false);
280+
using var import = await x;
281281
Console.WriteLine($"smoke: FetchBackground 3B ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}");
282282
var r = await GlobalThisFetch(url);
283283
Console.WriteLine($"smoke: FetchBackground 4 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}");

src/mono/sample/wasm/browser-threads-minimal/main.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const assemblyName = "Wasm.Browser.Threads.Minimal.Sample.dll";
77

88

99
try {
10-
const resolveUrl = (relativeUrl) => (new URL(relativeUrl, window.location.href)).toString()
11-
1210
const { getAssemblyExports, runMain } = await dotnet
1311
//.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
1412
//.withDiagnosticTracing(true)
@@ -33,6 +31,7 @@ try {
3331
await exports.Sample.Test.DisposeTest();
3432
console.log("smoke: DisposeTest done ");
3533

34+
/* FIXME
3635
console.log("smoke: running TestHelloWebWorker");
3736
await exports.Sample.Test.TestHelloWebWorker();
3837
await exports.Sample.Test.TestHelloWebWorker();
@@ -43,11 +42,13 @@ try {
4342
await exports.Sample.Test.TestHelloWebWorker();
4443
await exports.Sample.Test.TestHelloWebWorker();
4544
console.log("smoke: TestHelloWebWorker done");
45+
*/
4646

4747
console.log("smoke: running TestCanStartThread");
4848
await exports.Sample.Test.TestCanStartThread();
4949
console.log("smoke: TestCanStartThread done");
5050

51+
/* FIXME
5152
console.log("smoke: running TestTLS");
5253
await exports.Sample.Test.TestTLS();
5354
console.log("smoke: TestTLS done");
@@ -58,14 +59,17 @@ try {
5859
console.log("smoke: running TestCallSetTimeoutOnWorker");
5960
await exports.Sample.Test.TestCallSetTimeoutOnWorker();
6061
console.log("smoke: TestCallSetTimeoutOnWorker done");
62+
*/
6163

6264
console.log("smoke: running HttpClientMain(blurst.txt)");
6365
let t = await exports.Sample.Test.HttpClientMain(globalThis.document.baseURI + "blurst.txt");
6466
console.log("smoke: HttpClientMain(blurst.txt) done " + t);
6567

68+
/* FIXME
6669
console.log("smoke: running HttpClientWorker(blurst.txt)");
6770
let t2 = await exports.Sample.Test.HttpClientWorker(globalThis.document.baseURI + "blurst.txt");
6871
console.log("smoke: HttpClientWorker(blurst.txt) done " + t2);
72+
*/
6973

7074
console.log("smoke: running HttpClientPool(blurst.txt)");
7175
let t3 = await exports.Sample.Test.HttpClientPool(globalThis.document.baseURI + "blurst.txt");
@@ -107,8 +111,10 @@ try {
107111
}
108112
console.log("smoke: TaskRunCompute done");
109113

114+
/* FIXME
110115
console.log("smoke: running StartAllocatorFromWorker");
111116
exports.Sample.Test.StartAllocatorFromWorker();
117+
*/
112118

113119
await delay(5000);
114120

@@ -120,8 +126,10 @@ try {
120126
console.log("smoke: running GCCollect");
121127
exports.Sample.Test.GCCollect();
122128

129+
/* FIXME
123130
console.log("smoke: running StopTimerFromWorker");
124131
exports.Sample.Test.StopTimerFromWorker();
132+
*/
125133

126134
let exit_code = await runMain(assemblyName, []);
127135
exit(exit_code);

src/mono/wasm/runtime/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import cwraps from "./cwraps";
55
import { mono_wasm_load_icu_data } from "./icu";
6-
import { ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, Module, loaderHelpers, runtimeHelpers } from "./globals";
6+
import { ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals";
77
import { mono_log_info, mono_log_debug, mono_log_warn, parseSymbolMapFile } from "./logging";
88
import { mono_wasm_load_bytes_into_heap } from "./memory";
99
import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";

src/mono/wasm/runtime/cancelable-promise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import { _lookup_js_owned_object } from "./gc-handles";
5-
import { createPromiseController, loaderHelpers } from "./globals";
5+
import { createPromiseController, loaderHelpers, mono_assert } from "./globals";
66
import { TaskCallbackHolder } from "./marshal-to-cs";
77
import { ControllablePromise, GCHandle } from "./types/internal";
88

0 commit comments

Comments
 (0)