Skip to content

Commit

Permalink
fix reference
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Aug 5, 2021
1 parent bf48561 commit f6947e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
8 changes: 7 additions & 1 deletion src/mono/wasm/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
40 changes: 21 additions & 19 deletions src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ();
Expand Down

0 comments on commit f6947e0

Please sign in to comment.