Chromium Code Reviews| Index: test/mjsunit/harmony/array-from.js |
| diff --git a/test/mjsunit/harmony/array-from.js b/test/mjsunit/harmony/array-from.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a09d95a446062f7b3e23e07875beaca88a23ec81 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/array-from.js |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony |
|
arv (Not doing code reviews)
2014/07/02 18:26:44
Use more specific flag(s).
|
| + |
| +assertEquals(1, Array.from.length); |
| + |
| +assertArrayEquals(Array.from(NaN), []); |
| +assertArrayEquals(Array.from(Infinity), []); |
| +assertArrayEquals(Array.from(10000000), []); |
| +assertArrayEquals(Array.from('test'), ['t', 'e', 's', 't']); |
| +assertArrayEquals(Array.from({length: 1, '0': { 'foo': 'bar' }}), [{'foo': 'bar'}]); |
|
arv (Not doing code reviews)
2014/07/02 18:26:44
Can you add test with length = -1
I wish we could
|
| +assertArrayEquals(Array.from(['foo', 'bar', 'baz']), ['foo', 'bar', 'baz']); |
| +assertArrayEquals(Array.from((new Set).add('foo').add('bar').add('baz')), ['foo', 'bar', 'baz']); |
| +assertArrayEquals(Array.from((new Map).set(0, 'foo').set(1, 'bar').set(2, 'baz')), [[0, 'foo'], [1, 'bar'], [2, 'baz']]); |
| +assertArrayEquals(Array.from(generator()), ['a', 'b', 'c']); |
| +assertArrayEquals(Array.from('test', function(x) { |
| + return this.filter(x); |
| +}, { |
| + filter: function(x) { return x.toUpperCase(); } |
| +}), ['T', 'E', 'S', 'T']); |
| +assertArrayEquals(Array.from('test', function(x) { |
| + return x.toUpperCase(); |
| +}), ['T', 'E', 'S', 'T']); |
| + |
| +// Mozilla: |
| +// Array.from on a string handles surrogate pairs correctly. |
| +var gclef = "\uD834\uDD1E"; // U+1D11E MUSICAL SYMBOL G CLEF |
| +assertArrayEquals(Array.from(gclef), [gclef]); |
| +assertArrayEquals(Array.from(gclef + " G"), [gclef, " ", "G"]); |
| + |
| +function* generator() { |
| + var a = ['a', 'b', 'c']; |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
function* generator() {
yield 'a';
yield 'b';
|
| + var n = 0; |
| + while (n < a.length) { |
| + yield a[n++]; |
| + } |
| +} |
| + |
| +assertThrows('Array.from(null)', TypeError); |
| +assertThrows('Array.from(undefined)', TypeError); |
| + |
| +var nullIterator = {}; |
| +nullIterator[Symbol.iterator] = null; |
| +assertThrows('Array.from(nullIterator)', TypeError); |
| + |
| +var nonObjIterator = {}; |
| +nonObjIterator[Symbol.iterator] = function() { return "nonObject"; }; |
| +assertThrows('Array.from(nonObjIterator)', TypeError); |
| + |
| +assertThrows('Array.from([], null)', TypeError); |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
This needs more tests. Especially things like call
|