Bug 1339690 - Part 8: Produce an appropriate warning highlighting the invalid property value.
MozReview-Commit-ID: 1KoFMxOo78L
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -19,16 +19,17 @@
#include "mozilla/dom/KeyframeEffectReadOnly.h" // For PropertyValuesPair etc.
#include "jsapi.h" // For ForOfIterator etc.
#include "nsClassHashtable.h"
#include "nsContentUtils.h" // For GetContextForContent
#include "nsCSSParser.h"
#include "nsCSSPropertyIDSet.h"
#include "nsCSSProps.h"
#include "nsCSSPseudoElements.h" // For CSSPseudoElementType
+#include "nsIScriptError.h"
#include "nsStyleContext.h"
#include "nsTArray.h"
#include <algorithm> // For std::stable_sort
namespace mozilla {
// ------------------------------------------------------------------
//
@@ -840,16 +841,33 @@ static bool
AppendValueAsString(JSContext* aCx,
nsTArray<nsString>& aValues,
JS::Handle<JS::Value> aValue)
{
return ConvertJSValueToString(aCx, aValue, dom::eStringify, dom::eStringify,
*aValues.AppendElement());
}
+static void
+ReportInvalidPropertyValueToConsole(nsCSSPropertyID aProperty,
+ const nsAString& aInvalidPropertyValue,
+ nsIDocument* aDoc)
+{
+ const nsString& invalidValue = PromiseFlatString(aInvalidPropertyValue);
+ const NS_ConvertASCIItoUTF16 propertyName(
+ nsCSSProps::GetStringValue(aProperty));
+ const char16_t* params[] = { invalidValue.get(), propertyName.get() };
+ nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+ NS_LITERAL_CSTRING("Animation"),
+ aDoc,
+ nsContentUtils::eDOM_PROPERTIES,
+ "InvalidKeyframePropertyValue",
+ params, ArrayLength(params));
+}
+
/**
* Construct a PropertyValuePair parsing the given string into a suitable
* nsCSSValue object.
*
* @param aProperty The CSS property.
* @param aStringValue The property value to parse.
* @param aParser The CSS parser object to use.
* @param aDocument The document to use when parsing.
@@ -864,30 +882,33 @@ MakePropertyValuePair(nsCSSPropertyID aP
Maybe<PropertyValuePair> result;
if (aDocument->GetStyleBackendType() == StyleBackendType::Servo) {
RefPtr<RawServoDeclarationBlock> servoDeclarationBlock =
KeyframeUtils::ParseProperty(aProperty, aStringValue, aDocument);
if (servoDeclarationBlock) {
result.emplace(aProperty, Move(servoDeclarationBlock));
+ } else {
+ ReportInvalidPropertyValueToConsole(aProperty, aStringValue, aDocument);
}
return result;
}
nsCSSValue value;
if (!nsCSSProps::IsShorthand(aProperty)) {
aParser.ParseLonghandProperty(aProperty,
aStringValue,
aDocument->GetDocumentURI(),
aDocument->GetDocumentURI(),
aDocument->NodePrincipal(),
value);
if (value.GetUnit() == eCSSUnit_Null) {
// Invalid property value, so return Nothing.
+ ReportInvalidPropertyValueToConsole(aProperty, aStringValue, aDocument);
return result;
}
}
if (value.GetUnit() == eCSSUnit_Null) {
// If we have a shorthand, store the string value as a token stream.
nsCSSValueTokenStream* tokenStream = new nsCSSValueTokenStream;
tokenStream->mTokenStream = aStringValue;
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -344,8 +344,10 @@ ScriptSourceEmpty=‘%S’ attribute of <script> element is empty.
# LOCALIZATION NOTE: Do not translate "<script>".
ScriptSourceInvalidUri=‘%S’ attribute of <script> element is not a valid URI: “%S”
# LOCALIZATION NOTE: Do not translate "<script>".
ScriptSourceLoadFailed=Loading failed for the <script> with source “%S”.
# LOCALIZATION NOTE: Do not translate "<script>".
ScriptSourceMalformed=<script> source URI is malformed: “%S”.
# LOCALIZATION NOTE: Do not translate "<script>".
ScriptSourceNotAllowed=<script> source URI is not allowed in this document: “%S”.
+# LOCALIZATION NOTE: %1$S is the invalid property value and %2$S is the property name.
+InvalidKeyframePropertyValue=Keyframe property value “%1$S” is invalid according to the syntax for “%2$S”.