Chromium Code Reviews| 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/modules/v8/V8IDBObserverCallback.h" | 5 #include "bindings/modules/v8/V8IDBObserverCallback.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptController.h" | 7 #include "bindings/core/v8/ScriptController.h" |
| 8 #include "bindings/core/v8/ToV8.h" | |
| 8 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 9 #include "bindings/core/v8/V8PrivateProperty.h" | 10 #include "bindings/core/v8/V8PrivateProperty.h" |
| 10 #include "bindings/modules/v8/V8IDBObserver.h" | 11 #include "bindings/modules/v8/V8IDBObserver.h" |
| 12 #include "bindings/modules/v8/V8IDBObserverChanges.h" | |
| 13 #include "wtf/Assertions.h" | |
| 11 | 14 |
| 12 namespace blink { | 15 namespace blink { |
| 13 | 16 |
| 14 V8IDBObserverCallback::V8IDBObserverCallback(v8::Local<v8::Function> callback, v 8::Local<v8::Object> owner, ScriptState* scriptState) | 17 V8IDBObserverCallback::V8IDBObserverCallback(v8::Local<v8::Function> callback, v 8::Local<v8::Object> owner, ScriptState* scriptState) |
| 15 : ActiveDOMCallback(scriptState->getExecutionContext()) | 18 : ActiveDOMCallback(scriptState->getExecutionContext()) |
| 16 , m_callback(scriptState->isolate(), callback) | 19 , m_callback(scriptState->isolate(), callback) |
| 17 , m_scriptState(scriptState) | 20 , m_scriptState(scriptState) |
| 18 { | 21 { |
| 19 V8PrivateProperty::getIDBObserverCallback(scriptState->isolate()).set(script State->context(), owner, callback); | 22 V8PrivateProperty::getIDBObserverCallback(scriptState->isolate()).set(script State->context(), owner, callback); |
| 20 m_callback.setPhantom(); | 23 m_callback.setPhantom(); |
| 21 } | 24 } |
| 22 | 25 |
| 23 V8IDBObserverCallback::~V8IDBObserverCallback() | 26 V8IDBObserverCallback::~V8IDBObserverCallback() |
| 24 { | 27 { |
| 25 } | 28 } |
| 26 | 29 |
| 30 void V8IDBObserverCallback::handleChanges(IDBObserverChanges& changes, IDBObserv er& observer) | |
| 31 { | |
| 32 if (!canInvokeCallback()) | |
| 33 return; | |
| 34 | |
| 35 if (!m_scriptState->contextIsValid()) | |
| 36 return; | |
| 37 ScriptState::Scope scope(m_scriptState.get()); | |
| 38 | |
| 39 if (m_callback.isEmpty()) | |
| 40 return; | |
| 41 v8::Local<v8::Value> observerHandle = toV8(&observer, m_scriptState->context ()->Global(), m_scriptState->isolate()); | |
| 42 if (observerHandle.IsEmpty()) { | |
| 43 if (!isScriptControllerTerminating()) | |
| 44 CRASH(); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 if (!observerHandle->IsObject()) | |
| 49 return; | |
| 50 | |
| 51 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(observerHandl e); | |
| 52 v8::Local<v8::Value> changesHandle = toV8(&changes, m_scriptState->context() ->Global(), m_scriptState->isolate()); | |
| 53 if (changesHandle.IsEmpty()) | |
| 54 return; | |
| 55 | |
| 56 v8::Local<v8::Value> argv[] = { changesHandle }; | |
| 57 | |
| 58 v8::TryCatch exceptionCatcher(m_scriptState->isolate()); | |
| 59 exceptionCatcher.SetVerbose(true); | |
| 60 V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), m_scriptState->getExecutionContext(), thisObject, 1, argv, m_scriptState->isolat e()); | |
|
haraken
2016/07/20 19:11:15
1 => WTF_ARRAY_LENGTH
| |
| 61 } | |
| 62 | |
| 27 DEFINE_TRACE(V8IDBObserverCallback) | 63 DEFINE_TRACE(V8IDBObserverCallback) |
| 28 { | 64 { |
| 29 IDBObserverCallback::trace(visitor); | 65 IDBObserverCallback::trace(visitor); |
| 30 ActiveDOMCallback::trace(visitor); | 66 ActiveDOMCallback::trace(visitor); |
| 31 } | 67 } |
| 32 | 68 |
| 33 } // namespace blink | 69 } // namespace blink |
| OLD | NEW |