Bug 1257849 part 5. Implement DOMTokenList.prototype.supports(). r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 04 May 2016 23:41:25 -0400
changeset 335189 5d87bd22c1c92575090a08321a44c2b200abcd65
parent 335188 7df7d2acee673dc40566c5e2a3be93cf59b4064f
child 335190 7c3bfb2700e78d06160699635d5b7438934d568d
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)
reviewersbkelly
bugs1257849
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 1257849 part 5. Implement DOMTokenList.prototype.supports(). r=bkelly
dom/base/nsDOMTokenList.cpp
dom/base/nsDOMTokenList.h
dom/bindings/Errors.msg
dom/webidl/DOMTokenList.webidl
testing/web-platform/meta/dom/interfaces.html.ini
testing/web-platform/tests/dom/nodes/Element-classlist.html
testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-rellist.html
--- a/dom/base/nsDOMTokenList.cpp
+++ b/dom/base/nsDOMTokenList.cpp
@@ -342,16 +342,38 @@ nsDOMTokenList::Replace(const nsAString&
 
   tokens.AppendElement(aToken);
   RemoveInternal(attr, tokens);
 
   tokens[0] = aNewToken;
   AddInternal(attr, tokens);
 }
 
+bool
+nsDOMTokenList::Supports(const nsAString& aToken,
+                         ErrorResult& aError)
+{
+  if (!mSupportedTokens) {
+    aError.ThrowTypeError<MSG_TOKENLIST_NO_SUPPORTED_TOKENS>(
+      mElement->LocalName(),
+      nsDependentAtomString(mAttrAtom));
+    return false;
+  }
+
+  for (DOMTokenListSupportedToken* supportedToken = mSupportedTokens;
+       *supportedToken;
+       ++supportedToken) {
+    if (aToken.LowerCaseEqualsASCII(*supportedToken)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 void
 nsDOMTokenList::Stringify(nsAString& aResult)
 {
   if (!mElement) {
     aResult.Truncate();
     return;
   }
 
--- a/dom/base/nsDOMTokenList.h
+++ b/dom/base/nsDOMTokenList.h
@@ -66,16 +66,18 @@ public:
   void Remove(const nsTArray<nsString>& aTokens,
               mozilla::ErrorResult& aError);
   void Replace(const nsAString& aToken,
                const nsAString& aNewToken,
                mozilla::ErrorResult& aError);
   bool Toggle(const nsAString& aToken,
               const mozilla::dom::Optional<bool>& force,
               mozilla::ErrorResult& aError);
+  bool Supports(const nsAString& aToken,
+                mozilla::ErrorResult& aError);
 
   void GetValue(nsAString& aResult) { Stringify(aResult); }
   void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
   void Stringify(nsAString& aResult);
 
 protected:
   virtual ~nsDOMTokenList();
 
--- a/dom/bindings/Errors.msg
+++ b/dom/bindings/Errors.msg
@@ -91,8 +91,9 @@ MSG_DEF(MSG_IS_NOT_PROMISE, 1, JSEXN_TYP
 MSG_DEF(MSG_SW_INSTALL_ERROR, 2, JSEXN_TYPEERR, "ServiceWorker script at {0} for scope {1} encountered an error during installation.")
 MSG_DEF(MSG_SW_SCRIPT_THREW, 2, JSEXN_TYPEERR, "ServiceWorker script at {0} for scope {1} threw an exception during script evaluation.")
 MSG_DEF(MSG_TYPEDARRAY_IS_SHARED, 1, JSEXN_TYPEERR, "{0} can't be a typed array on SharedArrayBuffer")
 MSG_DEF(MSG_CACHE_ADD_FAILED_RESPONSE, 3, JSEXN_TYPEERR, "Cache got {0} response with bad status {1} while trying to add request {2}")
 MSG_DEF(MSG_SW_UPDATE_BAD_REGISTRATION, 2, JSEXN_TYPEERR, "Failed to update the ServiceWorker for scope {0] because the registration has been {1} since the update was scheduled.")
 MSG_DEF(MSG_INVALID_DURATION_ERROR, 1, JSEXN_TYPEERR, "Invalid duration '{0}'.")
 MSG_DEF(MSG_INVALID_EASING_ERROR, 1, JSEXN_TYPEERR, "Invalid easing '{0}'.")
 MSG_DEF(MSG_USELESS_SETTIMEOUT, 1, JSEXN_TYPEERR, "Useless {0} call (missing quotes around argument?)")
+MSG_DEF(MSG_TOKENLIST_NO_SUPPORTED_TOKENS, 2, JSEXN_TYPEERR, "{0} attribute of <{1}> does not define any supported tokens")
--- a/dom/webidl/DOMTokenList.webidl
+++ b/dom/webidl/DOMTokenList.webidl
@@ -18,12 +18,14 @@ interface DOMTokenList {
   [Throws]
   void add(DOMString... tokens);
   [Throws]
   void remove(DOMString... tokens);
   [Throws]
   void replace(DOMString token, DOMString newToken);
   [Throws]
   boolean toggle(DOMString token, optional boolean force);
+  [Throws]
+  boolean supports(DOMString token);
   [SetterThrows]
   attribute DOMString value;
   stringifier DOMString ();
 };
--- a/testing/web-platform/meta/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/dom/interfaces.html.ini
@@ -82,25 +82,16 @@
     expected: FAIL
 
   [Document interface: xmlDoc must inherit property "query" with the proper type (35)]
     expected: FAIL
 
   [Document interface: xmlDoc must inherit property "queryAll" with the proper type (36)]
     expected: FAIL
 
-  [DOMTokenList interface: operation supports(DOMString)]
-    expected: FAIL
-
-  [DOMTokenList interface: document.body.classList must inherit property "supports" with the proper type (7)]
-    expected: FAIL
-
-  [DOMTokenList interface: calling supports(DOMString) on document.body.classList with too few arguments must throw TypeError]
-    expected: FAIL
-
   [Element interface: element must inherit property "query" with the proper type (36)]
     expected: FAIL
 
   [Element interface: element must inherit property "queryAll" with the proper type (37)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "origin" with the proper type (3)]
     expected: FAIL
--- a/testing/web-platform/tests/dom/nodes/Element-classlist.html
+++ b/testing/web-platform/tests/dom/nodes/Element-classlist.html
@@ -386,16 +386,22 @@ test(function () {
 
   foo.classList.replace('a', 'b');
   assert_equals(foo.className, 'b');
 
   assert_throws('SYNTAX_ERR', function () { foo.classList.replace('t with space', '') });
   assert_throws('INVALID_CHARACTER_ERR', function () { foo.classList.replace('t with space', 'foo') });
   assert_throws('SYNTAX_ERR', function () { foo.classList.replace('', 'foo') });
 }, 'classList.replace should work');
+
+test(function() {
+  var foo = document.createElement('div');
+  assert_throws(new TypeError(),
+                function() { foo.classList.supports('hello') });
+}, 'classList.supports should throw');
     </script>
   </head>
   <body>
 
     <div id="log"></div>
 
   </body>
 </html>
--- a/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-rellist.html
+++ b/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-rellist.html
@@ -14,10 +14,12 @@ test(function() {
   var list = document.getElementById("link").relList;
   assert_equals(list.contains(undefined), true); //"undefined"
   assert_equals(list.contains(null), true); //"null"
   assert_equals(list.contains(-0), true); //"0"
   assert_equals(list.contains(+0), true); //"0"
   assert_equals(list.contains(NaN), true); //"NaN"
   assert_equals(list.contains(+Infinity), true); //"Infinity"
   assert_equals(list.contains(-Infinity), false); //"-Infinity"
+  assert_equals(list.supports("stylesheet"), true);
+  assert_equals(list.supports("nosuchrelvalueever"), false);
 });
 </script>