OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "bindings/core/v8/V8AbstractEventListener.h" | 31 #include "bindings/core/v8/V8AbstractEventListener.h" |
32 | 32 |
33 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
34 #include "bindings/core/v8/V8Event.h" | 34 #include "bindings/core/v8/V8Event.h" |
35 #include "bindings/core/v8/V8EventListenerHelper.h" | 35 #include "bindings/core/v8/V8EventListenerHelper.h" |
36 #include "bindings/core/v8/V8EventTarget.h" | 36 #include "bindings/core/v8/V8EventTarget.h" |
37 #include "bindings/core/v8/V8HiddenValue.h" | 37 #include "bindings/core/v8/V8HiddenValue.h" |
38 #include "core/dom/Document.h" | |
39 #include "core/dom/DocumentParser.h" | |
38 #include "core/events/BeforeUnloadEvent.h" | 40 #include "core/events/BeforeUnloadEvent.h" |
39 #include "core/events/Event.h" | 41 #include "core/events/Event.h" |
40 #include "core/workers/WorkerGlobalScope.h" | 42 #include "core/workers/WorkerGlobalScope.h" |
41 #include "platform/InstanceCounters.h" | 43 #include "platform/InstanceCounters.h" |
42 | 44 |
43 namespace blink { | 45 namespace blink { |
44 | 46 |
45 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, | 47 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, |
46 DOMWrapperWorld& world, | 48 DOMWrapperWorld& world, |
47 v8::Isolate* isolate) | 49 v8::Isolate* isolate) |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 194 |
193 EventTarget* target = event->currentTarget(); | 195 EventTarget* target = event->currentTarget(); |
194 v8::Local<v8::Value> value = | 196 v8::Local<v8::Value> value = |
195 toV8(target, scriptState->context()->Global(), isolate()); | 197 toV8(target, scriptState->context()->Global(), isolate()); |
196 if (value.IsEmpty()) | 198 if (value.IsEmpty()) |
197 return v8::Local<v8::Object>(); | 199 return v8::Local<v8::Object>(); |
198 return v8::Local<v8::Object>::New(isolate(), | 200 return v8::Local<v8::Object>::New(isolate(), |
199 v8::Local<v8::Object>::Cast(value)); | 201 v8::Local<v8::Object>::Cast(value)); |
200 } | 202 } |
201 | 203 |
202 bool V8AbstractEventListener::belongsToTheCurrentWorld() const { | 204 bool V8AbstractEventListener::belongsToTheCurrentWorld( |
203 return ScriptState::hasCurrentScriptState(isolate()) && | 205 ExecutionContext* executionContext) const { |
204 &world() == &DOMWrapperWorld::current(isolate()); | 206 if (ScriptState::hasCurrentScriptState(isolate()) && |
207 &world() == &DOMWrapperWorld::current(isolate())) | |
208 return true; | |
209 // If currently parsing, the parser could be accessing this listener | |
210 // outside of any v8 context; check if it belongs to the main world. | |
211 if (!isolate()->InContext() && executionContext->isDocument()) { | |
haraken
2016/11/11 03:54:40
Maybe the following looks a bit tidier?
if (Scrip
sof
2016/11/11 06:27:04
If the current context is a debugger context, you
| |
212 Document* document = toDocument(executionContext); | |
213 if (document->parser() && document->parser()->isParsing()) | |
214 return world().isMainWorld(); | |
215 } | |
216 return false; | |
205 } | 217 } |
206 | 218 |
207 void V8AbstractEventListener::clearListenerObject() { | 219 void V8AbstractEventListener::clearListenerObject() { |
208 if (!hasExistingListenerObject()) | 220 if (!hasExistingListenerObject()) |
209 return; | 221 return; |
210 m_listener.clear(); | 222 m_listener.clear(); |
211 if (m_workerGlobalScope) { | 223 if (m_workerGlobalScope) { |
212 m_workerGlobalScope->deregisterEventListener(this); | 224 m_workerGlobalScope->deregisterEventListener(this); |
213 } else { | 225 } else { |
214 m_keepAlive.clear(); | 226 m_keepAlive.clear(); |
215 } | 227 } |
216 } | 228 } |
217 | 229 |
218 void V8AbstractEventListener::wrapperCleared( | 230 void V8AbstractEventListener::wrapperCleared( |
219 const v8::WeakCallbackInfo<V8AbstractEventListener>& data) { | 231 const v8::WeakCallbackInfo<V8AbstractEventListener>& data) { |
220 data.GetParameter()->clearListenerObject(); | 232 data.GetParameter()->clearListenerObject(); |
221 } | 233 } |
222 | 234 |
223 DEFINE_TRACE(V8AbstractEventListener) { | 235 DEFINE_TRACE(V8AbstractEventListener) { |
224 visitor->trace(m_workerGlobalScope); | 236 visitor->trace(m_workerGlobalScope); |
225 EventListener::trace(visitor); | 237 EventListener::trace(visitor); |
226 } | 238 } |
227 | 239 |
228 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) { | 240 DEFINE_TRACE_WRAPPERS(V8AbstractEventListener) { |
229 visitor->traceWrappers(m_listener.cast<v8::Value>()); | 241 visitor->traceWrappers(m_listener.cast<v8::Value>()); |
230 } | 242 } |
231 | 243 |
232 } // namespace blink | 244 } // namespace blink |
OLD | NEW |