OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-arrays --harmony-generators |
| 6 (function() { |
| 7 |
| 8 assertEquals(1, Array.from.length); |
| 9 |
| 10 function* generator() { |
| 11 yield 'a'; |
| 12 yield 'b'; |
| 13 yield 'c'; |
| 14 } |
| 15 |
| 16 function testArrayFrom(thisArg, constructor) { |
| 17 assertArrayLikeEquals(Array.from.call(thisArg, generator()), ['a', 'b', 'c'],
constructor); |
| 18 } |
| 19 |
| 20 testArrayFrom(Array, Array); |
| 21 testArrayFrom(null, Array); |
| 22 testArrayFrom({}, Array); |
| 23 testArrayFrom(Object, Object); |
| 24 testArrayFrom(Other, Other); |
| 25 |
| 26 function Other() {} |
| 27 |
| 28 function assertArrayLikeEquals(value, expected, type) { |
| 29 assertInstanceof(value, type); |
| 30 assertEquals(expected.length, value.length); |
| 31 for (var i=0; i<value.length; ++i) { |
| 32 assertEquals(expected[i], value[i]); |
| 33 } |
| 34 } |
| 35 |
| 36 })(); |
OLD | NEW |