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

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp

Issue 2088963002: IntersectionObserver constructor: fail on invalid rootMargin syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/root-margin-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/dom/IntersectionObserver.h" 5 #include "core/dom/IntersectionObserver.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/css/parser/CSSParserTokenRange.h" 8 #include "core/css/parser/CSSParserTokenRange.h"
9 #include "core/css/parser/CSSTokenizer.h" 9 #include "core/css/parser/CSSTokenizer.h"
10 #include "core/dom/Element.h" 10 #include "core/dom/Element.h"
(...skipping 21 matching lines...) Expand all
32 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg in, ExceptionState& exceptionState) 32 static void parseRootMargin(String rootMarginParameter, Vector<Length>& rootMarg in, ExceptionState& exceptionState)
33 { 33 {
34 // TODO(szager): Make sure this exact syntax and behavior is spec-ed somewhe re. 34 // TODO(szager): Make sure this exact syntax and behavior is spec-ed somewhe re.
35 35
36 // The root margin argument accepts syntax similar to that for CSS margin: 36 // The root margin argument accepts syntax similar to that for CSS margin:
37 // 37 //
38 // "1px" = top/right/bottom/left 38 // "1px" = top/right/bottom/left
39 // "1px 2px" = top/bottom left/right 39 // "1px 2px" = top/bottom left/right
40 // "1px 2px 3px" = top left/right bottom 40 // "1px 2px 3px" = top left/right bottom
41 // "1px 2px 3px 4px" = top left right bottom 41 // "1px 2px 3px 4px" = top left right bottom
42 //
43 // Any extra stuff after the first four tokens is ignored.
44 CSSTokenizer::Scope tokenizerScope(rootMarginParameter); 42 CSSTokenizer::Scope tokenizerScope(rootMarginParameter);
45 CSSParserTokenRange tokenRange = tokenizerScope.tokenRange(); 43 CSSParserTokenRange tokenRange = tokenizerScope.tokenRange();
46 while (rootMargin.size() < 4 && tokenRange.peek().type() != EOFToken && !exc eptionState.hadException()) { 44 while (rootMargin.size() < 5 && tokenRange.peek().type() != EOFToken && !exc eptionState.hadException()) {
45 if (rootMargin.size() == 4) {
eae 2016/06/22 10:51:04 According the the comment above four tokens should
szager1 2016/06/22 15:11:45 At this point in the code, there are already four
eae 2016/06/22 16:54:40 The while conditions check that rootMargin.size()
46 exceptionState.throwDOMException(SyntaxError, "Extra text found at t he end of rootMargin.");
47 break;
48 }
47 const CSSParserToken& token = tokenRange.consumeIncludingWhitespace(); 49 const CSSParserToken& token = tokenRange.consumeIncludingWhitespace();
48 switch (token.type()) { 50 switch (token.type()) {
49 case PercentageToken: 51 case PercentageToken:
50 rootMargin.append(Length(token.numericValue(), Percent)); 52 rootMargin.append(Length(token.numericValue(), Percent));
51 break; 53 break;
52 case DimensionToken: 54 case DimensionToken:
53 switch (token.unitType()) { 55 switch (token.unitType()) {
54 case CSSPrimitiveValue::UnitType::Pixels: 56 case CSSPrimitiveValue::UnitType::Pixels:
55 rootMargin.append(Length(static_cast<int>(floor(token.numericVal ue())), Fixed)); 57 rootMargin.append(Length(static_cast<int>(floor(token.numericVal ue())), Fixed));
56 break; 58 break;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 354
353 DEFINE_TRACE(IntersectionObserver) 355 DEFINE_TRACE(IntersectionObserver)
354 { 356 {
355 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this); 357 visitor->template registerWeakMembers<IntersectionObserver, &IntersectionObs erver::clearWeakMembers>(this);
356 visitor->trace(m_callback); 358 visitor->trace(m_callback);
357 visitor->trace(m_observations); 359 visitor->trace(m_observations);
358 visitor->trace(m_entries); 360 visitor->trace(m_entries);
359 } 361 }
360 362
361 } // namespace blink 363 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/intersection-observer/root-margin-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698