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

Unified Diff: extensions/renderer/event_emitter.cc

Issue 2605353003: [Extensions Bindings] Allow event listener unregistration in handling (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « extensions/renderer/api_event_handler_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/event_emitter.cc
diff --git a/extensions/renderer/event_emitter.cc b/extensions/renderer/event_emitter.cc
index 74245a54e0622e57bc7f91a447eae684ed4bca75..afc358a6a6ce60a105910fbafe0fd7c3f34a8b31 100644
--- a/extensions/renderer/event_emitter.cc
+++ b/extensions/renderer/event_emitter.cc
@@ -34,10 +34,15 @@ gin::ObjectTemplateBuilder EventEmitter::GetObjectTemplateBuilder(
void EventEmitter::Fire(v8::Local<v8::Context> context,
std::vector<v8::Local<v8::Value>>* args) {
- for (const auto& listener : listeners_) {
- run_js_.Run(listener.Get(context->GetIsolate()), context, args->size(),
- args->data());
- }
+ // We create a local copy of listeners_ since the array can be modified during
+ // handling.
+ std::vector<v8::Local<v8::Function>> listeners;
+ listeners.reserve(listeners_.size());
+ for (const auto& listener : listeners_)
+ listeners.push_back(listener.Get(context->GetIsolate()));
+
+ for (const auto& listener : listeners)
+ run_js_.Run(listener, context, args->size(), args->data());
}
void EventEmitter::AddListener(gin::Arguments* arguments) {
« no previous file with comments | « extensions/renderer/api_event_handler_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698