Commit f9e82417 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Throw SyntaxError on parsing invalid cssText.

Currently we return null when calling CSSStyleValue.parse with an
invalid cssText. The spec says to throw a SyntaxError:

https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-parse

Bug: 775806
Change-Id: Iab99af48ce162fa1810ac678e63475e1660d9d95
Reviewed-on: https://chromium-review.googlesource.com/743082Reviewed-by: default avatarBugs Nash <bugsnash@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512438}
parent 3ed279d5
...@@ -2,7 +2,7 @@ This is a testharness.js-based test. ...@@ -2,7 +2,7 @@ This is a testharness.js-based test.
PASS Calling CSSStyleValue.parse with an empty string throws a TypeError PASS Calling CSSStyleValue.parse with an empty string throws a TypeError
PASS Calling CSSStyleValue.parse with an unsupported CSS property throws a TypeError PASS Calling CSSStyleValue.parse with an unsupported CSS property throws a TypeError
PASS Calling CSSStyleValue.parse with a CSS shorthand throws a TypeError PASS Calling CSSStyleValue.parse with a CSS shorthand throws a TypeError
FAIL Calling CSSStyleValue.parse with an invalid cssText for the given property throws a SyntaxError assert_throws: function "() => CSSStyleValue[parseMethod]('width', '10deg')" did not throw PASS Calling CSSStyleValue.parse with an invalid cssText for the given property throws a SyntaxError
PASS Calling CSSStyleValue.parse with a valid cssText for the given property returns a valid CSSStyleValue PASS Calling CSSStyleValue.parse with a valid cssText for the given property returns a valid CSSStyleValue
PASS Calling CSSStyleValue.parse with a mixed case cssText returns a valid CSSStyleValue PASS Calling CSSStyleValue.parse with a mixed case cssText returns a valid CSSStyleValue
FAIL Calling CSSStyleValue.parse with a custom property returns a valid CSSStyleValue Failed to execute 'parse' on 'CSSStyleValue': Invalid property name FAIL Calling CSSStyleValue.parse with a custom property returns a valid CSSStyleValue Failed to execute 'parse' on 'CSSStyleValue': Invalid property name
......
...@@ -36,8 +36,13 @@ ScriptValue CSSStyleValue::parse(ScriptState* script_state, ...@@ -36,8 +36,13 @@ ScriptValue CSSStyleValue::parse(ScriptState* script_state,
const CSSValue* css_value = const CSSValue* css_value =
CSSParser::ParseSingleValue(property_id, value, StrictCSSParserContext()); CSSParser::ParseSingleValue(property_id, value, StrictCSSParserContext());
if (!css_value) if (!css_value) {
exception_state.ThrowDOMException(
kSyntaxError, "The value provided ('" + value +
"') could not be parsed as a '" + property_name +
"'.");
return ScriptValue::CreateNull(script_state); return ScriptValue::CreateNull(script_state);
}
CSSStyleValueVector style_value_vector = CSSStyleValueVector style_value_vector =
StyleValueFactory::CssValueToStyleValueVector(property_id, *css_value); StyleValueFactory::CssValueToStyleValueVector(property_id, *css_value);
......
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