Bug 1079640 - Fix some tests that fail when ES6 symbols are disabled. r=bz. DONTBUILD.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 08 Oct 2014 11:12:11 -0500
changeset 209867 50288676ddbc40b549e552e48e212c86020dc042
parent 209866 37dae39533a6806bc5fb44d303013eab0c8b3238
child 209868 a1a6b6736374d0e886ca14940ca9b7ae5bad18d8
push id27628
push userkwierso@gmail.com
push dateSat, 11 Oct 2014 02:00:16 +0000
treeherdermozilla-central@f74ad36bb97b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1079640
milestone35.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 1079640 - Fix some tests that fail when ES6 symbols are disabled. r=bz. DONTBUILD.
dom/bindings/test/test_sequence_detection.html
js/src/jsapi-tests/testForOfIterator.cpp
--- a/dom/bindings/test/test_sequence_detection.html
+++ b/dom/bindings/test/test_sequence_detection.html
@@ -10,29 +10,41 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
   /** Test for Bug 1066432 **/
   SimpleTest.waitForExplicitFinish();
   SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, function() {
     var testInterfaceJS = new TestInterfaceJS();
     ok(testInterfaceJS, "got a TestInterfaceJS object");
+
+    var nonIterableObject = { "@@iterator": 5 };
+    if (typeof Symbol === "function") {
+      // Make this test fail if Symbol.iterator is correctly implemented.
+      // This is here to make sure this test is updated when bug 918828 lands,
+      // at which point the correct code will be:
+      //   var JS_HAS_SYMBOLS = typeof Symbol === "function";
+      //   var std_iterator = JS_HAS_SYMBOLS ? Symbol.iterator : "@@iterator";
+      //   var nonIterableObject = { [std_iterator]: 5};
+      // Otherwise, fixing bug 918828 would cause this test to silently stop
+      // testing what it's supposed to be testing.
+      nonIterableObject[Symbol.iterator] = Array.prototype[Symbol.iterator];
+    }
+
     try {
-      testInterfaceJS.testSequenceOverload(
-        { "@@iterator": 5, [Symbol.iterator]: Array.prototype[Symbol.iterator] });
-      ok(false, "Should have thrown in the overload case");
+      testInterfaceJS.testSequenceOverload(nonIterableObject);
+      ok(false, "Should have thrown in the overload case");  // see long comment above!
     } catch (e) {
       ise(e.name, "TypeError", "Should get a TypeError for the overload case");
       ok(e.message.contains("not iterable"),
          "Should have a message about being non-iterable in the overload case");
     }
 
     try {
-      testInterfaceJS.testSequenceUnion(
-        { "@@iterator": 5, [Symbol.iterator]: Array.prototype[Symbol.iterator] });
+      testInterfaceJS.testSequenceUnion(nonIterableObject);
       ok(false, "Should have thrown in the union case");
     } catch (e) {
       ise(e.name, "TypeError", "Should get a TypeError for the union case");
       ok(e.message.contains("not iterable"),
          "Should have a message about being non-iterable in the union case");
     }
 
     SimpleTest.finish();
--- a/js/src/jsapi-tests/testForOfIterator.cpp
+++ b/js/src/jsapi-tests/testForOfIterator.cpp
@@ -2,37 +2,47 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsapi-tests/tests.h"
 
+#ifdef JS_HAS_SYMBOLS
+#define IF_JS_HAS_SYMBOLS(x) x
+#else
+#define IF_JS_HAS_SYMBOLS(x)
+#endif
+
 BEGIN_TEST(testForOfIterator_basicNonIterable)
 {
     JS::RootedValue v(cx);
     // Hack to make it simple to produce an object that has a property
     // named Symbol.iterator.
-    EVAL("var obj = { '@@iterator': 5, [Symbol.iterator]: Array.prototype[Symbol.iterator] }; obj;", &v);
+    EVAL("var obj = {'@@iterator': 5"
+         IF_JS_HAS_SYMBOLS(", [Symbol.iterator]: Array.prototype[Symbol.iterator]")
+         "}; obj;", &v);
     JS::ForOfIterator iter(cx);
     bool ok = iter.init(v);
     CHECK(!ok);
     JS_ClearPendingException(cx);
     return true;
 }
 END_TEST(testForOfIterator_basicNonIterable)
 
 BEGIN_TEST(testForOfIterator_bug515273_part1)
 {
     JS::RootedValue v(cx);
 
     // Hack to make it simple to produce an object that has a property
     // named Symbol.iterator.
-    EVAL("var obj = { '@@iterator': 5, [Symbol.iterator]: Array.prototype[Symbol.iterator] }; obj;", &v);
+    EVAL("var obj = {'@@iterator': 5"
+         IF_JS_HAS_SYMBOLS(", [Symbol.iterator]: Array.prototype[Symbol.iterator]")
+         "}; obj;", &v);
 
     JS::ForOfIterator iter(cx);
     bool ok = iter.init(v, JS::ForOfIterator::AllowNonIterable);
     CHECK(!ok);
     JS_ClearPendingException(cx);
     return true;
 }
 END_TEST(testForOfIterator_bug515273_part1)