Bug 1263116 - Stop throwing for DOMTokenList's.contains() when using empty string or ASCII whitespace, r=baku
authorBen Tian <btian@mozilla.com>
Thu, 05 May 2016 18:07:22 +0800
changeset 335336 f33893ecd47c56e5e24c34314f7776d6122c4d17
parent 335335 567a13dc5e5117ec8561dcdafc511e6ea04c2e86
child 335337 49dab7b4a276d14dacf73cd5b1fb12716fa741a2
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1263116
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1263116 - Stop throwing for DOMTokenList's.contains() when using empty string or ASCII whitespace, r=baku
dom/base/nsDOMTokenList.cpp
dom/base/nsDOMTokenList.h
dom/base/test/test_classList.html
dom/webidl/DOMTokenList.webidl
layout/base/nsDisplayList.cpp
testing/web-platform/tests/dom/nodes/Element-classlist.html
--- a/dom/base/nsDOMTokenList.cpp
+++ b/dom/base/nsDOMTokenList.cpp
@@ -114,23 +114,18 @@ nsDOMTokenList::CheckTokens(const nsTArr
       return rv;
     }
   }
 
   return NS_OK;
 }
 
 bool
-nsDOMTokenList::Contains(const nsAString& aToken, ErrorResult& aError)
+nsDOMTokenList::Contains(const nsAString& aToken)
 {
-  aError = CheckToken(aToken);
-  if (aError.Failed()) {
-    return false;
-  }
-
   const nsAttrValue* attr = GetParsedAttr();
   return attr && attr->Contains(aToken);
 }
 
 void
 nsDOMTokenList::AddInternal(const nsAttrValue* aAttr,
                             const nsTArray<nsString>& aTokens)
 {
--- a/dom/base/nsDOMTokenList.h
+++ b/dom/base/nsDOMTokenList.h
@@ -53,17 +53,17 @@ public:
   {
     bool found;
     IndexedGetter(aIndex, found, aResult);
     if (!found) {
       SetDOMStringToNull(aResult);
     }
   }
   void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
-  bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError);
+  bool Contains(const nsAString& aToken);
   void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
   void Add(const nsTArray<nsString>& aTokens,
            mozilla::ErrorResult& aError);
   void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
   void Remove(const nsTArray<nsString>& aTokens,
               mozilla::ErrorResult& aError);
   void Replace(const nsAString& aToken,
                const nsAString& aNewToken,
--- a/dom/base/test/test_classList.html
+++ b/dom/base/test/test_classList.html
@@ -95,17 +95,17 @@ function checkModification(e, funcName, 
 }
 
 function assignToClassListStrict(e) {
   "use strict";
   try {
     e.classList = "foo";
     ok(true, "assigning to classList didn't throw");
     e.removeAttribute("class");
-  } catch (e) { 
+  } catch (e) {
     ok(false, "assigning to classList threw");
   }
 }
 
 function assignToClassList(e) {
   try {
     var expect = e.classList;
     e.classList = "foo";
@@ -211,34 +211,31 @@ function testClassList(e) {
   is(e.classList[2], undefined, "wrong classList[] result");
 
   // contains() method
 
   e.removeAttribute("class");
   is(e.classList.contains("a"), false, "wrong classList.contains() result");
   try {
     e.classList.contains("");
-    ok(false, "classList.contains() didn't throw");
+    ok(true, "classList.contains(empty_string) didn't throw");
   } catch (e) {
-    is(e.name, "SyntaxError", "wrong exception thrown");
-    is(e.code, DOMException.SYNTAX_ERR, "wrong exception thrown");
+    ok(false, "classList.contains(empty_string) threw");
   }
   try {
     e.classList.contains("  ");
-    ok(false, "classList.contains() didn't throw");
+    ok(true, "classList.contains(string_with_spaces) didn't throw");
   } catch (e) {
-    is(e.name, "InvalidCharacterError", "wrong exception thrown");
-    is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
+    ok(false, "classList.contains(string_with_spaces) threw");
   }
   try {
     e.classList.contains("aa ");
-    ok(false, "classList.contains() didn't throw");
+    ok(true, "classList.contains(string_with_spaces) didn't throw");
   } catch (e) {
-    is(e.name, "InvalidCharacterError", "wrong exception thrown");
-    is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
+    ok(false, "classList.contains(string_with_spaces) threw");
   }
 
   e.setAttribute("class", "");
   is(e.classList.contains("a"), false, "wrong classList.contains() result");
 
   e.setAttribute("class", "a");
   is(e.classList.contains("a"), true, "wrong classList.contains() result");
   is(e.classList.contains("aa"), false, "wrong classList.contains() result");
@@ -377,17 +374,17 @@ function testClassList(e) {
   // Test for bug 530171
   checkToggle("null", null, false, "");
   checkToggle("", null, true, "null");
   checkToggle("undefined", undefined, false, "");
   checkToggle("", undefined, true, "undefined");
 
 
   // tests for the force argument handling
-  
+
   function checkForceToggle(before, argument, force, expectedRes, after, expectedException) {
     checkModification(e, "toggle", [argument, force], expectedRes, before, after, expectedException);
   }
 
   checkForceToggle("", "a", true, true, "a");
   checkForceToggle("a", "a", true, true, "a");
   checkForceToggle("a", "b", true, true, "a b");
   checkForceToggle("a b", "b", true, true, "a b");
--- a/dom/webidl/DOMTokenList.webidl
+++ b/dom/webidl/DOMTokenList.webidl
@@ -8,17 +8,16 @@
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface DOMTokenList {
   readonly attribute unsigned long length;
   getter DOMString? item(unsigned long index);
-  [Throws]
   boolean contains(DOMString token);
   [Throws]
   void add(DOMString... tokens);
   [Throws]
   void remove(DOMString... tokens);
   [Throws]
   void replace(DOMString token, DOMString newToken);
   [Throws]
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -968,19 +968,18 @@ nsDisplayListBuilder::MarkFramesForDispl
                                                const nsFrameList& aFrames,
                                                const nsRect& aDirtyRect) {
   mFramesMarkedForDisplay.SetCapacity(mFramesMarkedForDisplay.Length() + aFrames.GetLength());
   for (nsIFrame* e : aFrames) {
     // Skip the AccessibleCaret frame when building no caret.
     if (!IsBuildingCaret()) {
       nsIContent* content = e->GetContent();
       if (content && content->IsInNativeAnonymousSubtree() && content->IsElement()) {
-        ErrorResult rv;
         auto classList = content->AsElement()->ClassList();
-        if (classList->Contains(NS_LITERAL_STRING("moz-accessiblecaret"), rv)) {
+        if (classList->Contains(NS_LITERAL_STRING("moz-accessiblecaret"))) {
           continue;
         }
       }
     }
     mFramesMarkedForDisplay.AppendElement(e);
     MarkOutOfFlowFrameForDisplay(aDirtyFrame, e, aDirtyRect);
   }
 }
--- a/testing/web-platform/tests/dom/nodes/Element-classlist.html
+++ b/testing/web-platform/tests/dom/nodes/Element-classlist.html
@@ -61,38 +61,32 @@ test(function () {
 test(function () {
   assert_equals( elem.className, ' ' );
 }, 'className should contain initial markup whitespace');
 test(function () {
   assert_equals( elem.classList + '', ' ', 'implicit' );
   assert_equals( elem.classList.toString(), ' ', 'explicit' );
 }, 'classList should contain initial markup whitespace');
 test(function () {
-  assert_throws( 'SYNTAX_ERR', function () { elem.classList.contains(''); } );
-}, '.contains(empty_string) must throw a SYNTAX_ERR');
-test(function () {
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.add(''); } );
 }, '.add(empty_string) must throw a SYNTAX_ERR');
 test(function () {
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.remove(''); } );
 }, '.remove(empty_string) must throw a SYNTAX_ERR');
 test(function () {
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.toggle(''); } );
 }, '.toggle(empty_string) must throw a SYNTAX_ERR');
 test(function () {
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('', 'foo'); } );
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('foo', ''); } );
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('', 'foo bar'); } );
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('foo bar', ''); } );
   assert_throws( 'SYNTAX_ERR', function () { elem.classList.replace('', ''); } );
 }, '.replace with empty_string must throw a SYNTAX_ERR');
 test(function () {
-  assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.contains('a b'); } );
-}, '.contains(string_with_spaces) must throw an INVALID_CHARACTER_ERR');
-test(function () {
   assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.add('a b'); } );
 }, '.add(string_with_spaces) must throw an INVALID_CHARACTER_ERR');
 test(function () {
   assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.remove('a b'); } );
 }, '.remove(string_with_spaces) must throw an INVALID_CHARACTER_ERR');
 test(function () {
   assert_throws( 'INVALID_CHARACTER_ERR', function () { elem.classList.toggle('a b'); } );
 }, '.toggle(string_with_spaces) must throw an INVALID_CHARACTER_ERR');