OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-arrays --harmony-generators | 5 // Flags: --harmony-arrays --harmony-generators |
6 (function() { | 6 (function() { |
7 | 7 |
8 assertEquals(1, Array.from.length); | 8 assertEquals(1, Array.from.length); |
9 | 9 |
10 function assertArrayLikeEquals(value, expected, type) { | 10 function assertArrayLikeEquals(value, expected, type) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) { | 85 assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) { |
86 return this.filter(x); | 86 return this.filter(x); |
87 }, { | 87 }, { |
88 filter: function(x) { return x.toUpperCase(); } | 88 filter: function(x) { return x.toUpperCase(); } |
89 }), ['T', 'E', 'S', 'T'], constructor); | 89 }), ['T', 'E', 'S', 'T'], constructor); |
90 assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) { | 90 assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) { |
91 return x.toUpperCase(); | 91 return x.toUpperCase(); |
92 }), ['T', 'E', 'S', 'T'], constructor); | 92 }), ['T', 'E', 'S', 'T'], constructor); |
93 | 93 |
94 this.thisArg = thisArg; | 94 assertThrows(function() { Array.from.call(thisArg, null); }, TypeError); |
95 assertThrows('Array.from.call(thisArg, null)', TypeError); | 95 assertThrows(function() { Array.from.call(thisArg, undefined); }, TypeError); |
96 assertThrows('Array.from.call(thisArg, undefined)', TypeError); | 96 assertThrows(function() { Array.from.call(thisArg, [], null); }, TypeError); |
97 assertThrows('Array.from.call(thisArg, [], null)', TypeError); | 97 assertThrows(function() { Array.from.call(thisArg, [], "noncallable"); }, |
98 assertThrows('Array.from.call(thisArg, [], "noncallable")', TypeError); | 98 TypeError); |
99 | 99 |
100 this.nullIterator = {}; | 100 var nullIterator = {}; |
101 nullIterator[Symbol.iterator] = null; | 101 nullIterator[Symbol.iterator] = null; |
102 assertThrows('Array.from.call(thisArg, nullIterator)', TypeError); | 102 assertArrayLikeEquals(Array.from.call(thisArg, nullIterator), [], |
| 103 constructor); |
103 | 104 |
104 this.nonObjIterator = {}; | 105 var nonObjIterator = {}; |
105 nonObjIterator[Symbol.iterator] = function() { return "nonObject"; }; | 106 nonObjIterator[Symbol.iterator] = function() { return "nonObject"; }; |
106 assertThrows('Array.from.call(thisArg, nonObjIterator)', TypeError); | 107 assertThrows(function() { Array.from.call(thisArg, nonObjIterator); }, |
| 108 TypeError); |
107 | 109 |
108 assertThrows('Array.from.call(thisArg, [], null)', TypeError); | 110 assertThrows(function() { Array.from.call(thisArg, [], null); }, TypeError); |
109 } | 111 } |
110 | 112 |
111 function Other() {} | 113 function Other() {} |
112 | 114 |
113 var boundFn = (function() {}).bind(Array, 27); | 115 var boundFn = (function() {}).bind(Array, 27); |
114 | 116 |
115 testArrayFrom(Array, Array); | 117 testArrayFrom(Array, Array); |
116 testArrayFrom(null, Array); | 118 testArrayFrom(null, Array); |
117 testArrayFrom({}, Array); | 119 testArrayFrom({}, Array); |
118 testArrayFrom(Object, Object); | 120 testArrayFrom(Object, Object); |
119 testArrayFrom(Other, Other); | 121 testArrayFrom(Other, Other); |
120 testArrayFrom(Math.cos, Array); | 122 testArrayFrom(Math.cos, Array); |
121 testArrayFrom(Math.cos.bind(Math), Array); | 123 testArrayFrom(Math.cos.bind(Math), Array); |
122 testArrayFrom(boundFn, boundFn); | 124 testArrayFrom(boundFn, boundFn); |
123 | 125 |
124 })(); | 126 })(); |
OLD | NEW |