Bug 1286321: always ignore language attribute when processing script element if type attribute is defined; r?bz draft
authorDecky Coss <coss@cosstropolis.com>
Wed, 13 Jul 2016 12:10:13 -0400
changeset 387781 9296bc320ccac114f4a418420ed528a54e491554
parent 387298 412755b088952351ae0bb40384ec409367077f38
child 525454 cfb35b6fde92397d73284c3fa34eadf799101f6f
push id23075
push usercoss@cosstropolis.com
push dateThu, 14 Jul 2016 21:16:43 +0000
reviewersbz
bugs1286321
milestone50.0a1
Bug 1286321: always ignore language attribute when processing script element if type attribute is defined; r?bz MozReview-Commit-ID: AQV9mkYzLL2
dom/base/nsIScriptElement.h
dom/base/nsScriptLoader.cpp
dom/html/HTMLScriptElement.cpp
dom/html/HTMLScriptElement.h
dom/svg/SVGScriptElement.cpp
dom/svg/SVGScriptElement.h
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/script-language-type.html.ini
--- a/dom/base/nsIScriptElement.h
+++ b/dom/base/nsIScriptElement.h
@@ -46,29 +46,30 @@ public:
                      // behave like script-created scripts.
       mCreatorParser(nullptr)
   {
   }
 
   /**
    * Content type identifying the scripting language. Can be empty, in
    * which case javascript will be assumed.
+   * Return false if type attribute is not found.
    */
-  virtual void GetScriptType(nsAString& type) = 0;
-    
+  virtual bool GetScriptType(nsAString& type) = 0;
+
   /**
    * Location of script source text. Can return null, in which case
    * this is assumed to be an inline script element.
    */
   nsIURI* GetScriptURI()
   {
     NS_PRECONDITION(mFrozen, "Not ready for this call yet!");
     return mUri;
   }
-  
+
   /**
    * Script source text for inline script elements.
    */
   virtual void GetScriptText(nsAString& text) = 0;
 
   virtual void GetScriptCharset(nsAString& charset) = 0;
 
   /**
@@ -88,17 +89,17 @@ public:
   }
 
   /**
    * Is the script async. Currently only supported by HTML scripts.
    */
   bool GetScriptAsync()
   {
     NS_PRECONDITION(mFrozen, "Not ready for this call yet!");
-    return mAsync;  
+    return mAsync;
   }
 
   /**
    * Is the script an external script?
    */
   bool GetScriptExternal()
   {
     NS_PRECONDITION(mFrozen, "Not ready for this call yet!");
@@ -193,17 +194,17 @@ public:
    */
   void EndEvaluating()
   {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
     if (parser) {
       parser->EndEvaluatingParserInsertedScript();
     }
   }
-  
+
   /**
    * Retrieves a pointer to the creator parser if this has one or null if not
    */
   already_AddRefed<nsIParser> GetCreatorParser()
   {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
     return parser.forget();
   }
@@ -259,69 +260,69 @@ protected:
    *         loaded
    */
   virtual bool MaybeProcessScript() = 0;
 
   /**
    * The start line number of the script.
    */
   uint32_t mLineNumber;
-  
+
   /**
    * The "already started" flag per HTML5.
    */
   bool mAlreadyStarted;
-  
+
   /**
    * The script didn't have an end tag.
    */
   bool mMalformed;
-  
+
   /**
    * False if parser-inserted but the parser hasn't triggered running yet.
    */
   bool mDoneAddingChildren;
 
   /**
    * If true, the .async property returns true instead of reflecting the
    * content attribute.
    */
   bool mForceAsync;
 
   /**
    * Whether src, defer and async are frozen.
    */
   bool mFrozen;
-  
+
   /**
    * The effective deferredness.
    */
   bool mDefer;
-  
+
   /**
    * The effective asyncness.
    */
   bool mAsync;
-  
+
   /**
    * The effective externalness. A script can be external with mUri being null
    * if the src attribute contained an invalid URL string.
    */
   bool mExternal;
 
   /**
    * Whether this element was parser-created.
    */
   mozilla::dom::FromParser mParserCreated;
 
   /**
    * The effective src (or null if no src).
    */
   nsCOMPtr<nsIURI> mUri;
-  
+
   /**
    * The creator parser of a non-defer, non-async parser-inserted script.
    */
   nsWeakPtr mCreatorParser;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptElement, NS_ISCRIPTELEMENT_IID)
 
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -1272,26 +1272,27 @@ nsScriptLoader::ProcessScriptElement(nsI
     return false;
   }
 
   JSVersion version = JSVERSION_DEFAULT;
 
   // Check the type attribute to determine language and version.
   // If type exists, it trumps the deprecated 'language='
   nsAutoString type;
-  aElement->GetScriptType(type);
+  bool hasType = aElement->GetScriptType(type);
+
   nsScriptKind scriptKind = nsScriptKind::Classic;
   if (!type.IsEmpty()) {
     // Support type="module" only for chrome documents.
     if (nsContentUtils::IsChromeDoc(mDocument) && type.LowerCaseEqualsASCII("module")) {
       scriptKind = nsScriptKind::Module;
     } else {
       NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
     }
-  } else {
+  } else if (!hasType) {
     // no 'type=' element
     // "language" is a deprecated attribute of HTML, so we check it only for
     // HTML script elements.
     if (scriptContent->IsHTMLElement()) {
       nsAutoString language;
       scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
       if (!language.IsEmpty()) {
         if (!nsContentUtils::IsJavaScriptLanguage(language)) {
--- a/dom/html/HTMLScriptElement.cpp
+++ b/dom/html/HTMLScriptElement.cpp
@@ -239,20 +239,20 @@ HTMLScriptElement::SetInnerHTML(const ns
                                 ErrorResult& aError)
 {
   aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
 }
 
 // variation of this code in nsSVGScriptElement - check if changes
 // need to be transfered when modifying
 
-void
+bool
 HTMLScriptElement::GetScriptType(nsAString& type)
 {
-  GetType(type);
+  return GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
 }
 
 void
 HTMLScriptElement::GetScriptText(nsAString& text)
 {
   GetText(text);
 }
 
--- a/dom/html/HTMLScriptElement.h
+++ b/dom/html/HTMLScriptElement.h
@@ -33,17 +33,17 @@ public:
   using nsGenericHTMLElement::SetInnerHTML;
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             mozilla::ErrorResult& aError) override;
 
   // nsIDOMHTMLScriptElement
   NS_DECL_NSIDOMHTMLSCRIPTELEMENT
 
   // nsIScriptElement
-  virtual void GetScriptType(nsAString& type) override;
+  virtual bool GetScriptType(nsAString& type) override;
   virtual void GetScriptText(nsAString& text) override;
   virtual void GetScriptCharset(nsAString& charset) override;
   virtual void FreezeUriAsyncDefer() override;
   virtual CORSMode GetCORSMode() const override;
 
   // nsIContent
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
--- a/dom/svg/SVGScriptElement.cpp
+++ b/dom/svg/SVGScriptElement.cpp
@@ -76,17 +76,17 @@ SVGScriptElement::Clone(mozilla::dom::No
 
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
 void
 SVGScriptElement::GetType(nsAString & aType)
 {
-  GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
+  GetScriptType(aType);
 }
 
 void
 SVGScriptElement::SetType(const nsAString & aType, ErrorResult& rv)
 {
   rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
 }
 
@@ -110,20 +110,20 @@ already_AddRefed<SVGAnimatedString>
 SVGScriptElement::Href()
 {
   return mStringAttributes[HREF].ToDOMAnimatedString(this);
 }
 
 //----------------------------------------------------------------------
 // nsIScriptElement methods
 
-void
+bool
 SVGScriptElement::GetScriptType(nsAString& type)
 {
-  GetType(type);
+  return GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
 }
 
 void
 SVGScriptElement::GetScriptText(nsAString& text)
 {
   nsContentUtils::GetNodeTextContent(this, false, text);
 }
 
@@ -225,9 +225,8 @@ SVGScriptElement::ParseAttribute(int32_t
 CORSMode
 SVGScriptElement::GetCORSMode() const
 {
   return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
 }
 
 } // namespace dom
 } // namespace mozilla
-
--- a/dom/svg/SVGScriptElement.h
+++ b/dom/svg/SVGScriptElement.h
@@ -36,17 +36,17 @@ protected:
   virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
 
 public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIScriptElement
-  virtual void GetScriptType(nsAString& type) override;
+  virtual bool GetScriptType(nsAString& type) override;
   virtual void GetScriptText(nsAString& text) override;
   virtual void GetScriptCharset(nsAString& charset) override;
   virtual void FreezeUriAsyncDefer() override;
   virtual CORSMode GetCORSMode() const override;
 
   // nsScriptElement
   virtual bool HasScriptContent() override;
 
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/script-language-type.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[script-language-type.html]
-  type: testharness
-  [A script with empty type should run]
-    expected: FAIL
-