22// The .NET Foundation licenses this file to you under the MIT license.
33
44"use strict" ;
5+
6+ import createDotnetRuntime from './dotnet.js'
7+
58class FrameApp {
69 async init ( { BINDING } ) {
710 const reachManagedReached = BINDING . bind_static_method ( "[Wasm.Browser.Bench.Sample] Sample.AppStartTask/ReachManaged:Reached" ) ;
@@ -13,11 +16,17 @@ class FrameApp {
1316 }
1417}
1518
16- globalThis . frameApp = new FrameApp ( ) ;
19+ try {
20+ globalThis . frameApp = new FrameApp ( ) ;
21+
22+ let mute = false ;
23+ window . addEventListener ( "pageshow" , event => { window . parent . resolveAppStartEvent ( "pageshow" ) ; } )
1724
18- let mute = false ;
19- createDotnetRuntime ( ( { BINDING } ) => {
20- return {
25+ window . muteErrors = ( ) => {
26+ mute = true ;
27+ }
28+
29+ const { BINDING } = await createDotnetRuntime ( ( ) => ( {
2130 disableDotnet6Compatibility : true ,
2231 configSrc : "./mono-config.json" ,
2332 printErr : function ( ) {
@@ -29,37 +38,29 @@ createDotnetRuntime(({ BINDING }) => {
2938 window . parent . resolveAppStartEvent ( "onConfigLoaded" ) ;
3039 // Module.config.diagnostic_tracing = true;
3140 } ,
32- onDotnetReady : async ( ) => {
33- window . parent . resolveAppStartEvent ( "onDotnetReady" ) ;
34- try {
35- await frameApp . init ( { BINDING } ) ;
36- } catch ( error ) {
37- set_exit_code ( 1 , error ) ;
38- throw ( error ) ;
39- }
40- } ,
4141 onAbort : ( error ) => {
42- set_exit_code ( 1 , error ) ;
42+ wasm_exit ( 1 , error ) ;
4343 } ,
44- }
45- } ) . catch ( err => {
44+ } ) ) ;
45+
46+ window . parent . resolveAppStartEvent ( "onDotnetReady" ) ;
47+ await frameApp . init ( { BINDING } ) ;
48+ }
49+ catch ( err ) {
4650 if ( ! mute ) {
4751 console . error ( `WASM ERROR ${ err } ` ) ;
4852 }
49- } )
50-
51- window . addEventListener ( "pageshow" , event => { window . parent . resolveAppStartEvent ( "pageshow" ) ; } )
52-
53- window . muteErrors = ( ) => {
54- mute = true ;
53+ wasm_exit ( 1 , err ) ;
5554}
5655
57- function set_exit_code ( exit_code , reason ) {
56+ function wasm_exit ( exit_code , reason ) {
5857 /* Set result in a tests_done element, to be read by xharness */
5958 var tests_done_elem = document . createElement ( "label" ) ;
6059 tests_done_elem . id = "tests_done" ;
6160 tests_done_elem . innerHTML = exit_code . toString ( ) ;
61+ if ( exit_code ) tests_done_elem . style . background = "red" ;
6262 document . body . appendChild ( tests_done_elem ) ;
6363
64+ if ( reason ) console . error ( reason ) ;
6465 console . log ( `WASM EXIT ${ exit_code } ` ) ;
6566} ;
0 commit comments