| 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/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/modules/v8/V8IDBObserverCallback.h" |
| 12 #include "bindings/modules/v8/V8IDBObserverInit.h" | 12 #include "bindings/modules/v8/V8IDBObserverInit.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 void V8IDBObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) | 16 void V8IDBObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) |
| 17 { | 17 { |
| 18 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::Constructio
nContext, "IDBObserver"); |
| 19 |
| 18 if (UNLIKELY(info.Length() < 1)) { | 20 if (UNLIKELY(info.Length() < 1)) { |
| 19 V8ThrowException::throwException(info.GetIsolate(), createMinimumArityTy
peErrorForConstructor(info.GetIsolate(), "IDBObserver", 1, info.Length())); | 21 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i
nfo.Length())); |
| 20 return; | 22 return; |
| 21 } | 23 } |
| 22 | 24 |
| 23 v8::Local<v8::Object> wrapper = info.Holder(); | 25 v8::Local<v8::Object> wrapper = info.Holder(); |
| 24 | 26 |
| 25 if (!info[0]->IsFunction()) { | 27 if (!info[0]->IsFunction()) { |
| 26 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f
ailedToConstruct("IDBObserver", "The callback provided as parameter 1 is not a f
unction.")); | 28 exceptionState.throwTypeError("The callback provided as parameter 1 is n
ot a function."); |
| 27 return; | 29 return; |
| 28 } | 30 } |
| 29 | 31 |
| 30 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()
) { | 32 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()
) { |
| 31 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f
ailedToConstruct("IDBObserver", "IDBObserverInit (parameter 2) is not an object.
")); | 33 exceptionState.throwTypeError("parameter 2 ('options') is not an object.
"); |
| 32 return; | 34 return; |
| 33 } | 35 } |
| 34 | 36 |
| 35 IDBObserverInit idbObserverInit; | 37 IDBObserverInit idbObserverInit; |
| 36 ExceptionState exceptionState(ExceptionState::ConstructionContext, "IDBObser
ver", info.Holder(), info.GetIsolate()); | |
| 37 V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit, excep
tionState); | 38 V8IDBObserverInit::toImpl(info.GetIsolate(), info[1], idbObserverInit, excep
tionState); |
| 38 if (exceptionState.hadException()) | 39 if (exceptionState.hadException()) |
| 39 return; | 40 return; |
| 40 | 41 |
| 41 IDBObserverCallback* callback = new V8IDBObserverCallback(v8::Local<v8::Func
tion>::Cast(info[0]), wrapper, ScriptState::current(info.GetIsolate())); | 42 IDBObserverCallback* callback = new V8IDBObserverCallback(v8::Local<v8::Func
tion>::Cast(info[0]), wrapper, ScriptState::current(info.GetIsolate())); |
| 42 IDBObserver* observer = IDBObserver::create(*callback, idbObserverInit); | 43 IDBObserver* observer = IDBObserver::create(*callback, idbObserverInit); |
| 43 if (exceptionState.hadException()) | 44 if (exceptionState.hadException()) |
| 44 return; | 45 return; |
| 45 DCHECK(observer); | 46 DCHECK(observer); |
| 46 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); | 47 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // namespace blink | 50 } // namespace blink |
| OLD | NEW |