Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/V8IDBObserverCallback.cpp

Issue 2397363002: Replace hand-written IDBObserverCallback with auto-generated code (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "bindings/modules/v8/V8IDBObserverCallback.h"
6
7 #include "bindings/core/v8/ScriptController.h"
8 #include "bindings/core/v8/ToV8.h"
9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8PrivateProperty.h"
11 #include "bindings/modules/v8/V8IDBObserver.h"
12 #include "bindings/modules/v8/V8IDBObserverChanges.h"
13 #include "wtf/Assertions.h"
14
15 namespace blink {
16
17 V8IDBObserverCallback::V8IDBObserverCallback(v8::Local<v8::Function> callback,
18 v8::Local<v8::Object> owner,
19 ScriptState* scriptState)
20 : ActiveDOMCallback(scriptState->getExecutionContext()),
21 m_callback(scriptState->isolate(), callback),
22 m_scriptState(scriptState) {
23 V8PrivateProperty::getIDBObserverCallback(scriptState->isolate())
24 .set(scriptState->context(), owner, callback);
25 m_callback.setPhantom();
26 }
27
28 V8IDBObserverCallback::~V8IDBObserverCallback() {}
29
30 void V8IDBObserverCallback::handleChanges(IDBObserverChanges& changes,
31 IDBObserver& observer) {
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(
42 &observer, m_scriptState->context()->Global(), m_scriptState->isolate());
43 if (!observerHandle->IsObject())
44 return;
45
46 v8::Local<v8::Object> thisObject =
47 v8::Local<v8::Object>::Cast(observerHandle);
48 v8::Local<v8::Value> changesHandle = toV8(
49 &changes, m_scriptState->context()->Global(), m_scriptState->isolate());
50 if (changesHandle.IsEmpty())
51 return;
52
53 v8::Local<v8::Value> argv[] = {changesHandle};
54
55 V8ScriptRunner::callFunction(m_callback.newLocal(m_scriptState->isolate()),
56 m_scriptState->getExecutionContext(), thisObject,
57 WTF_ARRAY_LENGTH(argv), argv,
58 m_scriptState->isolate());
59 }
60
61 DEFINE_TRACE(V8IDBObserverCallback) {
62 IDBObserverCallback::trace(visitor);
63 ActiveDOMCallback::trace(visitor);
64 }
65
66 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698