Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console-node-ts\Wasm.Console.Node.TS.Sample.csproj" />
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-webpack\Wasm.Browser.WebPack.Sample.csproj" />
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\node-webpack\Wasm.Node.WebPack.Sample.csproj" />
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-nextjs\Wasm.Browser.NextJs.Sample.csproj" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/mono/sample/mbr/browser/WasmDelta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
<!-- Set RoslynILDiffFullPath property to the path of roslynildiff -->
<Import Project="..\DeltaHelper.targets" />
<Import Project="$(MonoProjectRoot)wasm\build\WasmApp.InTree.targets" />

<Target Name="RunSample" DependsOnTargets="Build">
<Exec Command="$(_Dotnet) serve -o -d:bin/$(Configuration)/AppBundle -p:8000 --mime .mjs=text/javascript" IgnoreExitCode="true" YieldDuringToolExecution="true" />
</Target>
</Project>
23 changes: 4 additions & 19 deletions src/mono/sample/mbr/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,17 @@
<title>Hot Reload Sample</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="modulepreload" href="./main.js" />
<link rel="modulepreload" href="./dotnet.js" />
</head>

<body>
<h3 id="header">Wasm Hot Reload Sample</h3>
Result from Sample.Test.TestMeaning: <span id="out"></span>
<div>
Click here (upto 2 times): <button id="update">Update</button>
</div>
<script type='text/javascript'>
const App = {
init: function () {
const update = BINDING.bind_static_method("[WasmDelta] Sample.Test:Update");
const testMeaning = BINDING.bind_static_method("[WasmDelta] Sample.Test:TestMeaning");
const outElement = document.getElementById("out");
document.getElementById("update").addEventListener("click", function () {
update();
console.log("applied update");
outElement.innerHTML = testMeaning();
})
outElement.innerHTML = testMeaning();
console.log("ready");
},
};
</script>
<script type="text/javascript" src="main.js"></script>
<script defer src="dotnet.js"></script>
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
<script type='module' src="./main.js"></script>
</body>

</html>
33 changes: 21 additions & 12 deletions src/mono/sample/mbr/browser/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import createDotnetRuntime from './dotnet.js'

"use strict";
var Module = {
configSrc: "./mono-config.json",
onConfigLoaded: function () {
MONO.config.environment_variables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug";
},
onDotnetReady: function () {
App.init();
},
};
try {
const { BINDING } = await createDotnetRuntime(({ MONO }) => ({
configSrc: "./mono-config.json",
onConfigLoaded: () => {
MONO.config.environment_variables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug";
},
}));
const update = BINDING.bind_static_method("[WasmDelta] Sample.Test:Update");
const testMeaning = BINDING.bind_static_method("[WasmDelta] Sample.Test:TestMeaning");
const outElement = document.getElementById("out");
document.getElementById("update").addEventListener("click", function () {
update();
console.log("applied update");
outElement.innerHTML = testMeaning();
})
outElement.innerHTML = testMeaning();
console.log("ready");
} catch (err) {
console.log(`WASM ERROR ${err}`);
}
5 changes: 3 additions & 2 deletions src/mono/sample/wasm/browser-bench/appstart-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<title>App task</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="modulepreload" href="frame-main.js" />
<link rel="modulepreload" href="dotnet.js" />
</head>

<body>
<h3 id="header">Wasm Browser Sample - App task frame</h3>
<span id="out"></span>
<script type="text/javascript" src="dotnet.js"></script>
<script type="text/javascript" src="frame-main.js"></script>
<script type="module" src="frame-main.js"></script>
</body>

</html>
55 changes: 20 additions & 35 deletions src/mono/sample/wasm/browser-bench/frame-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

"use strict";

import createDotnetRuntime from './dotnet.js'

class FrameApp {
async init({ BINDING }) {
const reachManagedReached = BINDING.bind_static_method("[Wasm.Browser.Bench.Sample] Sample.AppStartTask/ReachManaged:Reached");
Expand All @@ -13,11 +16,17 @@ class FrameApp {
}
}

globalThis.frameApp = new FrameApp();
try {
globalThis.frameApp = new FrameApp();

let mute = false;
window.addEventListener("pageshow", event => { window.parent.resolveAppStartEvent("pageshow"); })

window.muteErrors = () => {
mute = true;
}

let mute = false;
createDotnetRuntime(({ BINDING }) => {
return {
const { BINDING } = await createDotnetRuntime(() => ({
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
printErr: function () {
Expand All @@ -28,38 +37,14 @@ createDotnetRuntime(({ BINDING }) => {
onConfigLoaded: () => {
window.parent.resolveAppStartEvent("onConfigLoaded");
// Module.config.diagnostic_tracing = true;
},
onDotnetReady: async () => {
window.parent.resolveAppStartEvent("onDotnetReady");
try {
await frameApp.init({ BINDING });
} catch (error) {
set_exit_code(1, error);
throw (error);
}
},
onAbort: (error) => {
set_exit_code(1, error);
},
}
}).catch(err => {
}
}));

window.parent.resolveAppStartEvent("onDotnetReady");
await frameApp.init({ BINDING });
}
catch (err) {
if (!mute) {
console.error(`WASM ERROR ${err}`);
}
})

window.addEventListener("pageshow", event => { window.parent.resolveAppStartEvent("pageshow"); })

window.muteErrors = () => {
mute = true;
}

function set_exit_code(exit_code, reason) {
/* Set result in a tests_done element, to be read by xharness */
var tests_done_elem = document.createElement("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString();
document.body.appendChild(tests_done_elem);

console.log(`WASM EXIT ${exit_code}`);
};
3 changes: 1 addition & 2 deletions src/mono/sample/wasm/browser-bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
<body>
<h3 id="header">Wasm Browser Sample - Simple Benchmark</h3>
Output:<br><br> <span id="out"></span>
<script type="text/javascript" src="dotnet.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="module" src="main.js"></script>
</body>

</html>
36 changes: 10 additions & 26 deletions src/mono/sample/wasm/browser-bench/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"use strict";

import createDotnetRuntime from './dotnet.js'

let runBenchmark;
let setTasks;

Expand Down Expand Up @@ -76,30 +78,12 @@ class MainApp {
}
}

globalThis.mainApp = new MainApp();
try {
globalThis.mainApp = new MainApp();

createDotnetRuntime(({ BINDING }) => ({
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
onDotnetReady: () => {
try {
mainApp.init({ BINDING });
} catch (error) {
set_exit_code(1, error);
throw (error);
}
},
onAbort: (error) => {
set_exit_code(1, error);
},
}));

function set_exit_code(exit_code, reason) {
/* Set result in a tests_done element, to be read by xharness */
const tests_done_elem = document.createElement("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString();
document.body.appendChild(tests_done_elem);

console.log(`WASM EXIT ${exit_code}`);
};
const { BINDING } = await createDotnetRuntime();
mainApp.init({ BINDING });
}
catch (err) {
console.error(`WASM ERROR ${err}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ ifneq ($(AOT),)
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
endif

PROJECT_NAME=Wasm.Browser.ES6.Sample.csproj
PROJECT_NAME=Wasm.Browser.CJS.Sample.csproj

run: run-browser
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ namespace Sample
{
public class Test
{
public static int Main(string[] args)
public static void Main(string[] args)
{
Console.WriteLine ("Hello, World!");
return 0;
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
<html>

<head>
<title>Sample ES6</title>
<title>Sample CJS</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="modulepreload" href="./main.js" />
<link rel="modulepreload" href="./dotnet.js" />
</head>

<body>
<h3 id="header">Wasm Browser ES6 Sample</h3>
<h3 id="header">Wasm Browser CJS Sample</h3>
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
<script type='module' src="./main.js"></script>
<script type="text/javascript" src="./dotnet.js"></script>
<script type="text/javascript" src="./main.js"></script>
</body>

</html>
38 changes: 38 additions & 0 deletions src/mono/sample/wasm/browser-cjs/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function wasm_exit(exit_code) {
/* Set result in a tests_done element, to be read by xharness in runonly CI test */
const tests_done_elem = document.createElement("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString();
document.body.appendChild(tests_done_elem);

console.log(`WASM EXIT ${exit_code}`);
}

async function loadRuntime() {
globalThis.exports = {};
await import("./dotnet.js");
return globalThis.exports.createDotnetRuntime;
}

async function main() {
try {
const createDotnetRuntime = await loadRuntime();
const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime(() => ({
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
}));

const testMeaning = BINDING.bind_static_method("[Wasm.Browser.CJS.Sample] Sample.Test:TestMeaning");
const ret = testMeaning();
document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`;

console.debug(`ret: ${ret}`);
let exit_code = ret == 42 ? 0 : 1;
wasm_exit(exit_code);
} catch (err) {
console.log(`WASM ERROR ${err}`);
wasm_exit(2)
}
}

main();
25 changes: 0 additions & 25 deletions src/mono/sample/wasm/browser-es6/main.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
2. Initialize the profiler in the main javascript (e.g. main.js)

```
var Module = {
await createDotnetRuntime(() => ({
onConfigLoaded: () => {
...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
<WasmMainJSPath>main.js</WasmMainJSPath>
<WasmProfilers>aot;</WasmProfilers>
<WasmBuildNative>true</WasmBuildNative>
</PropertyGroup>

<ItemGroup>
<WasmExtraConfig Include="enable_profiler" Value="true" Condition="'$(EnableProfiler)' == 'true'" />
<WasmExtraConfig Include="enable_profiler" Value="true" />
<WasmExtraFilesToDeploy Include="index.html" />
</ItemGroup>

Expand Down
Loading