summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Iterator/from/wrap-functions-on-other-global.js
blob: 186e4e62d04c02807c7f3d7dc5faa1efafa1d2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);