Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8IntersectionObserverCustom.cpp

Issue 1740923004: IntersectionObserver: make exceptions match spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: ASSERT observer constructor succeeded if no exception was thrown Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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());
41 return; 40 return;
42 }
43 41
44 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()));
45 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb serverInit, *callback, exceptionState); 43 IntersectionObserver* observer = IntersectionObserver::create(intersectionOb serverInit, *callback, exceptionState);
46 if (!observer || exceptionState.hadException()) { 44 if (exceptionState.throwIfNeeded())
47 V8ThrowException::throwGeneralError(info.GetIsolate(), exceptionState.me ssage());
48 return; 45 return;
49 } 46 ASSERT(observer);
50
51 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol ate(), observer, &wrapperTypeInfo, wrapper)); 47 v8SetReturnValue(info, V8DOMWrapper::associateObjectWithWrapper(info.GetIsol ate(), observer, &wrapperTypeInfo, wrapper));
52 } 48 }
53 49
54 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)
55 { 51 {
56 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve r>(); 52 IntersectionObserver* observer = scriptWrappable->toImpl<IntersectionObserve r>();
57 for (auto& observation : observer->observations()) { 53 for (auto& observation : observer->observations()) {
58 Element* target = observation->target(); 54 Element* target = observation->target();
59 if (!target) 55 if (!target)
60 continue; 56 continue;
61 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)));
62 isolate->SetReferenceFromGroup(id, wrapper); 58 isolate->SetReferenceFromGroup(id, wrapper);
63 } 59 }
64 } 60 }
65 61
66 } // namespace blink 62 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698