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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserToken.cpp

Issue 2115923002: Improve numeric value handling in CSS Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: V2 Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/css/parser/CSSParserToken.h" 5 #include "core/css/parser/CSSParserToken.h"
6 6
7 #include "core/css/CSSMarkup.h" 7 #include "core/css/CSSMarkup.h"
8 #include "core/css/CSSPrimitiveValue.h" 8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/parser/CSSPropertyParser.h" 9 #include "core/css/parser/CSSPropertyParser.h"
10 #include "wtf/HashMap.h" 10 #include "wtf/HashMap.h"
(...skipping 24 matching lines...) Expand all
35 initValueFromStringView(value); 35 initValueFromStringView(value);
36 m_id = -1; 36 m_id = -1;
37 } 37 }
38 38
39 CSSParserToken::CSSParserToken(CSSParserTokenType type, double numericValue, Num ericValueType numericValueType, NumericSign sign) 39 CSSParserToken::CSSParserToken(CSSParserTokenType type, double numericValue, Num ericValueType numericValueType, NumericSign sign)
40 : m_type(type) 40 : m_type(type)
41 , m_blockType(NotBlock) 41 , m_blockType(NotBlock)
42 , m_numericValueType(numericValueType) 42 , m_numericValueType(numericValueType)
43 , m_numericSign(sign) 43 , m_numericSign(sign)
44 , m_unit(static_cast<unsigned>(CSSPrimitiveValue::UnitType::Number)) 44 , m_unit(static_cast<unsigned>(CSSPrimitiveValue::UnitType::Number))
45 , m_numericValue(numericValue)
46 { 45 {
47 ASSERT(type == NumberToken); 46 ASSERT(type == NumberToken);
47 m_numericValue = clampTo<double>(numericValue, -std::numeric_limits<float>:: max(), std::numeric_limits<float>::max());
48 } 48 }
49 49
50 CSSParserToken::CSSParserToken(CSSParserTokenType type, UChar32 start, UChar32 e nd) 50 CSSParserToken::CSSParserToken(CSSParserTokenType type, UChar32 start, UChar32 e nd)
51 : m_type(UnicodeRangeToken) 51 : m_type(UnicodeRangeToken)
52 , m_blockType(NotBlock) 52 , m_blockType(NotBlock)
53 { 53 {
54 ASSERT_UNUSED(type, type == UnicodeRangeToken); 54 ASSERT_UNUSED(type, type == UnicodeRangeToken);
55 m_unicodeRange.start = start; 55 m_unicodeRange.start = start;
56 m_unicodeRange.end = end; 56 m_unicodeRange.end = end;
57 } 57 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 case RightBraceToken: 281 case RightBraceToken:
282 return builder.append('}'); 282 return builder.append('}');
283 283
284 case EOFToken: 284 case EOFToken:
285 case CommentToken: 285 case CommentToken:
286 ASSERT_NOT_REACHED(); 286 ASSERT_NOT_REACHED();
287 return; 287 return;
288 } 288 }
289 } 289 }
290 290
291 bool CSSParserToken::isValidNumericValue(double value)
292 {
293 return value >= -std::numeric_limits<float>::max()
294 && value <= std::numeric_limits<float>::max();
295 }
296
297 bool CSSParserToken::isValidNumericValue() const
298 {
299 return isValidNumericValue(numericValue());
300 }
301
302 } // namespace blink 291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698