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 "bindings/core/v8/V8IntersectionObserverCallback.h" | 5 #include "bindings/core/v8/V8IntersectionObserverCallback.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptController.h" | 7 #include "bindings/core/v8/ScriptController.h" |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "bindings/core/v8/V8IntersectionObserver.h" | 9 #include "bindings/core/v8/V8IntersectionObserver.h" |
10 #include "bindings/core/v8/V8PrivateProperty.h" | 10 #include "bindings/core/v8/V8PrivateProperty.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
12 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 V8IntersectionObserverCallback::V8IntersectionObserverCallback( | 16 V8IntersectionObserverCallback::V8IntersectionObserverCallback( |
17 v8::Local<v8::Function> callback, | 17 v8::Local<v8::Function> callback, |
18 v8::Local<v8::Object> owner, | 18 v8::Local<v8::Object> owner, |
19 ScriptState* scriptState) | 19 ScriptState* scriptState) |
20 : ActiveDOMCallback(scriptState->getExecutionContext()), | 20 : m_callback(scriptState->isolate(), callback), m_scriptState(scriptState) { |
21 m_callback(scriptState->isolate(), callback), | |
22 m_scriptState(scriptState) { | |
23 V8PrivateProperty::getIntersectionObserverCallback(scriptState->isolate()) | 21 V8PrivateProperty::getIntersectionObserverCallback(scriptState->isolate()) |
24 .set(scriptState->context(), owner, callback); | 22 .set(scriptState->context(), owner, callback); |
25 m_callback.setPhantom(); | 23 m_callback.setPhantom(); |
26 } | 24 } |
27 | 25 |
28 V8IntersectionObserverCallback::~V8IntersectionObserverCallback() {} | 26 V8IntersectionObserverCallback::~V8IntersectionObserverCallback() {} |
29 | 27 |
30 void V8IntersectionObserverCallback::handleEvent( | 28 void V8IntersectionObserverCallback::handleEvent( |
31 const HeapVector<Member<IntersectionObserverEntry>>& entries, | 29 const HeapVector<Member<IntersectionObserverEntry>>& entries, |
32 IntersectionObserver& observer) { | 30 IntersectionObserver& observer) { |
33 if (!canInvokeCallback()) | 31 ExecutionContext* executionContext = m_scriptState->getExecutionContext(); |
| 32 if (!executionContext || executionContext->isContextSuspended() || |
| 33 executionContext->isContextDestroyed()) |
34 return; | 34 return; |
35 | |
36 if (!m_scriptState->contextIsValid()) | 35 if (!m_scriptState->contextIsValid()) |
37 return; | 36 return; |
38 ScriptState::Scope scope(m_scriptState.get()); | 37 ScriptState::Scope scope(m_scriptState.get()); |
39 | 38 |
40 if (m_callback.isEmpty()) | 39 if (m_callback.isEmpty()) |
41 return; | 40 return; |
42 v8::Local<v8::Value> observerHandle = toV8( | 41 v8::Local<v8::Value> observerHandle = toV8( |
43 &observer, m_scriptState->context()->Global(), m_scriptState->isolate()); | 42 &observer, m_scriptState->context()->Global(), m_scriptState->isolate()); |
44 if (!observerHandle->IsObject()) | 43 if (!observerHandle->IsObject()) |
45 return; | 44 return; |
46 | 45 |
47 v8::Local<v8::Object> thisObject = | 46 v8::Local<v8::Object> thisObject = |
48 v8::Local<v8::Object>::Cast(observerHandle); | 47 v8::Local<v8::Object>::Cast(observerHandle); |
49 v8::Local<v8::Value> entriesHandle = toV8( | 48 v8::Local<v8::Value> entriesHandle = toV8( |
50 entries, m_scriptState->context()->Global(), m_scriptState->isolate()); | 49 entries, m_scriptState->context()->Global(), m_scriptState->isolate()); |
51 if (entriesHandle.IsEmpty()) { | 50 if (entriesHandle.IsEmpty()) { |
52 return; | 51 return; |
53 } | 52 } |
54 v8::Local<v8::Value> argv[] = {entriesHandle, observerHandle}; | 53 v8::Local<v8::Value> argv[] = {entriesHandle, observerHandle}; |
55 | 54 |
56 v8::TryCatch exceptionCatcher(m_scriptState->isolate()); | 55 v8::TryCatch exceptionCatcher(m_scriptState->isolate()); |
57 exceptionCatcher.SetVerbose(true); | 56 exceptionCatcher.SetVerbose(true); |
58 V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), | 57 V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), |
59 m_scriptState->getExecutionContext(), thisObject, | 58 m_scriptState->getExecutionContext(), thisObject, |
60 2, argv, m_scriptState->isolate()); | 59 2, argv, m_scriptState->isolate()); |
61 } | 60 } |
62 | 61 |
63 DEFINE_TRACE(V8IntersectionObserverCallback) { | 62 DEFINE_TRACE(V8IntersectionObserverCallback) { |
64 IntersectionObserverCallback::trace(visitor); | 63 IntersectionObserverCallback::trace(visitor); |
65 ActiveDOMCallback::trace(visitor); | |
66 } | 64 } |
67 | 65 |
68 } // namespace blink | 66 } // namespace blink |
OLD | NEW |