Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/custom/V8IntersectionObserverCustom.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8IntersectionObserverCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8IntersectionObserverCustom.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ac21e2f41c158b71f3ed30ed968466df0f2173a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8IntersectionObserverCustom.cpp |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "bindings/core/v8/V8IntersectionObserver.h" |
| + |
| +#include "bindings/core/v8/ExceptionMessages.h" |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "bindings/core/v8/V8Binding.h" |
| +#include "bindings/core/v8/V8DOMWrapper.h" |
| +#include "bindings/core/v8/V8GCController.h" |
| +#include "bindings/core/v8/V8IntersectionObserverCallback.h" |
| +#include "bindings/core/v8/V8IntersectionObserverInit.h" |
| + |
| +namespace blink { |
| + |
| +void V8IntersectionObserver::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| +{ |
| + if (UNLIKELY(info.Length() < 1)) { |
| + V8ThrowException::throwException(createMinimumArityTypeErrorForMethod(info.GetIsolate(), "createIntersectionObserver", "Intersection", 1, info.Length()), info.GetIsolate()); |
| + return; |
| + } |
| + |
| + v8::Local<v8::Object> wrapper = info.Holder(); |
| + |
| + if (!info[0]->IsFunction()) { |
| + V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createIntersectionObserver", "Intersection", "The callback provided as parameter 1 is not a function.")); |
| + return; |
| + } |
| + |
| + if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject()) { |
| + V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("createIntersectionObserver", "Intersection", "IntersectionObserverInit (parameter 2) is not an object.")); |
| + return; |
| + } |
| + |
| + IntersectionObserverInit intersectionObserverInit; |
| + ExceptionState exceptionState(ExceptionState::ConstructionContext, "Intersection", info.Holder(), info.GetIsolate()); |
| + V8IntersectionObserverInit::toImpl(info.GetIsolate(), info[1], intersectionObserverInit, exceptionState); |
| + if (exceptionState.hadException()) { |
| + V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.message()); |
| + return; |
| + } |
| + |
| + IntersectionObserverCallback* callback = new V8IntersectionObserverCallback(v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIsolate())); |
| + IntersectionObserver* observer = IntersectionObserver::create(intersectionObserverInit, *callback, exceptionState); |
|
haraken
2015/12/22 01:13:29
I think you can just pass callback instead of *cal
esprehn
2015/12/22 07:50:32
*callback signifies that it's not null to the ::cr
szager1
2015/12/22 07:53:40
Previous comment from esprehn@ suggested this para
|
| + if (!observer || exceptionState.hadException()) { |
| + V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.message()); |
|
haraken
2015/12/22 01:13:29
Why do you need this GeneralError?
When writing c
szager1
2015/12/22 07:53:40
IntersectionObserver::create will return NULL and
|
| + return; |
| + } |
| + |
| + v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsolate(), observer, &wrapperTypeInfo, wrapper)); |
| +} |
| + |
| +} // namespace blink |