Bug 1042398 - Tests. r=bholley
authorMike Conley <mconley@mozilla.com>
Wed, 23 Jul 2014 15:20:05 -0700
changeset 195795 6878d55c8dda10b257d4d453265deddb01d22bb2
parent 195794 25608b44a40897db129de97fd453538f1cc0fa79
child 195796 68ec1899bb631f1ae0ce303b3736a02b447a5175
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbholley
bugs1042398
milestone34.0a1
Bug 1042398 - Tests. r=bholley
js/xpconnect/tests/unit/test_xrayed_iterator.js
js/xpconnect/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_xrayed_iterator.js
@@ -0,0 +1,36 @@
+const Cu = Components.utils;
+function run_test() {
+
+  var toEval = [
+    "var customIterator = {",
+    "  _array: [6, 7, 8, 9],",
+    "  __iterator__: function() {",
+    "    for (var i = 0; i < this._array.length; ++i)",
+    "      yield this._array[i];",
+    "  }",
+    "}"
+  ].join('\n');
+
+  function checkIterator(iterator) {
+    var control = [6, 7, 8, 9];
+    var i = 0;
+    for (var item in iterator) {
+      do_check_eq(item, control[i]);
+      ++i;
+    }
+  }
+
+  // First, try in our own scope.
+  eval(toEval);
+  checkIterator(customIterator);
+
+  // Next, try a vanilla CCW.
+  var sbChrome = Cu.Sandbox(this);
+  Cu.evalInSandbox(toEval, sbChrome, '1.7');
+  checkIterator(sbChrome.customIterator);
+
+  // Finally, try an Xray waiver.
+  var sbContent = Cu.Sandbox('http://www.example.com');
+  Cu.evalInSandbox(toEval, sbContent, '1.7');
+  checkIterator(Cu.waiveXrays(sbContent.customIterator));
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -94,8 +94,9 @@ head = head_watchdog.js
 head = head_watchdog.js
 [test_watchdog_toggle.js]
 head = head_watchdog.js
 [test_watchdog_default.js]
 head = head_watchdog.js
 [test_watchdog_hibernate.js]
 head = head_watchdog.js
 [test_writeToGlobalPrototype.js]
+[test_xrayed_iterator.js]