@@ -22,48 +22,45 @@ const originalConsole = {
2222 error : console . error
2323} ;
2424
25- let isXUnitDoneCheck = false ;
26- let isXmlDoneCheck = false ;
27-
28- function proxyMethod ( prefix , func , asJson ) {
25+ function proxyConsoleMethod ( prefix , func , asJson ) {
2926 return function ( ) {
30- const args = [ ...arguments ] ;
31- let payload = args [ 0 ] ;
32- if ( payload === undefined ) payload = 'undefined' ;
33- else if ( payload === null ) payload = 'null' ;
34- else if ( typeof payload === 'function' ) payload = payload . toString ( ) ;
35- else if ( typeof payload !== 'string' ) {
36- try {
37- payload = JSON . stringify ( payload ) ;
38- } catch ( e ) {
39- payload = payload . toString ( ) ;
27+ try {
28+ const args = [ ...arguments ] ;
29+ let payload = args [ 0 ] ;
30+ if ( payload === undefined ) payload = 'undefined' ;
31+ else if ( payload === null ) payload = 'null' ;
32+ else if ( typeof payload === 'function' ) payload = payload . toString ( ) ;
33+ else if ( typeof payload !== 'string' ) {
34+ try {
35+ payload = JSON . stringify ( payload ) ;
36+ } catch ( e ) {
37+ payload = payload . toString ( ) ;
38+ }
4039 }
41- }
42- if ( payload . indexOf ( "=== TEST EXECUTION SUMMARY ===" ) != - 1 ) {
43- isXUnitDoneCheck = true ;
44- }
4540
46- if ( payload . startsWith ( "STARTRESULTXML" ) ) {
47- originalConsole . log ( 'Sending RESULTXML' )
48- isXmlDoneCheck = true ;
49- func ( payload ) ;
50- }
51- else if ( asJson ) {
52- func ( JSON . stringify ( {
53- method : prefix ,
54- payload : payload ,
55- arguments : args
56- } ) ) ;
57- } else {
58- func ( [ prefix + payload , ...args . slice ( 1 ) ] ) ;
41+ if ( payload . startsWith ( "STARTRESULTXML" ) ) {
42+ originalConsole . log ( 'Sending RESULTXML' )
43+ func ( payload ) ;
44+ }
45+ else if ( asJson ) {
46+ func ( JSON . stringify ( {
47+ method : prefix ,
48+ payload : payload ,
49+ arguments : args
50+ } ) ) ;
51+ } else {
52+ func ( [ prefix + payload , ...args . slice ( 1 ) ] ) ;
53+ }
54+ } catch ( err ) {
55+ originalConsole . error ( `proxyConsole failed: ${ err } ` )
5956 }
6057 } ;
6158} ;
6259
6360const methods = [ "debug" , "trace" , "warn" , "info" , "error" ] ;
6461for ( let m of methods ) {
6562 if ( typeof ( console [ m ] ) !== "function" ) {
66- console [ m ] = proxyMethod ( `console.${ m } : ` , console . log , false ) ;
63+ console [ m ] = proxyConsoleMethod ( `console.${ m } : ` , console . log , false ) ;
6764 }
6865}
6966
@@ -94,7 +91,7 @@ if (is_browser) {
9491
9592 // redirect output early, so that when emscripten starts it's already redirected
9693 for ( let m of [ "log" , ...methods ] )
97- console [ m ] = proxyMethod ( `console.${ m } ` , send , true ) ;
94+ console [ m ] = proxyConsoleMethod ( `console.${ m } ` , send , true ) ;
9895}
9996
10097if ( typeof globalThis . crypto === 'undefined' ) {
@@ -369,20 +366,9 @@ async function loadDotnet(file) {
369366 } ;
370367 } else if ( is_browser ) { // vanila JS in browser
371368 loadScript = async function ( file ) {
372- const script = document . createElement ( "script" ) ;
373- script . src = file ;
374- document . head . appendChild ( script ) ;
375- let timeout = 100 ;
376- // bysy spin waiting for script to load into global namespace
377- while ( timeout > 0 ) {
378- if ( globalThis . createDotnetRuntime ) {
379- return globalThis . createDotnetRuntime ;
380- }
381- // delay 10ms
382- await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
383- timeout -- ;
384- }
385- throw new Error ( "Can't load " + file ) ;
369+ globalThis . exports = { } ; // if we are loading cjs file
370+ const createDotnetRuntime = await import ( file ) ;
371+ return typeof createDotnetRuntime === "function" ? createDotnetRuntime : globalThis . exports . createDotnetRuntime ;
386372 }
387373 }
388374 else if ( typeof globalThis . load !== 'undefined' ) {
0 commit comments