Chromium Code Reviews| 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/core/v8/V8IntersectionObserver.h" | 5 #include "bindings/core/v8/V8IntersectionObserver.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" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 } | 29 } |
| 30 | 30 |
| 31 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject() ) { | 31 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !info[1]->IsObject() ) { |
| 32 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f ailedToExecute("createIntersectionObserver", "Intersection", "IntersectionObserv erInit (parameter 2) is not an object.")); | 32 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f ailedToExecute("createIntersectionObserver", "Intersection", "IntersectionObserv erInit (parameter 2) is not an object.")); |
| 33 return; | 33 return; |
| 34 } | 34 } |
| 35 | 35 |
| 36 IntersectionObserverInit intersectionObserverInit; | 36 IntersectionObserverInit intersectionObserverInit; |
| 37 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Intersec tion", info.Holder(), info.GetIsolate()); | 37 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Intersec tion", info.Holder(), info.GetIsolate()); |
| 38 V8IntersectionObserverInit::toImpl(info.GetIsolate(), info[1], intersectionO bserverInit, exceptionState); | 38 V8IntersectionObserverInit::toImpl(info.GetIsolate(), info[1], intersectionO bserverInit, exceptionState); |
| 39 if (exceptionState.hadException()) { | 39 if (exceptionState.throwIfNeeded()) |
| 40 V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.me ssage()); | 40 return; |
| 41 | |
| 42 IntersectionObserverCallback* callback = new V8IntersectionObserverCallback( v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIs olate())); | |
| 43 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb serverInit, *callback, exceptionState); | |
| 44 if (exceptionState.throwIfNeeded()) | |
| 45 return; | |
| 46 if (!observer) { | |
|
haraken
2016/02/29 23:35:56
Can this be ASSERT(observer)? If observer is null,
szager1
2016/02/29 23:45:39
Done.
| |
| 47 V8ThrowException::throwGeneralError(info.GetIsolate(), "Unknown error wh ile constructing IntersectionObserver."); | |
| 41 return; | 48 return; |
| 42 } | 49 } |
| 43 | 50 |
| 44 IntersectionObserverCallback* callback = new V8IntersectionObserverCallback( v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIs olate())); | |
| 45 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb serverInit, *callback, exceptionState); | |
| 46 if (!observer || exceptionState.hadException()) { | |
| 47 V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.me ssage()); | |
| 48 return; | |
| 49 } | |
| 50 | |
| 51 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol ate(), observer, &wrapperTypeInfo, wrapper)); | 51 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol ate(), observer, &wrapperTypeInfo, wrapper)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void V8IntersectionObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappab le* scriptWrappable, const v8::Persistent<v8::Object>& wrapper) | 54 void V8IntersectionObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappab le* scriptWrappable, const v8::Persistent<v8::Object>& wrapper) |
| 55 { | 55 { |
| 56 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve r>(); | 56 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve r>(); |
| 57 for (auto& observation : observer->observations()) { | 57 for (auto& observation : observer->observations()) { |
| 58 Element* target = observation->target(); | 58 Element* target = observation->target(); |
| 59 if (!target) | 59 if (!target) |
| 60 continue; | 60 continue; |
| 61 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor GC(isolate, target))); | 61 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor GC(isolate, target))); |
| 62 isolate->SetReferenceFromGroup(id, wrapper); | 62 isolate->SetReferenceFromGroup(id, wrapper); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |