fail fast if the delegate was collected prematurely (#56523)
authorPavel Savara <pavelsavara@microsoft.com>
Fri, 30 Jul 2021 05:56:22 +0000 (07:56 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Jul 2021 05:56:22 +0000 (07:56 +0200)
src/mono/wasm/runtime/binding_support.js

index d9d02da..85b8944 100644 (file)
@@ -892,6 +892,12 @@ var BindingSupportLib = {
                                // It's possible the managed object corresponding to this JS object was collected,
                                //  in which case we need to make a new one.
                                if (!result) {
+
+                                       if (typeof js_obj.__mono_delegate_alive__ !== "undefined") {
+                                               console.log("The delegate target that is being invoked is no longer available.  Please check if it has been prematurely GC'd.");
+                                               return null;
+                                       }
+               
                                        delete js_obj.__mono_gchandle__;
                                        delete js_obj.is_mono_bridged_obj;
                                }