Skip to content
Merged
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
feedback
  • Loading branch information
pavelsavara committed Aug 16, 2021
commit a6f7edacb7e0ce22c52127acae501c697aa218aa
48 changes: 28 additions & 20 deletions src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,12 @@ var BindingSupportLib = {

this._js_owned_object_table = new Map ();
// NOTE: FinalizationRegistry and WeakRef are missing on Safari below 14.1
if (typeof globalThis.FinalizationRegistry === "function") {
this._is_finalizarion_registry_supported = typeof globalThis.FinalizationRegistry === "function";
this._is_weak_ref_supported = typeof globalThis.WeakRef === "function";

if (this._is_finalizarion_registry_supported) {
this._js_owned_object_registry = new globalThis.FinalizationRegistry(this._js_owned_object_finalized.bind(this));
}
this._weak_ref_ctor = typeof globalThis.WeakRef !== "function"
? globalThis.WeakRef
// this is trivial WeakRef replacement, which holds strong refrence, instead of weak one, when the browser doesn't support it
: function WeakRef(targetObject) {
this.deref = () => {
return targetObject;
}
};
},

_js_owned_object_finalized: function (gc_handle) {
Expand All @@ -199,8 +194,21 @@ var BindingSupportLib = {
return null;
},

_register_js_owned_object: function(gc_handle, js_obj){
this._js_owned_object_table.set(gc_handle, new this._weak_ref_ctor(js_obj));
_register_js_owned_object: function (gc_handle, js_obj) {
var wr;
if (this._is_weak_ref_supported) {
wr = new WeakRef(js_obj);
}
else {
// this is trivial WeakRef replacement, which holds strong refrence, instead of weak one, when the browser doesn't support it
wr = {
deref: () => {
return js_obj;
}
}
}

this._js_owned_object_table.set(gc_handle, wr);
},

_wrap_js_thenable_as_task: function (thenable) {
Expand All @@ -222,7 +230,7 @@ var BindingSupportLib = {
this._mono_wasm_release_js_handle(thenable_js_handle);

// when FinalizationRegistry is not supported by this browser, we will do immediate cleanup after use
if (!this._js_owned_object_registry) {
if (!this._is_finalizarion_registry_supported) {
this._release_js_owned_object_by_gc_handle(tcs_gc_handle);
}
}, (reason) => {
Expand All @@ -231,13 +239,13 @@ var BindingSupportLib = {
this._mono_wasm_release_js_handle(thenable_js_handle);

// when FinalizationRegistry is not supported by this browser, we will do immediate cleanup after use
if (!this._js_owned_object_registry) {
if (!this._is_finalizarion_registry_supported) {
this._release_js_owned_object_by_gc_handle(tcs_gc_handle);
}
});

// collect the TaskCompletionSource with its Task after js doesn't hold the thenable anymore
if (this._js_owned_object_registry) {
if (this._is_finalizarion_registry_supported) {
this._js_owned_object_registry.register(thenable, tcs_gc_handle);
}

Expand Down Expand Up @@ -267,7 +275,7 @@ var BindingSupportLib = {
// note that we do not implement promise/task roundtrip
// With more complexity we could recover original instance when this promise is marshaled back to C#.
var result = new Promise(function (resolve, reject) {
if (self._js_owned_object_registry) {
if (self._is_finalizarion_registry_supported) {
cont_obj = {
resolve: resolve,
reject: reject
Expand Down Expand Up @@ -295,7 +303,7 @@ var BindingSupportLib = {
this._setup_js_cont (root.value, cont_obj );

// register for GC of the Task after the JS side is done with the promise
if (this._js_owned_object_registry) {
if (this._is_finalizarion_registry_supported) {
this._js_owned_object_registry.register(result, gc_handle);
}

Expand Down Expand Up @@ -336,7 +344,7 @@ var BindingSupportLib = {
}

// NOTE: this would be leaking C# objects when the browser doesn't support FinalizationRegistry/WeakRef
if (this._js_owned_object_registry) {
if (this._is_finalizarion_registry_supported) {
// register for GC of the C# object after the JS side is done with the object
this._js_owned_object_registry.register(result, gc_handle);
}
Expand Down Expand Up @@ -395,7 +403,7 @@ var BindingSupportLib = {
}

// NOTE: this would be leaking C# objects when the browser doesn't support FinalizationRegistry. Except in case of EventListener where we cleanup after unregistration.
if (this._js_owned_object_registry) {
if (this._is_finalizarion_registry_supported) {
// register for GC of the deleate after the JS side is done with the function
this._js_owned_object_registry.register(result, gc_handle);
}
Expand Down Expand Up @@ -2037,7 +2045,7 @@ var BindingSupportLib = {
? BINDING.mono_wasm_get_jsobj_from_js_handle(optionsHandle)
: null;

if(!BINDING._js_owned_object_registry){
if(!BINDING._is_finalizarion_registry_supported){
// we are counting registrations because same delegate could be registered into multiple sources
listener.__registration_count__ = listener.__registration_count__ ? listener.__registration_count__ + 1 : 1;
}
Expand Down Expand Up @@ -2073,7 +2081,7 @@ var BindingSupportLib = {
// and trigger the FinalizationRegistry handler if it's unused

// When FinalizationRegistry is not supported by this browser, we cleanup manuall after unregistration
if (!BINDING._js_owned_object_registry) {
if (!BINDING._is_finalizarion_registry_supported) {
listener.__registration_count__--;
if (listener.__registration_count__ === 0) {
BINDING._js_owned_object_table.delete(listener_gc_handle);
Expand Down