Index: extensions/renderer/resources/messaging.js |
diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js |
index 9fc29d49752b1e788edc7015cf1c8e4725e5f5e6..5ff748e3c5a2bf172ff6ca3d16bc033eb0758fa8 100644 |
--- a/extensions/renderer/resources/messaging.js |
+++ b/extensions/renderer/resources/messaging.js |
@@ -128,12 +128,18 @@ |
// doesn't keep a reference to it, we need to clean up the port. Do |
// so by attaching to the garbage collection of the responseCallback |
// using some native hackery. |
+ // |
+ // If the context is destroyed before this has a chance to execute, |
+ // BindToGC knows to release |portId| (important for updating C++ state |
+ // both in this renderer and on the other end). We don't need to clear |
+ // any JavaScript state, as calling destroy_() would usually do - but |
+ // the context has been destroyed, so there isn't any JS state to clear. |
messagingNatives.BindToGC(responseCallback, function() { |
if (port) { |
privates(port).impl.destroy_(); |
port = null; |
} |
- }); |
+ }, portId); |
var rv = requestEvent.dispatch(request, sender, responseCallback); |
if (isSendMessage) { |
responseCallbackPreserved = |