diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 6796330a98012..e4e7c88896bf0 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -23,7 +23,13 @@ function proxyMethod (prefix, func, asJson) { if(payload === undefined) payload = 'undefined'; else if(payload === null) payload = 'null'; else if(typeof payload === 'function') payload = payload.toString(); - else if(typeof payload !== 'string') payload = JSON.stringify(payload); + else if(typeof payload !== 'string') { + try{ + payload = JSON.stringify(payload); + }catch(e){ + payload = payload.toString(); + } + } if (asJson) { func (JSON.stringify({ diff --git a/src/mono/wasm/runtime/binding_support.js b/src/mono/wasm/runtime/binding_support.js index f6cb1e6b39916..a000bb77d9d5c 100644 --- a/src/mono/wasm/runtime/binding_support.js +++ b/src/mono/wasm/runtime/binding_support.js @@ -197,11 +197,11 @@ var BindingSupportLib = { thenable.then ((result) => { this.set_tcs_result(tcs_gchandle, result); // let go of the thenable reference - this.mono_wasm_release_handle(thenable_js_handle); + this.mono_wasm_unregister_obj(thenable_js_handle); }, (reason) => { this.set_tcs_failure(tcs_gchandle, reason); // let go of the thenable reference - this.mono_wasm_release_handle(thenable_js_handle); + this.mono_wasm_unregister_obj(thenable_js_handle); }); // collect the TaskCompletionSource with its Task after js doesn't hold the thenable anymore @@ -1647,6 +1647,24 @@ var BindingSupportLib = { return this.mono_wasm_object_registry[handle - 1]; return null; }, + mono_wasm_unregister_obj: function(js_handle, is_exception) { + var obj = BINDING.mono_wasm_object_registry[js_handle - 1]; + if (typeof obj !== "undefined" && obj !== null) { + // if this is the global object then do not + // unregister it. + if (globalThis === obj) + return obj; + + if (typeof obj.__mono_gchandle__ !== "undefined") { + obj.__mono_gchandle__ = undefined; + obj.__mono_jshandle__ = undefined; + } + + delete BINDING.mono_wasm_object_registry[js_handle - 1]; + BINDING.mono_wasm_free_list.push(js_handle - 1); + } + return obj; + }, mono_wasm_free_raw_object: function(js_id) { var obj = this.mono_wasm_object_registry[js_id - 1]; if (typeof obj !== "undefined" && obj !== null) { @@ -1901,23 +1919,7 @@ var BindingSupportLib = { }, mono_wasm_release_handle: function(js_handle, is_exception) { BINDING.bindings_lazy_init (); - - var obj = BINDING.mono_wasm_object_registry[js_handle - 1]; - if (typeof obj !== "undefined" && obj !== null) { - // if this is the global object then do not - // unregister it. - if (globalThis === obj) - return obj; - - if (typeof obj.__mono_gchandle__ !== "undefined") { - obj.__mono_gchandle__ = undefined; - obj.__mono_jshandle__ = undefined; - } - - delete BINDING.mono_wasm_object_registry[js_handle - 1]; - BINDING.mono_wasm_free_list.push(js_handle - 1); - } - return obj; + BINDING.mono_wasm_unregister_obj(js_handle); }, mono_wasm_release_object: function(js_handle, is_exception) { BINDING.bindings_lazy_init ();