Commit 26f38f3f authored by Bugs Nash's avatar Bugs Nash Committed by Commit Bot

Added null safety to CSSParserContext args in CSSProperty utils files

This patch
- Changed CSSParserContext argument from * to & for null safety and
  readability in the remaining utils files in core/css/properties
- Changed the CSSPropertyParserHelpers::ConsumeCommaSeparatedList
  parameter pack argument to a universal reference with perfect
  forwarding so that reference arguments can be passed through it.

Bug: 668012
Change-Id: I5e607c9a1f8e26d7848092468d666f9879711941
Reviewed-on: https://chromium-review.googlesource.com/590910Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarRenée Wright <rjwright@chromium.org>
Commit-Queue: Bugs Nash <bugsnash@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490691}
parent b1758611
......@@ -175,10 +175,10 @@ CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) {
template <typename Func, typename... Args>
CSSValueList* ConsumeCommaSeparatedList(Func callback,
CSSParserTokenRange& range,
Args... args) {
Args&&... args) {
CSSValueList* list = CSSValueList::CreateCommaSeparated();
do {
CSSValue* value = callback(range, args...);
CSSValue* value = callback(range, std::forward<Args>(args)...);
if (!value)
return nullptr;
list->Append(*value);
......
......@@ -18,7 +18,7 @@ const CSSValue* CSSPropertyAPIAnimationName::parseSingleValue(
const CSSParserLocalContext& local_context) {
// Allow quoted name if this is an alias property.
return CSSPropertyParserHelpers::ConsumeCommaSeparatedList(
CSSPropertyAnimationNameUtils::ConsumeAnimationName, range, &context,
CSSPropertyAnimationNameUtils::ConsumeAnimationName, range, context,
local_context.UseAliasParsing());
}
......
......@@ -12,7 +12,7 @@ const CSSValue* CSSPropertyAPIWebkitBorderImage::parseSingleValue(
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext&) {
return CSSPropertyBorderImageUtils::ConsumeWebkitBorderImage(range, &context);
return CSSPropertyBorderImageUtils::ConsumeWebkitBorderImage(range, context);
}
} // namespace blink
......@@ -15,7 +15,7 @@ namespace blink {
namespace {
static CSSValue* ConsumeReflect(CSSParserTokenRange& range,
const CSSParserContext* context) {
const CSSParserContext& context) {
CSSIdentifierValue* direction = CSSPropertyParserHelpers::ConsumeIdent<
CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>(range);
if (!direction)
......@@ -26,7 +26,7 @@ static CSSValue* ConsumeReflect(CSSParserTokenRange& range,
offset = CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kPixels);
} else {
offset = ConsumeLengthOrPercent(
range, context->Mode(), kValueRangeAll,
range, context.Mode(), kValueRangeAll,
CSSPropertyParserHelpers::UnitlessQuirk::kForbid);
if (!offset)
return nullptr;
......@@ -48,7 +48,7 @@ const CSSValue* CSSPropertyAPIWebkitBoxReflect::parseSingleValue(
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext&) {
return ConsumeReflect(range, &context);
return ConsumeReflect(range, context);
}
} // namespace blink
......@@ -11,14 +11,14 @@ namespace blink {
CSSValue* CSSPropertyAnimationNameUtils::ConsumeAnimationName(
CSSParserTokenRange& range,
const CSSParserContext* context,
const CSSParserContext& context,
bool allow_quoted_name) {
if (range.Peek().Id() == CSSValueNone)
return CSSPropertyParserHelpers::ConsumeIdent(range);
if (allow_quoted_name && range.Peek().GetType() == kStringToken) {
// Legacy support for strings in prefixed animations.
context->Count(WebFeature::kQuotedAnimationName);
context.Count(WebFeature::kQuotedAnimationName);
const CSSParserToken& token = range.ConsumeIncludingWhitespace();
if (EqualIgnoringASCIICase(token.Value(), "none"))
......
......@@ -18,7 +18,7 @@ class CSSPropertyAnimationNameUtils {
public:
static CSSValue* ConsumeAnimationName(CSSParserTokenRange&,
const CSSParserContext*,
const CSSParserContext&,
bool allow_quoted_name);
};
......
......@@ -27,7 +27,7 @@ static CSSIdentifierValue* ConsumeBorderImageRepeatKeyword(
CSSValue* CSSPropertyBorderImageUtils::ConsumeWebkitBorderImage(
CSSParserTokenRange& range,
const CSSParserContext* context) {
const CSSParserContext& context) {
CSSValue* source = nullptr;
CSSValue* slice = nullptr;
CSSValue* width = nullptr;
......@@ -41,7 +41,7 @@ CSSValue* CSSPropertyBorderImageUtils::ConsumeWebkitBorderImage(
bool CSSPropertyBorderImageUtils::ConsumeBorderImageComponents(
CSSParserTokenRange& range,
const CSSParserContext* context,
const CSSParserContext& context,
CSSValue*& source,
CSSValue*& slice,
CSSValue*& width,
......@@ -50,7 +50,7 @@ bool CSSPropertyBorderImageUtils::ConsumeBorderImageComponents(
bool default_fill) {
do {
if (!source) {
source = CSSPropertyParserHelpers::ConsumeImageOrNone(range, context);
source = CSSPropertyParserHelpers::ConsumeImageOrNone(range, &context);
if (source)
continue;
}
......
......@@ -18,9 +18,9 @@ class CSSPropertyBorderImageUtils {
public:
static CSSValue* ConsumeWebkitBorderImage(CSSParserTokenRange&,
const CSSParserContext*);
const CSSParserContext&);
static bool ConsumeBorderImageComponents(CSSParserTokenRange&,
const CSSParserContext*,
const CSSParserContext&,
CSSValue*& source,
CSSValue*& slice,
CSSValue*& width,
......
......@@ -33,18 +33,18 @@ bool ConsumeNumbers(CSSParserTokenRange& args,
}
bool ConsumePerspective(CSSParserTokenRange& args,
const CSSParserContext* context,
const CSSParserContext& context,
CSSFunctionValue*& transform_value,
bool use_legacy_parsing) {
CSSPrimitiveValue* parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeNonNegative);
args, context.Mode(), kValueRangeNonNegative);
if (!parsed_value && use_legacy_parsing) {
double perspective;
if (!CSSPropertyParserHelpers::ConsumeNumberRaw(args, perspective) ||
perspective < 0) {
return false;
}
context->Count(WebFeature::kUnitlessPerspectiveInTransformProperty);
context.Count(WebFeature::kUnitlessPerspectiveInTransformProperty);
parsed_value = CSSPrimitiveValue::Create(
perspective, CSSPrimitiveValue::UnitType::kPixels);
}
......@@ -77,7 +77,7 @@ bool ConsumeTranslate3d(CSSParserTokenRange& args,
}
CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
const CSSParserContext* context,
const CSSParserContext& context,
bool use_legacy_parsing) {
CSSValueID function_id = range.Peek().FunctionId();
if (function_id == CSSValueInvalid)
......@@ -96,14 +96,14 @@ CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
case CSSValueSkewY:
case CSSValueSkew:
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
args, context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueSkew &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
args, context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
}
......@@ -135,21 +135,21 @@ CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
case CSSValueTranslateY:
case CSSValueTranslate:
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
args, context.Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueTranslate &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
args, context.Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
}
break;
case CSSValueTranslateZ:
parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeAll);
args, context.Mode(), kValueRangeAll);
break;
case CSSValueMatrix:
case CSSValueMatrix3d:
......@@ -168,12 +168,12 @@ CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
return nullptr;
}
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
args, context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
break;
case CSSValueTranslate3d:
if (!ConsumeTranslate3d(args, context->Mode(), transform_value))
if (!ConsumeTranslate3d(args, context.Mode(), transform_value))
return nullptr;
break;
default:
......@@ -198,7 +198,7 @@ CSSValue* CSSPropertyTransformUtils::ConsumeTransformList(
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
do {
CSSValue* parsed_transform_value =
ConsumeTransformValue(range, &context, local_context.UseAliasParsing());
ConsumeTransformValue(range, context, local_context.UseAliasParsing());
if (!parsed_transform_value)
return nullptr;
list->Append(*parsed_transform_value);
......
......@@ -42,7 +42,7 @@ CSSValue* ConsumeAnimationValue(CSSPropertyID property,
ConsumeAnimationIterationCount(range);
case CSSPropertyAnimationName:
return CSSPropertyAnimationNameUtils::ConsumeAnimationName(
range, &context, use_legacy_parsing);
range, context, use_legacy_parsing);
case CSSPropertyAnimationPlayState:
return CSSPropertyParserHelpers::ConsumeIdent<CSSValueRunning,
CSSValuePaused>(range);
......
......@@ -24,7 +24,7 @@ bool CSSShorthandPropertyAPIBorderImage::parseShorthand(
CSSValue* repeat = nullptr;
if (!CSSPropertyBorderImageUtils::ConsumeBorderImageComponents(
range, &context, source, slice, width, outset, repeat, false)) {
range, context, source, slice, width, outset, repeat, false)) {
return false;
}
......
......@@ -24,7 +24,7 @@ bool CSSShorthandPropertyAPIWebkitMaskBoxImage::parseShorthand(
CSSValue* repeat = nullptr;
if (!CSSPropertyBorderImageUtils::ConsumeBorderImageComponents(
range, &context, source, slice, width, outset, repeat, true)) {
range, context, source, slice, width, outset, repeat, true)) {
return false;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment