Bug 1293305 - Part 1.5: Fix addon-sdk test for for-each to skip if for-each is disabled. r=mossop
authorTooru Fujisawa <arai_a@mac.com>
Mon, 21 Nov 2016 15:03:34 +0900
changeset 323568 ef6714622e751e711b11550c31b70a754d622b54
parent 323567 0ea378af1f0a4b60be6f230530c3ffd043d277d3
child 323569 933d53cdb6fe0c6b5bd141e4345735c12aca6bf9
push id30978
push usercbook@mozilla.com
push dateMon, 21 Nov 2016 14:44:46 +0000
treeherdermozilla-central@0534254e9a40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1293305
milestone53.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 1293305 - Part 1.5: Fix addon-sdk test for for-each to skip if for-each is disabled. r=mossop
addon-sdk/source/test/test-api-utils.js
--- a/addon-sdk/source/test/test-api-utils.js
+++ b/addon-sdk/source/test/test-api-utils.js
@@ -276,16 +276,25 @@ exports.testValidateMapWithMissingKeyAnd
     },
     baz: {
       map: v => "foo"
     }
   });
   assert.deepEqual(val, { baz: "foo" });
 };
 
+function forEachEnabled() {
+  try {
+    eval(`for each (var x in {}) {}`);
+  } catch (e) {
+    return false;
+  }
+  return true;
+}
+
 exports.testAddIterator = function testAddIterator (assert) {
   let obj = {};
   let keys = ["foo", "bar", "baz"];
   let vals = [1, 2, 3];
   let keysVals = [["foo", 1], ["bar", 2], ["baz", 3]];
   apiUtils.addIterator(
     obj,
     function keysValsGen() {
@@ -298,19 +307,22 @@ exports.testAddIterator = function testA
   for (let key in obj)
     keysItr.push(key);
 
   assert.equal(keysItr.length, keys.length,
                    "the keys iterator returns the correct number of items");
   for (let i = 0; i < keys.length; i++)
     assert.equal(keysItr[i], keys[i], "the key is correct");
 
-  let valsItr = [];
-  for each (let val in obj)
-    valsItr.push(val);
-  assert.equal(valsItr.length, vals.length,
-                   "the vals iterator returns the correct number of items");
-  for (let i = 0; i < vals.length; i++)
-    assert.equal(valsItr[i], vals[i], "the val is correct");
-
+  if (forEachEnabled()) {
+    eval(`
+    let valsItr = [];
+    for each (let val in obj)
+      valsItr.push(val);
+    assert.equal(valsItr.length, vals.length,
+                     "the vals iterator returns the correct number of items");
+    for (let i = 0; i < vals.length; i++)
+      assert.equal(valsItr[i], vals[i], "the val is correct");
+  `);
+  }
 };
 
 require("sdk/test").run(exports);