2 //glue code to deal with the differences between ch, d8, jsc and sm.
3 if (typeof print === "undefined")
6 // JavaScript core does not have a console defined
7 if (typeof console === "undefined") {
8 var Console = function () {
9 this.log = function(msg){ print(msg) };
11 console = new Console();
14 if (typeof console !== "undefined") {
15 var has_console_warn = false;
17 if (typeof console.warn !== "undefined")
18 has_console_warn = true;
21 if (!has_console_warn)
22 console.warn = console.log;
25 fail_exec = function(reason) {
31 arguments = WScript.Arguments;
32 load = WScript.LoadScriptFile;
33 read = WScript.LoadBinaryFile;
34 fail_exec = function(reason) {
41 if (typeof scriptArgs !== "undefined")
42 arguments = scriptArgs;
44 //end of all the nice shell glue code.
46 // set up a global variable to be accessed in the App.init
47 var testArguments = arguments;
49 function inspect_object (o){
53 r += "'" + p + "' => '" + t + "', ";
58 // Preprocess arguments
59 var args = testArguments;
60 print("Arguments: " + testArguments);
64 if (args [0].startsWith ("--profile=")) {
65 var arg = args [0].substring ("--profile=".length);
69 args = args.slice (1);
70 } else if (args [0].startsWith ("--setenv=")) {
71 var arg = args [0].substring ("--setenv=".length);
72 var parts = arg.split ('=');
73 if (parts.length != 2)
74 fail_exec ("Error: malformed argument: '" + args [0]);
75 setenv [parts [0]] = parts [1];
76 args = args.slice (1);
82 load ("mono-config.js");
85 print: function(x) { print ("WASM: " + x) },
86 printErr: function(x) { print ("WASM-ERR: " + x) },
88 onRuntimeInitialized: function () {
89 // Have to set env vars here to enable setting MONO_LOG_LEVEL etc.
90 var wasm_setenv = Module.cwrap ('mono_wasm_setenv', 'void', ['string', 'string']);
91 for (var variable in setenv) {
92 wasm_setenv (variable, setenv [variable]);
95 MONO.mono_load_runtime_and_bcl (
98 config.enable_debugging,
101 config.add_bindings ();
106 // The default mono_load_runtime_and_bcl defaults to using
107 // fetch to load the assets. It also provides a way to set a
108 // fetch promise callback.
109 // Here we wrap the file read in a promise and fake a fetch response
111 return new Promise((resolve, reject) => {
112 var response = { ok: true, url: asset,
113 arrayBuffer: function() {
114 return new Promise((resolve2, reject2) => {
115 resolve2(new Uint8Array (read (asset, 'binary')));
128 var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string'])
129 var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string'])
130 var find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number'])
131 var runtime_invoke = Module.cwrap ('mono_wasm_invoke_method', 'number', ['number', 'number', 'number', 'number']);
132 var string_from_js = Module.cwrap ('mono_wasm_string_from_js', 'number', ['string']);
133 var assembly_get_entry_point = Module.cwrap ('mono_wasm_assembly_get_entry_point', 'number', ['number']);
134 var string_get_utf8 = Module.cwrap ('mono_wasm_string_get_utf8', 'string', ['number']);
135 var string_array_new = Module.cwrap ('mono_wasm_string_array_new', 'number', ['number']);
136 var obj_array_set = Module.cwrap ('mono_wasm_obj_array_set', 'void', ['number', 'number', 'number']);
137 var wasm_exit = Module.cwrap ('mono_wasm_exit', 'void', ['number']);
138 var wasm_setenv = Module.cwrap ('mono_wasm_setenv', 'void', ['string', 'string']);
140 const IGNORE_PARAM_COUNT = -1;
145 Module.print("Initializing.....");
147 for (var i = 0; i < profilers.length; ++i) {
148 var init = Module.cwrap ('mono_wasm_load_profiler_' + profilers [i], 'void', ['string'])
153 if (args[0] == "--regression") {
154 var exec_regresion = Module.cwrap ('mono_wasm_exec_regression', 'number', ['number', 'string'])
158 res = exec_regresion (10, args[1]);
159 Module.print ("REGRESSION RESULT: " + res);
161 Module.print ("ABORT: " + e);
166 fail_exec ("REGRESSION TEST FAILED");
171 if (args[0] == "--run") {
173 if (args.length == 1)
174 fail_exec ("Error: Missing main executable argument.");
175 main_assembly = assembly_load (args[1]);
176 if (main_assembly == 0)
177 fail_exec ("Error: Unable to load main executable '" + args[1] + "'");
178 main_method = assembly_get_entry_point (main_assembly);
179 if (main_method == 0)
180 fail_exec ("Error: Main (string[]) method not found.");
182 var app_args = string_array_new (args.length - 2);
183 for (var i = 2; i < args.length; ++i) {
184 obj_array_set (app_args, i - 2, string_from_js (args [i]));
187 var invoke_args = Module._malloc (4);
188 Module.setValue (invoke_args, app_args, "i32");
189 var eh_throw = Module._malloc (4);
190 Module.setValue (eh_throw, 0, "i32");
191 var res = runtime_invoke (main_method, 0, invoke_args, eh_throw);
192 var eh_res = Module.getValue (eh_throw, "i32");
194 print ("Exception:" + string_get_utf8 (res));
199 Module.print("Initializing Binding Test Suite support.....");
201 //binding test suite support code
202 binding_test_module = assembly_load ("binding_tests");
203 if (!binding_test_module)
205 Module.printErr("Binding tests module 'binding_tests' not found. Exiting Tests.")
206 throw new Error("Binding tests module 'binding_tests' not found. Exiting Tests.");
209 binding_test_class = find_class (binding_test_module, "", "TestClass");
210 if (!binding_test_class)
212 Module.printErr("Binding tests class 'TestClass' not found. Exiting Tests.")
213 throw new Error("Binding tests class 'TestClass' not found. Exiting Tests.");
216 Module.print("Binding support complete.");
219 Module.print("Checking for [main]Driver:Send ....");
221 var send_message = undefined;
225 send_message = BINDING.bind_static_method("[main]Driver:Send");
229 Module.printErr("[main]Driver:Send not found: " + e);
234 Module.print("Driver binding complete.");
236 var bad_send_msg_detected = false;
237 for (var i = 0; i < testArguments.length; ++i) {
242 res = send_message("start-test", testArguments [i])
244 printErr ("BAD SEND MSG: " + e);
245 bad_send_msg_detected = true;
247 print ("-----STARTED " + testArguments [i] + "---- " + res);
249 if (res == "SUCCESS") {
250 while (send_message ("pump-test", testArguments [i]) != "DONE")
252 Module.pump_message ();
259 var status = send_message ("test-result", "");
260 print ("Test status " + status)
261 if (status != "PASS")
262 fail_exec ("BAD TEST STATUS");
264 if (bad_send_msg_detected)
265 fail_exec ("BAD MSG SEND DETECTED");
269 //binding test suite support code
270 var binding_test_module = undefined;
271 var binding_test_class = undefined;
273 // This function is called from the binding test suite
274 function call_test_method(method_name, signature, args)
276 var target_method = find_method (binding_test_class, method_name, IGNORE_PARAM_COUNT)
278 throw "Could not find " + method_name;
280 return Module.mono_method_invoke (target_method, null, signature, args);