diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-03-27 13:21:40 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-03-27 13:21:40 +0200 |
commit | e19749682050ff716fc9ff3bbc05ee3911570670 (patch) | |
tree | 4213a4e8efdaadea0409642702ec6c499f7b9ccc /js/src/tests/ecma_6/shell.js | |
parent | 72721d1d032db2099593076bf96f274623af3c26 (diff) | |
parent | 70c8cf8db71880c1ab1f8fee4787a19316960dac (diff) | |
download | UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.gz UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.lz UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.xz UXP-e19749682050ff716fc9ff3bbc05ee3911570670.zip |
Merge remote-tracking branch 'janek/js_IteratorClose_1'
Diffstat (limited to 'js/src/tests/ecma_6/shell.js')
-rw-r--r-- | js/src/tests/ecma_6/shell.js | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/js/src/tests/ecma_6/shell.js b/js/src/tests/ecma_6/shell.js index 06be6f2db..756da9f36 100644 --- a/js/src/tests/ecma_6/shell.js +++ b/js/src/tests/ecma_6/shell.js @@ -3,21 +3,43 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ (function(global) { - /** Yield every permutation of the elements in some array. */ - global.Permutations = function* Permutations(items) { - if (items.length == 0) { - yield []; - } else { - items = items.slice(0); - for (let i = 0; i < items.length; i++) { - let swap = items[0]; - items[0] = items[i]; - items[i] = swap; - for (let e of Permutations(items.slice(1, items.length))) - yield [items[0]].concat(e); - } - } - }; + /** Yield every permutation of the elements in some array. */ + global.Permutations = function* Permutations(items) { + if (items.length == 0) { + yield []; + } else { + items = items.slice(0); + for (let i = 0; i < items.length; i++) { + let swap = items[0]; + items[0] = items[i]; + items[i] = swap; + for (let e of Permutations(items.slice(1, items.length))) + yield [items[0]].concat(e); + } + } + }; + + /** Make an iterator with a return method. */ + global.makeIterator = function makeIterator(overrides) { + var throwMethod; + if (overrides && overrides.throw) + throwMethod = overrides.throw; + var iterator = { + throw: throwMethod, + next: function(x) { + if (overrides && overrides.next) + return overrides.next(x); + return { done: false }; + }, + return: function(x) { + if (overrides && overrides.ret) + return overrides.ret(x); + return { done: true }; + } + }; + + return function() { return iterator; }; + }; })(this); if (typeof assertThrowsInstanceOf === 'undefined') { |