1 function inspect_object (o){
5 r += "'" + p + "' => '" + t + "', ";
12 print: function(x) { print ("WASM: " + x) },
13 printErr: function(x) { print ("WASM-ERR: " + x) },
16 monitorRunDependencies: function(left) {
17 this.totalDependencies = Math.max(this.totalDependencies, left);
18 print("STATUS: "+ (left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'));
21 instantiateWasm: function (env, receiveInstance) {
22 //merge Module's env with emcc's env
23 env.env = Object.assign({}, env.env, this.env);
24 var module = new WebAssembly.Module (read ('mono.wasm', 'binary'))
25 this.wasm_instance = new WebAssembly.Instance (module, env);
26 this.em_cb = receiveInstance;
30 finish_loading: function () {
31 this.em_cb (this.wasm_instance);
38 var assemblies = [ "mscorlib.dll", "System.dll", "System.Core.dll", "main.exe", "nunitlite.dll", "mini_tests.dll", "wasm_corlib_test.dll", "wasm_System_test.dll", "wasm_System.Core_test.dll" ];
41 Module.finish_loading ();
44 Module.FS_createPath ("/", "managed", true, true);
46 //Load all assembly in @assemblies into the FS at /mananaged
47 assemblies.forEach (function(asm_name) {
48 print ("LOADING " + asm_name)
49 var asm = new Uint8Array (read ("managed/" + asm_name, 'binary'));
50 Module.FS_createDataFile ("managed/" + asm_name, null, asm, true, true, true);
54 var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string'])
55 var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string'])
56 var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string'])
57 var find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number'])
58 var invoke_method = Module.cwrap ('mono_wasm_invoke_method', 'number', ['number', 'number', 'number'])
59 var mono_string_get_utf8 = Module.cwrap ('mono_wasm_string_get_utf8', 'number', ['number'])
60 var mono_string = Module.cwrap ('mono_wasm_string_from_js', 'number', ['string'])
62 function call_method (method, this_arg, args) {
63 var stack = Module.Runtime.stackSave ();
64 var args_mem = Runtime.stackAlloc (args.length);
65 var eh_throw = Runtime.stackAlloc (4);
66 for (var i = 0; i < args.length; ++i)
67 Module.setValue (args_mem + i * 4, args [i], "i32");
68 Module.setValue (eh_throw, 0, "i32");
70 var res = invoke_method (method, this_arg, args_mem, eh_throw);
72 if (Module.getValue (eh_throw, "i32") != 0) {
73 Module.Runtime.stackRestore(stack);
74 var msg = conv_string (res);
75 throw new Error (msg); //the convention is that invoke_method ToString () any outgoing exception
78 Module.Runtime.stackRestore(stack);
82 //FIXME this is wastefull, we could remove the temp malloc by going the UTF16 route
83 //FIXME this is unsafe, cuz raw objects could be GC'd.
84 function conv_string (mono_obj) {
87 var raw = mono_string_get_utf8 (mono_obj);
88 var res = Module.UTF8ToString (raw);
94 function mono_send_msg (key, val) {
96 return conv_string (call_method (send_message, null, [mono_string (key), mono_string (val)]));
98 print ("BAD SEND MSG: " + e);
103 load_runtime ("managed");
104 var main_module = assembly_load ("main")
109 var driver_class = find_class (main_module, "", "Driver")
113 var send_message = find_method (driver_class, "Send", -1)
117 print ("-----LOADED ----");
119 for (var i = 0; i < arguments.length; ++i) {
120 var res = mono_send_msg ("start-test", arguments [i])
121 print ("-----STARTED " + arguments [i] + "---- " + res);
123 if (res == "SUCCESS") {
124 while (mono_send_msg ("pump-test", arguments [i]) != "DONE") {
125 Module.pump_message ();
132 var status = mono_send_msg ("test-result", "");
133 print ("Test status " + status)
134 if (status != "PASS")