OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "config.h" |
| 6 #include "bindings/core/v8/V8IntersectionObserver.h" |
| 7 |
| 8 #include "bindings/core/v8/ExceptionMessages.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/V8Binding.h" |
| 11 #include "bindings/core/v8/V8DOMWrapper.h" |
| 12 #include "bindings/core/v8/V8GCController.h" |
| 13 #include "bindings/core/v8/V8IntersectionObserverCallback.h" |
| 14 #include "bindings/core/v8/V8IntersectionObserverInit.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 void V8IntersectionObserver::constructorCustom(const v8::FunctionCallbackInfo<v8
::Value>& info) |
| 19 { |
| 20 if (UNLIKELY(info.Length() < 1)) { |
| 21 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod(in
fo.GetIsolate(), "createIntersectionObserver", "Intersection", 1, info.Length())
, info.GetIsolate()); |
| 22 return; |
| 23 } |
| 24 |
| 25 v8::Local<v8::Object> wrapper = info.Holder(); |
| 26 |
| 27 if (!info[0]->IsFunction()) { |
| 28 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f
ailedToExecute("createIntersectionObserver", "Intersection", "The callback provi
ded as parameter 1 is not a function.")); |
| 29 return; |
| 30 } |
| 31 |
| 32 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()
) { |
| 33 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f
ailedToExecute("createIntersectionObserver", "Intersection", "IntersectionObserv
erInit (parameter 2) is not an object.")); |
| 34 return; |
| 35 } |
| 36 |
| 37 IntersectionObserverInit intersectionObserverInit; |
| 38 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Intersec
tion", info.Holder(), info.GetIsolate()); |
| 39 V8IntersectionObserverInit::toImpl(info.GetIsolate(), info[1], intersectionO
bserverInit, exceptionState); |
| 40 if (exceptionState.hadException()) { |
| 41 V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.me
ssage()); |
| 42 return; |
| 43 } |
| 44 |
| 45 IntersectionObserverCallback* callback = new V8IntersectionObserverCallback(
v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIs
olate())); |
| 46 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb
serverInit, *callback, exceptionState); |
| 47 if (!observer || exceptionState.hadException()) { |
| 48 V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.me
ssage()); |
| 49 return; |
| 50 } |
| 51 |
| 52 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); |
| 53 } |
| 54 |
| 55 } // namespace blink |
OLD | NEW |