Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ce637c
thenable and datetime cleanup
pavelsavara Aug 9, 2021
d8326dd
removed ownsHandle for readability, removed AnyRef from hierarchy, re…
pavelsavara Aug 9, 2021
4b96785
rename _csOwnedObjects
pavelsavara Aug 9, 2021
0a4c611
rename _csOwnedObjects
pavelsavara Aug 9, 2021
99b05bb
redirect to Inflight counter
pavelsavara Aug 9, 2021
0d218f9
renames
pavelsavara Aug 9, 2021
151a059
rename and move
pavelsavara Aug 9, 2021
0f3d6d0
rename
pavelsavara Aug 9, 2021
dca5d5e
New+BindCoreObject -> CreateCsOwnedObject single call
pavelsavara Aug 9, 2021
4783438
remove refcount frames
pavelsavara Aug 9, 2021
c2fd18e
differentiate gcHandles
pavelsavara Aug 9, 2021
d30c4a8
get rid of weak GCHandle
pavelsavara Aug 9, 2021
53e2eb9
feedback
pavelsavara Aug 10, 2021
36e864a
added MappedType enum
pavelsavara Aug 10, 2021
e0b3b53
naming consistency
pavelsavara Aug 10, 2021
7c743b1
feedback
pavelsavara Aug 10, 2021
efcd1a9
rename _cs_owned_objects_by_js_handle
pavelsavara Aug 10, 2021
a9212b7
split and rename files
pavelsavara Aug 10, 2021
4f24a9d
shouldAddInflight to more methods
pavelsavara Aug 10, 2021
c5f22be
improved in-flight references
pavelsavara Aug 10, 2021
7d23f76
assert for JSObject not disposed
pavelsavara Aug 10, 2021
cce3ccc
introduce in-flight assert
pavelsavara Aug 10, 2021
e29416a
move should_add_in_flight arg to fisrt position, so that we could bin…
pavelsavara Aug 10, 2021
e4dd539
doc
pavelsavara Aug 10, 2021
3897513
cleanup
pavelsavara Aug 10, 2021
d7345bc
doc
pavelsavara Aug 10, 2021
6ee696a
implement fallback for missing support of FInalizationRegistry/WeakRe…
pavelsavara Aug 16, 2021
92b9a3b
feedback
pavelsavara Aug 16, 2021
685d2a5
no polyfill feedback
pavelsavara Aug 16, 2021
a6f7eda
feedback
pavelsavara Aug 16, 2021
4a388ed
name consistency feedback
pavelsavara Aug 16, 2021
f5cede0
use symbols for helper fields
pavelsavara Aug 16, 2021
b8ad165
feedback
pavelsavara Aug 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove refcount frames
  • Loading branch information
pavelsavara committed Aug 16, 2021
commit 4783438f495ad9e89186e62dc1ff8ada072d320c
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ public static int CreateCSOwnedObject(int jsHandle, int mappedType)
return target.GCHandleValue;
}

public static int BindCoreCLRObject(int jsHandle, int gcHandle)
{
GCHandle h = (GCHandle)(IntPtr)gcHandle;
JSObject? obj = null;

lock (_csOwnedObjects)
{
if (_csOwnedObjects.TryGetValue(jsHandle, out WeakReference<JSObject>? wr))
{

if (!wr.TryGetTarget(out JSObject? instance) || (instance.GCHandleValue != (int)(IntPtr)h && h.IsAllocated))
{
throw new JSException(SR.Format(SR.MultipleHandlesPointingJsId, jsHandle));
}

obj = instance;
}
else if (h.Target is JSObject instance)
{
_csOwnedObjects.Add(jsHandle, new WeakReference<JSObject>(instance, trackResurrection: true));
obj = instance;
}
}

return obj?.GCHandleValue ?? 0;
}

public static int TryGetCsOwnedObjectJsHandle(object rawObj)
{
JSObject? jsObject = rawObj as JSObject;
Expand Down
56 changes: 8 additions & 48 deletions src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ var BindingSupportLib = {
// that any code relying on the old get_method/call_method pattern will
// break in a more understandable way.

this._bind_core_clr_obj = bind_runtime_method ("BindCoreCLRObject", "ii");
this._get_raw_mono_obj = bind_runtime_method ("GetDotNetObject", "ii!");

this._create_cs_owned_object = bind_runtime_method ("CreateCSOwnedObject", "ii");
Expand Down Expand Up @@ -552,10 +551,9 @@ var BindingSupportLib = {
}
},

_unbox_cs_owned_root: function (root) {
var gc_handle = this._cs_owned_object_get_js_handle(root.value, true);
var js_obj = BINDING.mono_wasm_get_jsobj_from_js_handle (gc_handle);
this.mono_inflight_current_frame.push(gc_handle);
_unbox_cs_owned_root_as_js_object: function (root) {
var js_handle = this._cs_owned_object_get_js_handle(root.value, true);
var js_obj = BINDING.mono_wasm_get_jsobj_from_js_handle (js_handle);
return js_obj;
},

Expand Down Expand Up @@ -600,7 +598,7 @@ var BindingSupportLib = {
var uriValue = this._object_to_string (root.value);
return uriValue;
case 23: // clr .NET SafeHandle/JSObject
return this._unbox_cs_owned_root (root);
return this._unbox_cs_owned_root_as_js_object (root);
case 30:
return undefined;
default:
Expand Down Expand Up @@ -875,11 +873,6 @@ var BindingSupportLib = {
return js_obj | 0;
},

wasm_bind_core_clr_obj: function (js_handle, gc_handle)
{
return this._bind_core_clr_obj (js_handle, gc_handle);
},

// when should_add_in_flight === true, the JSObject would be temporarily hold by Normal gc_handle, so that it would not get collected during transition to the managed stack.
// its InFlight gc_handle would be freed when the instance arrives to managed side via Interop.Runtime.ReleaseInFlight
wasm_get_raw_obj: function (gc_handle, should_add_in_flight)
Expand Down Expand Up @@ -1657,33 +1650,6 @@ var BindingSupportLib = {
}
return obj;
},
mono_wasm_parse_args_root : function (argsRoot) {
var js_args = this._mono_array_root_to_js_array(argsRoot);
this.mono_inflight_push_current_frame();
return js_args;
},
mono_inflight_push_current_frame : function () {
BINDING.mono_inflight_frames.push(BINDING.mono_inflight_current_frame);
BINDING.mono_inflight_current_frame = [];
},
// Release all managed objects that are loaded into the last of mono_inflight_frames
mono_inflight_pop_current_frame : function () {
if(!this.mono_inflight_frames.length){
throw new Error('ERR14: pop frame before push');
}
var inflight_frame = this.mono_inflight_frames.pop();
// TODO: Look into passing the array of owned object handles in one pass.
for (var refidx = 0; refidx < inflight_frame.length; refidx++)
{
var js_handle = inflight_frame[refidx];
this._release_cs_owned_object_by_handle(js_handle);
}
},
mono_wasm_convert_return_value: function (ret) {
var res = this.js_to_mono_obj (ret);
this.mono_inflight_pop_current_frame();
return res;
},
},
mono_wasm_invoke_js_with_args: function(js_handle, method_name, args, is_exception) {
let argsRoot = MONO.mono_wasm_new_root (args), nameRoot = MONO.mono_wasm_new_root (method_name);
Expand All @@ -1702,18 +1668,16 @@ var BindingSupportLib = {
return BINDING.js_string_to_mono_string ("ERR13: Invalid JS object handle '" + js_handle + "' while invoking '"+js_name+"'");
}

var js_args = BINDING.mono_wasm_parse_args_root(argsRoot);
var js_args = BINDING._mono_array_root_to_js_array(argsRoot);

var res;
try {
var m = obj [js_name];
if (typeof m === "undefined")
throw new Error("Method: '" + js_name + "' not found for: '" + Object.prototype.toString.call(obj) + "'");
var res = m.apply (obj, js_args);
return BINDING.mono_wasm_convert_return_value(res);
return BINDING.js_to_mono_obj(res);
} catch (e) {
// make sure we release object reference counts on errors.
BINDING.mono_inflight_pop_current_frame();
var res = e.toString ();
setValue (is_exception, 1, "i32");
if (res === null || res === undefined)
Expand Down Expand Up @@ -1779,7 +1743,6 @@ var BindingSupportLib = {
var result = false;

var js_value = BINDING._unbox_mono_obj_root(valueRoot);
BINDING.mono_inflight_push_current_frame();

if (createIfNotExist) {
js_obj[property] = js_value;
Expand All @@ -1804,7 +1767,6 @@ var BindingSupportLib = {
}

}
BINDING.mono_inflight_pop_current_frame();
return BINDING._box_js_bool (result);
} finally {
nameRoot.release();
Expand Down Expand Up @@ -1843,11 +1805,9 @@ var BindingSupportLib = {
}

var js_value = BINDING._unbox_mono_obj_root(valueRoot);
BINDING.mono_inflight_push_current_frame();

try {
obj [property_index] = js_value;
BINDING.mono_inflight_pop_current_frame();
return true;
} catch (e) {
var res = e.toString ();
Expand Down Expand Up @@ -1909,7 +1869,7 @@ var BindingSupportLib = {
return BINDING.js_string_to_mono_string ("JavaScript host object '" + js_name + "' not found.");
}

var js_args = BINDING.mono_wasm_parse_args_root(argsRoot);
var js_args = BINDING._mono_array_root_to_js_array(argsRoot);

try {

Expand All @@ -1929,7 +1889,7 @@ var BindingSupportLib = {
js_obj.__mono_gc_handle__ = gc_handle;
var js_handle = BINDING.mono_wasm_get_js_handle(js_obj);
// yes, convert int, because on error we need to return String on same method signature
return BINDING.mono_wasm_convert_return_value(js_handle);
return BINDING.js_to_mono_obj(js_handle);
} catch (e) {
var res = e.toString ();
setValue (is_exception, 1, "i32");
Expand Down