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::handleEvent(IDBObserverChanges& changes, IDBObserver & observer) | |
| 31 { | |
| 32 | |
|
jsbell
2016/07/11 18:25:33
Nit: remove this blank line
palakj1
2016/07/11 22:25:40
Done
| |
| 33 if (!canInvokeCallback()) | |
| 34 return; | |
| 35 | |
| 36 if (!m_scriptState->contextIsValid()) | |
| 37 return; | |
| 38 ScriptState::Scope scope(m_scriptState.get()); | |
| 39 | |
| 40 if (m_callback.isEmpty()) | |
| 41 return; | |
| 42 v8::Local<v8::Value> observerHandle = toV8(&observer, m_scriptState->context ()->Global(), m_scriptState->isolate()); | |
| 43 if (observerHandle.IsEmpty()) { | |
| 44 if (!isScriptControllerTerminating()) | |
| 45 CRASH(); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 if (!observerHandle->IsObject()) | |
| 50 return; | |
| 51 | |
| 52 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(observerHandl e); | |
| 53 v8::Local<v8::Value> changesHandle = toV8(&changes, m_scriptState->context() ->Global(), m_scriptState->isolate()); | |
| 54 if (changesHandle.IsEmpty()) { | |
| 55 return; | |
| 56 } | |
| 57 v8::Local<v8::Value> argv[] = { changesHandle }; | |
| 58 | |
| 59 v8::TryCatch exceptionCatcher(m_scriptState->isolate()); | |
| 60 exceptionCatcher.SetVerbose(true); | |
| 61 V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()), m_scriptState->getExecutionContext(), thisObject, 1, argv, m_scriptState->isolat e()); | |
| 62 } | |
| 63 | |
| 27 DEFINE_TRACE(V8IDBObserverCallback) | 64 DEFINE_TRACE(V8IDBObserverCallback) |
| 28 { | 65 { |
| 29 IDBObserverCallback::trace(visitor); | 66 IDBObserverCallback::trace(visitor); |
| 30 ActiveDOMCallback::trace(visitor); | 67 ActiveDOMCallback::trace(visitor); |
| 31 } | 68 } |
| 32 | 69 |
| 33 } // namespace blink | 70 } // namespace blink |
| OLD | NEW |