| 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.throwIfNeeded()) | 39 if (exceptionState.hadException()) |
| 40 return; | 40 return; |
| 41 | 41 |
| 42 IntersectionObserverCallback* callback = new V8IntersectionObserverCallback(
v8::Local<v8::Function>::Cast(info[0]), wrapper, ScriptState::current(info.GetIs
olate())); | 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); | 43 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb
serverInit, *callback, exceptionState); |
| 44 if (exceptionState.throwIfNeeded()) | 44 if (exceptionState.hadException()) |
| 45 return; | 45 return; |
| 46 ASSERT(observer); | 46 ASSERT(observer); |
| 47 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); | 47 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol
ate(), observer, &wrapperTypeInfo, wrapper)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void V8IntersectionObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappab
le* scriptWrappable, const v8::Persistent<v8::Object>& wrapper) | 50 void V8IntersectionObserver::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappab
le* scriptWrappable, const v8::Persistent<v8::Object>& wrapper) |
| 51 { | 51 { |
| 52 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve
r>(); | 52 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve
r>(); |
| 53 for (auto& observation : observer->observations()) { | 53 for (auto& observation : observer->observations()) { |
| 54 Element* target = observation->target(); | 54 Element* target = observation->target(); |
| 55 if (!target) | 55 if (!target) |
| 56 continue; | 56 continue; |
| 57 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor
GC(isolate, target))); | 57 v8::UniqueId id(reinterpret_cast<intptr_t>(V8GCController::opaqueRootFor
GC(isolate, target))); |
| 58 isolate->SetReferenceFromGroup(id, wrapper); | 58 isolate->SetReferenceFromGroup(id, wrapper); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |