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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/custom/V8IDBObserverCustom.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
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/V8IDBObserver.h" 5 #include "bindings/modules/v8/V8IDBObserver.h"
6 6
7 #include "bindings/core/v8/ExceptionMessages.h" 7 #include "bindings/core/v8/ExceptionMessages.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8DOMWrapper.h" 10 #include "bindings/core/v8/V8DOMWrapper.h"
11 #include "bindings/modules/v8/V8IDBObserverCallback.h" 11 #include "bindings/core/v8/V8PrivateProperty.h"
12 #include "bindings/modules/v8/IDBObserverCallback.h"
12 #include "bindings/modules/v8/V8IDBObserverInit.h" 13 #include "bindings/modules/v8/V8IDBObserverInit.h"
13 14
14 namespace blink { 15 namespace blink {
15 16
16 void V8IDBObserver::constructorCustom( 17 void V8IDBObserver::constructorCustom(
17 const v8::FunctionCallbackInfo<v8::Value>& info) { 18 const v8::FunctionCallbackInfo<v8::Value>& info) {
18 ExceptionState exceptionState( 19 ExceptionState exceptionState(
19 info.GetIsolate(), ExceptionState::ConstructionContext, "IDBObserver"); 20 info.GetIsolate(), ExceptionState::ConstructionContext, "IDBObserver");
20 21
21 if (UNLIKELY(info.Length() < 1)) { 22 if (UNLIKELY(info.Length() < 1)) {
(...skipping 15 matching lines...) Expand all
37 exceptionState.throwTypeError("parameter 2 ('options') is not an object."); 38 exceptionState.throwTypeError("parameter 2 ('options') is not an object.");
38 return; 39 return;
39 } 40 }
40 41
41 IDBObserverInit idbObserverInit; 42 IDBObserverInit idbObserverInit;
42 V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit, 43 V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit,
43 exceptionState); 44 exceptionState);
44 if (exceptionState.hadException()) 45 if (exceptionState.hadException())
45 return; 46 return;
46 47
48 v8::Local<v8::Function> v8Callback = v8::Local<v8::Function>::Cast(info[0]);
47 IDBObserverCallback* callback = 49 IDBObserverCallback* callback =
48 new V8IDBObserverCallback(v8::Local<v8::Function>::Cast(info[0]), wrapper, 50 IDBObserverCallback::create(info.GetIsolate(), v8Callback);
49 ScriptState::current(info.GetIsolate())); 51 IDBObserver* observer = IDBObserver::create(
50 IDBObserver* observer = IDBObserver::create(*callback, idbObserverInit); 52 ScriptState::forReceiverObject(info), callback, idbObserverInit);
51 if (exceptionState.hadException()) 53 if (exceptionState.hadException())
52 return; 54 return;
53 DCHECK(observer); 55 DCHECK(observer);
56 // TODO(bashi): Don't set private property (and remove this custom
57 // constructor) when we can call setWrapperReference() correctly.
58 V8PrivateProperty::getIDBObserverCallback(info.GetIsolate())
59 .set(info.GetIsolate()->GetCurrentContext(), wrapper, v8Callback);
54 v8SetReturnValue(info, 60 v8SetReturnValue(info,
55 V8DOMWrapper::associateObjectWithWrapper( 61 V8DOMWrapper::associateObjectWithWrapper(
56 info.GetIsolate(), observer, &wrapperTypeInfo, wrapper)); 62 info.GetIsolate(), observer, &wrapperTypeInfo, wrapper));
57 } 63 }
58 64
59 } // namespace blink 65 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698