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

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

Issue 2459113002: [IDBObservers] Moving options from constructor to .observe call. (Closed)
Patch Set: added more exceptions, fixed tests Created 4 years, 1 month 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/core/v8/V8PrivateProperty.h" 11 #include "bindings/core/v8/V8PrivateProperty.h"
12 #include "bindings/modules/v8/IDBObserverCallback.h" 12 #include "bindings/modules/v8/IDBObserverCallback.h"
13 #include "bindings/modules/v8/V8IDBObserverInit.h"
14 13
15 namespace blink { 14 namespace blink {
16 15
17 void V8IDBObserver::constructorCustom( 16 void V8IDBObserver::constructorCustom(
18 const v8::FunctionCallbackInfo<v8::Value>& info) { 17 const v8::FunctionCallbackInfo<v8::Value>& info) {
19 ExceptionState exceptionState( 18 ExceptionState exceptionState(
20 info.GetIsolate(), ExceptionState::ConstructionContext, "IDBObserver"); 19 info.GetIsolate(), ExceptionState::ConstructionContext, "IDBObserver");
21 20
22 if (UNLIKELY(info.Length() < 1)) { 21 if (UNLIKELY(info.Length() < 1)) {
23 exceptionState.throwTypeError( 22 exceptionState.throwTypeError(
24 ExceptionMessages::notEnoughArguments(1, info.Length())); 23 ExceptionMessages::notEnoughArguments(1, info.Length()));
25 return; 24 return;
26 } 25 }
27 26
28 v8::Local<v8::Object> wrapper = info.Holder(); 27 v8::Local<v8::Object> wrapper = info.Holder();
29 28
30 if (!info[0]->IsFunction()) { 29 if (!info[0]->IsFunction()) {
31 exceptionState.throwTypeError( 30 exceptionState.throwTypeError(
32 "The callback provided as parameter 1 is not a function."); 31 "The callback provided as parameter 1 is not a function.");
33 return; 32 return;
34 } 33 }
35 34
36 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && 35 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) &&
37 !info[1]->IsObject()) { 36 !info[1]->IsObject()) {
38 exceptionState.throwTypeError("parameter 2 ('options') is not an object."); 37 exceptionState.throwTypeError("parameter 2 ('options') is not an object.");
39 return; 38 return;
40 } 39 }
41 40
42 IDBObserverInit idbObserverInit;
43 V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit,
44 exceptionState);
45 if (exceptionState.hadException()) 41 if (exceptionState.hadException())
46 return; 42 return;
47 43
48 ScriptState* scriptState = ScriptState::forReceiverObject(info); 44 ScriptState* scriptState = ScriptState::forReceiverObject(info);
49 v8::Local<v8::Function> v8Callback = v8::Local<v8::Function>::Cast(info[0]); 45 v8::Local<v8::Function> v8Callback = v8::Local<v8::Function>::Cast(info[0]);
50 IDBObserverCallback* callback = 46 IDBObserverCallback* callback =
51 IDBObserverCallback::create(scriptState, v8Callback); 47 IDBObserverCallback::create(scriptState, v8Callback);
52 IDBObserver* observer = IDBObserver::create(callback, idbObserverInit); 48 IDBObserver* observer = IDBObserver::create(callback);
53 if (exceptionState.hadException()) 49 if (exceptionState.hadException())
54 return; 50 return;
55 DCHECK(observer); 51 DCHECK(observer);
56 // TODO(bashi): Don't set private property (and remove this custom 52 // TODO(bashi): Don't set private property (and remove this custom
57 // constructor) when we can call setWrapperReference() correctly. 53 // constructor) when we can call setWrapperReference() correctly.
58 V8PrivateProperty::getIDBObserverCallback(info.GetIsolate()) 54 V8PrivateProperty::getIDBObserverCallback(info.GetIsolate())
59 .set(info.GetIsolate()->GetCurrentContext(), wrapper, v8Callback); 55 .set(info.GetIsolate()->GetCurrentContext(), wrapper, v8Callback);
60 v8SetReturnValue(info, 56 v8SetReturnValue(info,
61 V8DOMWrapper::associateObjectWithWrapper( 57 V8DOMWrapper::associateObjectWithWrapper(
62 info.GetIsolate(), observer, &wrapperTypeInfo, wrapper)); 58 info.GetIsolate(), observer, &wrapperTypeInfo, wrapper));
63 } 59 }
64 60
65 } // namespace blink 61 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698