-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm] Decrease the startup ceremony (#62587)
* new API MONO.mono_run_main_and_exit and MONO.mono_run_main * default onAbort * console-v8-cjs sample * reduced setup ceremony
- Loading branch information
1 parent
7b2925b
commit 25c2073
Showing
12 changed files
with
128 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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.Threading.Tasks; | ||
|
||
public class Test | ||
{ | ||
public static async Task<int> Main(string[] args) | ||
{ | ||
await Task.Delay(1); | ||
Console.WriteLine("Hello World!"); | ||
for (int i = 0; i < args.Length; i++) { | ||
Console.WriteLine($"args[{i}] = {args[i]}"); | ||
} | ||
return args.Length; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir> | ||
<WasmMainJSPath>main.js</WasmMainJSPath> | ||
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script> | ||
<WasmEnableES6>false</WasmEnableES6> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<_SampleProject>Wasm.Console.V8.CJS.Sample.csproj</_SampleProject> | ||
<_SampleAssembly>Wasm.Console.V8.CJS.Sample.dll</_SampleAssembly> | ||
</PropertyGroup> | ||
|
||
<Target Name="RunSample" DependsOnTargets="RunSampleWithV8" /> | ||
</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,11 @@ | ||
load("./dotnet.js") | ||
|
||
const dllName = "Wasm.Console.V8.CJS.Sample.dll"; | ||
const app_args = Array.from(arguments); | ||
|
||
async function main() { | ||
const { MONO } = await createDotnetRuntime(); | ||
await MONO.mono_run_main_and_exit(dllName, app_args); | ||
} | ||
|
||
main(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Module } from "./imports"; | ||
import { mono_call_assembly_entry_point } from "./method-calls"; | ||
import { mono_wasm_set_main_args, runtime_is_initialized_reject } from "./startup"; | ||
|
||
|
||
export async function mono_run_main_and_exit(main_assembly_name: string, args: string[]): Promise<void> { | ||
try { | ||
const result = await mono_run_main(main_assembly_name, args); | ||
set_exit_code(result); | ||
} catch (error) { | ||
set_exit_code(1, error); | ||
} | ||
} | ||
|
||
export async function mono_run_main(main_assembly_name: string, args: string[]): Promise<number> { | ||
mono_wasm_set_main_args(main_assembly_name, args); | ||
return mono_call_assembly_entry_point(main_assembly_name, [args], "m"); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export function mono_on_abort(error: any): void { | ||
runtime_is_initialized_reject(error); | ||
set_exit_code(1, error); | ||
} | ||
|
||
function set_exit_code(exit_code: number, reason?: any) { | ||
if (reason) { | ||
Module.printErr(reason.toString()); | ||
if (reason.stack) { | ||
Module.printErr(reason.stack); | ||
} | ||
} | ||
const globalThisAny: any = globalThis; | ||
if (typeof globalThisAny.exit === "function") { | ||
globalThisAny.exit(exit_code); | ||
} | ||
else if (typeof globalThisAny.quit === "function") { | ||
globalThisAny.quit(exit_code); | ||
} | ||
} |
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