OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "core/inspector/v8/V8InjectedScriptHost.h" | 6 #include "core/inspector/v8/V8InjectedScriptHost.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
10 #include "bindings/core/v8/V8AbstractEventListener.h" | 10 #include "bindings/core/v8/V8AbstractEventListener.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); | 251 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); |
252 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info
.GetIsolate(), object); | 252 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info
.GetIsolate(), object); |
253 v8SetReturnValue(info, properties); | 253 v8SetReturnValue(info, properties); |
254 } | 254 } |
255 | 255 |
256 static v8::Local<v8::Array> getJSListenerFunctions(v8::Isolate* isolate, Executi
onContext* executionContext, const EventListenerInfo& listenerInfo) | 256 static v8::Local<v8::Array> getJSListenerFunctions(v8::Isolate* isolate, Executi
onContext* executionContext, const EventListenerInfo& listenerInfo) |
257 { | 257 { |
258 v8::Local<v8::Array> result = v8::Array::New(isolate); | 258 v8::Local<v8::Array> result = v8::Array::New(isolate); |
259 size_t handlersCount = listenerInfo.eventListenerVector.size(); | 259 size_t handlersCount = listenerInfo.eventListenerVector.size(); |
260 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { | 260 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { |
261 RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].lis
tener; | 261 EventListener* listener = listenerInfo.eventListenerVector[i].listener.g
et(); |
| 262 RefPtrWillBeRawPtr<EventListener> protect(listener); |
262 if (listener->type() != EventListener::JSEventListenerType) { | 263 if (listener->type() != EventListener::JSEventListenerType) { |
263 ASSERT_NOT_REACHED(); | 264 ASSERT_NOT_REACHED(); |
264 continue; | 265 continue; |
265 } | 266 } |
266 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene
r*>(listener.get()); | 267 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene
r*>(listener); |
267 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listene
r->world()); | 268 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listene
r->world()); |
268 // Hide listeners from other contexts. | 269 // Hide listeners from other contexts. |
269 if (context != isolate->GetCurrentContext()) | 270 if (context != isolate->GetCurrentContext()) |
270 continue; | 271 continue; |
271 v8::Local<v8::Object> function; | 272 v8::Local<v8::Object> function; |
272 { | 273 { |
273 // getListenerObject() may cause JS in the event attribute to get co
mpiled, potentially unsuccessfully. | 274 // getListenerObject() may cause JS in the event attribute to get co
mpiled, potentially unsuccessfully. |
274 v8::TryCatch block; | 275 v8::TryCatch block; |
275 function = v8Listener->getListenerObject(executionContext); | 276 function = v8Listener->getListenerObject(executionContext); |
276 if (block.HasCaught()) | 277 if (block.HasCaught()) |
(...skipping 10 matching lines...) Expand all Loading... |
287 | 288 |
288 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 289 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
289 { | 290 { |
290 if (info.Length() < 1) | 291 if (info.Length() < 1) |
291 return; | 292 return; |
292 | 293 |
293 EventTarget* target = InjectedScriptHost::eventTargetFromV8Value(info.GetIso
late(), info[0]); | 294 EventTarget* target = InjectedScriptHost::eventTargetFromV8Value(info.GetIso
late(), info[0]); |
294 if (!target) | 295 if (!target) |
295 return; | 296 return; |
296 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); | 297 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); |
297 Vector<EventListenerInfo> listenersArray; | 298 WillBeHeapVector<EventListenerInfo> listenersArray; |
298 host->getEventListenersImpl(target, listenersArray); | 299 host->getEventListenersImpl(target, listenersArray); |
299 | 300 |
300 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | 301 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); |
301 for (size_t i = 0; i < listenersArray.size(); ++i) { | 302 for (size_t i = 0; i < listenersArray.size(); ++i) { |
302 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate(
), target->executionContext(), listenersArray[i]); | 303 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate(
), target->executionContext(), listenersArray[i]); |
303 if (!listeners->Length()) | 304 if (!listeners->Length()) |
304 continue; | 305 continue; |
305 AtomicString eventType = listenersArray[i].eventType; | 306 AtomicString eventType = listenersArray[i].eventType; |
306 result->Set(v8String(info.GetIsolate(), eventType), listeners); | 307 result->Set(v8String(info.GetIsolate(), eventType), listeners); |
307 } | 308 } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 { | 615 { |
615 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); | 616 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
616 } | 617 } |
617 | 618 |
618 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Object> object) | 619 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Object> object) |
619 { | 620 { |
620 return InjectedScriptHostWrapper::unwrap(object); | 621 return InjectedScriptHostWrapper::unwrap(object); |
621 } | 622 } |
622 | 623 |
623 } // namespace blink | 624 } // namespace blink |
OLD | NEW |