summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js')
-rw-r--r--js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js b/js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js
new file mode 100644
index 0000000000..186e4e62d0
--- /dev/null
+++ b/js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js
@@ -0,0 +1,31 @@
+// |reftest| skip-if(!this.hasOwnProperty('Iterator'))
+
+class TestError extends Error {}
+
+function checkIterResult({done, value}, expectedDone, expectedValue) {
+ assertEq(done, expectedDone);
+ assertEq(value, expectedValue);
+}
+
+const iter = {
+ next(value) {
+ return {done: false, value: arguments.length};
+ },
+ return() {
+ throw new TestError();
+ },
+ throw: (value) => ({done: true, value}),
+};
+const thisWrap = Iterator.from(iter);
+const otherGlobal = newGlobal({newCompartment: true});
+const otherWrap = otherGlobal.Iterator.from(iter);
+
+checkIterResult(thisWrap.next.call(otherWrap), false, 0);
+checkIterResult(thisWrap.next.call(otherWrap, 'value'), false, 1);
+
+assertThrowsInstanceOf(thisWrap.return.bind(otherWrap), TestError);
+
+checkIterResult(thisWrap.throw.call(otherWrap, 'value'), true, 'value');
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);