| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 V8PrivateProperty::GetIntersectionObserverCallback(script_state->GetIsolate()) | 22 V8PrivateProperty::GetIntersectionObserverCallback(script_state->GetIsolate()) |
| 23 .Set(owner, callback); | 23 .Set(owner, callback); |
| 24 callback_.SetPhantom(); | 24 callback_.SetPhantom(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 V8IntersectionObserverCallback::~V8IntersectionObserverCallback() {} | 27 V8IntersectionObserverCallback::~V8IntersectionObserverCallback() {} |
| 28 | 28 |
| 29 void V8IntersectionObserverCallback::HandleEvent( | 29 void V8IntersectionObserverCallback::HandleEvent( |
| 30 const HeapVector<Member<IntersectionObserverEntry>>& entries, | 30 const HeapVector<Member<IntersectionObserverEntry>>& entries, |
| 31 IntersectionObserver& observer) { | 31 IntersectionObserver& observer) { |
| 32 ExecutionContext* execution_context = script_state_->GetExecutionContext(); | 32 ExecutionContext* execution_context = |
| 33 ExecutionContext::From(script_state_.Get()); |
| 33 if (!execution_context || execution_context->IsContextSuspended() || | 34 if (!execution_context || execution_context->IsContextSuspended() || |
| 34 execution_context->IsContextDestroyed()) | 35 execution_context->IsContextDestroyed()) |
| 35 return; | 36 return; |
| 36 if (!script_state_->ContextIsValid()) | 37 if (!script_state_->ContextIsValid()) |
| 37 return; | 38 return; |
| 38 ScriptState::Scope scope(script_state_.Get()); | 39 ScriptState::Scope scope(script_state_.Get()); |
| 39 | 40 |
| 40 if (callback_.IsEmpty()) | 41 if (callback_.IsEmpty()) |
| 41 return; | 42 return; |
| 42 v8::Local<v8::Value> observer_handle = | 43 v8::Local<v8::Value> observer_handle = |
| 43 ToV8(&observer, script_state_->GetContext()->Global(), | 44 ToV8(&observer, script_state_->GetContext()->Global(), |
| 44 script_state_->GetIsolate()); | 45 script_state_->GetIsolate()); |
| 45 if (!observer_handle->IsObject()) | 46 if (!observer_handle->IsObject()) |
| 46 return; | 47 return; |
| 47 | 48 |
| 48 v8::Local<v8::Object> this_object = | 49 v8::Local<v8::Object> this_object = |
| 49 v8::Local<v8::Object>::Cast(observer_handle); | 50 v8::Local<v8::Object>::Cast(observer_handle); |
| 50 v8::Local<v8::Value> entries_handle = | 51 v8::Local<v8::Value> entries_handle = |
| 51 ToV8(entries, script_state_->GetContext()->Global(), | 52 ToV8(entries, script_state_->GetContext()->Global(), |
| 52 script_state_->GetIsolate()); | 53 script_state_->GetIsolate()); |
| 53 if (entries_handle.IsEmpty()) { | 54 if (entries_handle.IsEmpty()) { |
| 54 return; | 55 return; |
| 55 } | 56 } |
| 56 v8::Local<v8::Value> argv[] = {entries_handle, observer_handle}; | 57 v8::Local<v8::Value> argv[] = {entries_handle, observer_handle}; |
| 57 | 58 |
| 58 v8::TryCatch exception_catcher(script_state_->GetIsolate()); | 59 v8::TryCatch exception_catcher(script_state_->GetIsolate()); |
| 59 exception_catcher.SetVerbose(true); | 60 exception_catcher.SetVerbose(true); |
| 60 V8ScriptRunner::CallFunction(callback_.NewLocal(script_state_->GetIsolate()), | 61 V8ScriptRunner::CallFunction(callback_.NewLocal(script_state_->GetIsolate()), |
| 61 script_state_->GetExecutionContext(), | 62 ExecutionContext::From(script_state_.Get()), |
| 62 this_object, 2, argv, | 63 this_object, 2, argv, |
| 63 script_state_->GetIsolate()); | 64 script_state_->GetIsolate()); |
| 64 } | 65 } |
| 65 | 66 |
| 66 DEFINE_TRACE(V8IntersectionObserverCallback) { | 67 DEFINE_TRACE(V8IntersectionObserverCallback) { |
| 67 IntersectionObserverCallback::Trace(visitor); | 68 IntersectionObserverCallback::Trace(visitor); |
| 68 } | 69 } |
| 69 | 70 |
| 70 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |