| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/event_emitter.h" | 5 #include "extensions/renderer/event_emitter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "gin/object_template_builder.h" | 9 #include "gin/object_template_builder.h" |
| 10 #include "gin/per_context_data.h" | 10 #include "gin/per_context_data.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 void EventEmitter::Fire(v8::Local<v8::Context> context, | 35 void EventEmitter::Fire(v8::Local<v8::Context> context, |
| 36 std::vector<v8::Local<v8::Value>>* args) { | 36 std::vector<v8::Local<v8::Value>>* args) { |
| 37 // We create a local copy of listeners_ since the array can be modified during | 37 // We create a local copy of listeners_ since the array can be modified during |
| 38 // handling. | 38 // handling. |
| 39 std::vector<v8::Local<v8::Function>> listeners; | 39 std::vector<v8::Local<v8::Function>> listeners; |
| 40 listeners.reserve(listeners_.size()); | 40 listeners.reserve(listeners_.size()); |
| 41 for (const auto& listener : listeners_) | 41 for (const auto& listener : listeners_) |
| 42 listeners.push_back(listener.Get(context->GetIsolate())); | 42 listeners.push_back(listener.Get(context->GetIsolate())); |
| 43 | 43 |
| 44 for (const auto& listener : listeners) | 44 for (const auto& listener : listeners) { |
| 45 v8::TryCatch try_catch(context->GetIsolate()); |
| 46 // SetVerbose() means the error will still get logged, which is what we |
| 47 // want. We don't let it bubble up any further to prevent it from being |
| 48 // surfaced in e.g. JS code that triggered the event. |
| 49 try_catch.SetVerbose(true); |
| 45 run_js_.Run(listener, context, args->size(), args->data()); | 50 run_js_.Run(listener, context, args->size(), args->data()); |
| 51 } |
| 46 } | 52 } |
| 47 | 53 |
| 48 void EventEmitter::AddListener(gin::Arguments* arguments) { | 54 void EventEmitter::AddListener(gin::Arguments* arguments) { |
| 49 v8::Local<v8::Function> listener; | 55 v8::Local<v8::Function> listener; |
| 50 if (!arguments->GetNext(&listener)) | 56 if (!arguments->GetNext(&listener)) |
| 51 return; | 57 return; |
| 52 | 58 |
| 53 v8::Local<v8::Object> holder; | 59 v8::Local<v8::Object> holder; |
| 54 CHECK(arguments->GetHolder(&holder)); | 60 CHECK(arguments->GetHolder(&holder)); |
| 55 CHECK(!holder.IsEmpty()); | 61 CHECK(!holder.IsEmpty()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 85 arguments->isolate()->GetCurrentContext(); | 91 arguments->isolate()->GetCurrentContext(); |
| 86 std::vector<v8::Local<v8::Value>> v8_args; | 92 std::vector<v8::Local<v8::Value>> v8_args; |
| 87 if (arguments->Length() > 0) { | 93 if (arguments->Length() > 0) { |
| 88 // Converting to v8::Values should never fail. | 94 // Converting to v8::Values should never fail. |
| 89 CHECK(arguments->GetRemaining(&v8_args)); | 95 CHECK(arguments->GetRemaining(&v8_args)); |
| 90 } | 96 } |
| 91 Fire(context, &v8_args); | 97 Fire(context, &v8_args); |
| 92 } | 98 } |
| 93 | 99 |
| 94 } // namespace extensions | 100 } // namespace extensions |
| OLD | NEW |