diff options
Diffstat (limited to 'js/src/jit-test/tests/for-of/next-shenanigans.js')
-rw-r--r-- | js/src/jit-test/tests/for-of/next-shenanigans.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/for-of/next-shenanigans.js b/js/src/jit-test/tests/for-of/next-shenanigans.js new file mode 100644 index 0000000000..f57b04e12e --- /dev/null +++ b/js/src/jit-test/tests/for-of/next-shenanigans.js @@ -0,0 +1,27 @@ +// Test for-of with iter.next and monkeypatching. + +function* g(n) { for (var i=0; i<n; i++) yield i; } +var GeneratorObjectPrototype = Object.getPrototypeOf(g).prototype; +var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next; + +// Monkeypatch next on an iterator. +var inner = g(20); +var n = 0; +for (let x of inner) { + assertEq(x, n++); + if (n == 1) { + inner.next = function() { throw 'not reached'; }; + } +} +assertEq(n, 20); + +// Monkeypatch next on the prototype. +var inner = g(20); +var n = 0; +for (let x of inner) { + assertEq(x, n++); + if (n == 1) { + GeneratorObjectPrototype.next = function() { throw 'not reached'; }; + } +} +assertEq(n, 20); |