Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: extensions/renderer/event_emitter.cc

Issue 2722463006: [Extensions Bindings] Notify of event unregistration on invalidation (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/event_emitter.cc
diff --git a/extensions/renderer/event_emitter.cc b/extensions/renderer/event_emitter.cc
index 96eab80b41dbe84b29b28b8d0c17eed8d1de25c7..a9c44d0ed1feabbe36e351f9969f8c2f692e4614 100644
--- a/extensions/renderer/event_emitter.cc
+++ b/extensions/renderer/event_emitter.cc
@@ -52,7 +52,15 @@ void EventEmitter::Fire(v8::Local<v8::Context> context,
}
}
+void EventEmitter::Invalidate() {
+ valid_ = false;
+ listeners_.clear();
+}
+
void EventEmitter::AddListener(gin::Arguments* arguments) {
+ if (!valid_)
jbroman 2017/03/01 17:49:47 This won't catch such objects which don't are crea
Devlin 2017/03/01 19:03:50 Yeah, I still don't have a complete grasp of all t
jbroman 2017/03/01 19:26:34 Well, that's slightly later than WillReleaseScript
Devlin 2017/03/02 17:26:32 Done. Added comments in InvalidateContext() and a
+ return;
+
v8::Local<v8::Function> listener;
// TODO(devlin): For some reason, we don't throw an error when someone calls
// add/removeListener with no argument. We probably should. For now, keep
@@ -78,6 +86,9 @@ void EventEmitter::AddListener(gin::Arguments* arguments) {
}
void EventEmitter::RemoveListener(gin::Arguments* arguments) {
+ if (!valid_)
jbroman 2017/03/01 17:49:47 Isn't |listeners_| empty in this case anyhow?
Devlin 2017/03/01 19:03:50 Yep, but this seemed more obvious to readers. If
+ return;
+
v8::Local<v8::Function> listener;
// See comment in AddListener().
if (!arguments->GetNext(&listener))
@@ -107,6 +118,8 @@ bool EventEmitter::HasListeners() {
}
void EventEmitter::Dispatch(gin::Arguments* arguments) {
+ DCHECK(valid_);
jbroman 2017/03/01 19:26:34 Should this be a DCHECK or an early return? Script
Devlin 2017/03/02 17:26:32 Oh, right, we had to expose this. Forgot about th
+
if (listeners_.empty())
return;
v8::HandleScope handle_scope(arguments->isolate());

Powered by Google App Engine
This is Rietveld 408576698