Bug 1339690 - Part 8: Produce an appropriate warning highlighting the invalid property value. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 14 Jun 2017 14:18:25 +0800
changeset 594711 6f60f44816917bc7fcaa2a4e3a0fc822132ebf7f
parent 594710 c2c385fbee2efd575b216bdc266389d2d2a9b271
child 633497 432a374394a8263d7716504f3a2618b9d94e7d73
push id64112
push userbmo:boris.chiou@gmail.com
push dateThu, 15 Jun 2017 10:38:49 +0000
bugs1339690
milestone56.0a1
Bug 1339690 - Part 8: Produce an appropriate warning highlighting the invalid property value. MozReview-Commit-ID: 1KoFMxOo78L
dom/animation/KeyframeUtils.cpp
dom/locales/en-US/chrome/dom/dom.properties
--- 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”.