forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WASM] Converted mono-config.js to mono-config.json (dotnet#53606)
* converted mono-config.js to mono-config.json * Fixed test * fixed handling of case where Module isn't defined * Fixed remaining failing tests * Replaced alerts with console.log to fix Helix test * replaced all vars with consts * use fetch * clean syntax * prevent timeouts when the mono-config file fails to load * Moved config file loading to preInit * Fixed tests * Adjusted file linking * removed the unnecessary js_support.js * cleaned up function * updated samples * removed lingering pre-js flag * Fixed trimming tests * addressed PR comments * removed useless function
- Loading branch information
1 parent
f891033
commit a3f0e2b
Showing
19 changed files
with
218 additions
and
109 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
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 |
---|---|---|
@@ -1,33 +1,99 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
var Module = { | ||
var Module = { | ||
is_testing: false, | ||
config: null, | ||
|
||
preInit: async function() { | ||
Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); | ||
}, | ||
|
||
// Called when the runtime is initialized and wasm is ready | ||
onRuntimeInitialized: function () { | ||
config.loaded_cb = function () { | ||
if (!Module.config || Module.config.error) { | ||
console.log("An error occured while loading the config file"); | ||
return; | ||
} | ||
|
||
Module.config.loaded_cb = function () { | ||
try { | ||
App.init (); | ||
Module.init(); | ||
} catch (error) { | ||
test_exit(1); | ||
Module.test_exit(1); | ||
throw (error); | ||
} | ||
}; | ||
config.fetch_file_cb = function (asset) { | ||
Module.config.fetch_file_cb = function (asset) { | ||
return fetch (asset, { credentials: 'same-origin' }); | ||
} | ||
|
||
if (config.enable_profiler) | ||
if (Module.config.enable_profiler) | ||
{ | ||
config.aot_profiler_options = { | ||
Module.config.aot_profiler_options = { | ||
write_at:"Sample.Test::StopProfile", | ||
send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData" | ||
} | ||
} | ||
|
||
try | ||
{ | ||
MONO.mono_load_runtime_and_bcl_args (config); | ||
MONO.mono_load_runtime_and_bcl_args (Module.config); | ||
} catch (error) { | ||
test_exit(1); | ||
Module.test_exit(1); | ||
throw(error); | ||
} | ||
}, | ||
|
||
init: function () { | ||
console.log("not ready yet") | ||
var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []); | ||
document.getElementById("out").innerHTML = ret; | ||
console.log ("ready"); | ||
|
||
if (Module.is_testing) | ||
{ | ||
console.debug(`ret: ${ret}`); | ||
let exit_code = ret == 42 ? 0 : 1; | ||
Module.test_exit(exit_code); | ||
} | ||
|
||
if (Module.config.enable_profiler) { | ||
BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:StopProfile", []); | ||
Module.saveProfile(); | ||
} | ||
}, | ||
|
||
onLoad: function() { | ||
var url = new URL(decodeURI(window.location)); | ||
let args = url.searchParams.getAll('arg'); | ||
Module.is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined); | ||
}, | ||
|
||
test_exit: function(exit_code) { | ||
if (!Module.is_testing) { | ||
console.log(`test_exit: ${exit_code}`); | ||
return; | ||
} | ||
|
||
/* 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}`); | ||
}, | ||
|
||
saveProfile: function () { | ||
var a = document.createElement('a'); | ||
var blob = new Blob([Module.aot_profile_data]); | ||
a.href = URL.createObjectURL(blob); | ||
a.download = "data.aotprofile"; | ||
// Append anchor to body. | ||
document.body.appendChild(a); | ||
a.click(); | ||
|
||
// Remove anchor from body | ||
document.body.removeChild(a); | ||
} | ||
}; | ||
}; |
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
Oops, something went wrong.