| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script> |
| function createIterable(iterations) { |
| return { |
| [Symbol.iterator]() { |
| var i = 0; |
| return {next: () => iterations[i++]}; |
| }, |
| }; |
| } |
| |
| function assertIterationJoinEqual(iterable, description) { |
| test(() => { |
| assert_equals(internals.dictionaryTest().stringFromIterable(iterable), Array.from(iterable).join(',')); |
| }, description); |
| } |
| |
| assertIterationJoinEqual([1, 2, 3], 'Standard array of numbers.'); |
| assertIterationJoinEqual(new Set([1, 2, 3]), 'Standard set of numbers.'); |
| assertIterationJoinEqual([], 'Standard empty array.'); |
| assertIterationJoinEqual(new Set(), 'Standard empty set.'); |
| |
| assertIterationJoinEqual(createIterable([ |
| {done: false, value: 1}, |
| {done: false, value: 2}, |
| {done: false, value: 3}, |
| {done: true}, |
| ]), 'Custom list of numbers.'); |
| |
| assertIterationJoinEqual(createIterable([ |
| {done: false, value: 1}, |
| {done: false, value: 2}, |
| {done: false, value: 3}, |
| {done: 'yes'}, |
| ]), 'Truthy done signal.'); |
| |
| assertIterationJoinEqual(createIterable([ |
| {value: 1}, |
| {value: 2}, |
| {value: 3}, |
| {done: true}, |
| ]), 'Custom list of numbers with missing "done: false" signal.'); |
| |
| assertIterationJoinEqual(createIterable([ |
| {done: false, value: 1}, |
| {done: false, value: 2}, |
| {done: true}, |
| {done: false, value: 3}, |
| ]), 'Terminates when done is true.'); |
| |
| assertIterationJoinEqual(createIterable([ |
| {done: true}, |
| ]), 'Empty list.'); |
| |
| assertIterationJoinEqual({}, 'Non-iterable object.'); |
| |
| test(() => { |
| var iterable = {[Symbol.iterator]() { return {}; }}; |
| assert_throws(null, () => Array.from(iterable)); |
| assert_throws(null, () => internals.dictionaryTest().stringFromIterable(iterable)); |
| }, 'Iterator object without next() function should throw.'); |
| |
| test(() => { |
| var iterable = createIterable([ |
| {done: false, value: 1}, |
| {done: false, value: 2}, |
| {done: false, value: 3}, |
| 1234, |
| ]); |
| assert_throws(null, () => Array.from(iterable)); |
| assert_throws(null, () => internals.dictionaryTest().stringFromIterable(iterable)); |
| }, 'Non-object iterator.next() result should throw.'); |
| </script> |