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 // Based on Mozilla Array.of() tests at http://dxr.mozilla.org/mozilla-central/s
ource/js/src/jit-test/tests/collections | 5 // Based on Mozilla Array.of() tests at http://dxr.mozilla.org/mozilla-central/s
ource/js/src/jit-test/tests/collections |
6 | 6 |
7 // Flags: --harmony-arrays | 7 // Flags: --harmony-arrays |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 var desc = Object.getOwnPropertyDescriptor(Array, "of"); | 153 var desc = Object.getOwnPropertyDescriptor(Array, "of"); |
154 | 154 |
155 assertEquals(desc.configurable, true); | 155 assertEquals(desc.configurable, true); |
156 assertEquals(desc.enumerable, false); | 156 assertEquals(desc.enumerable, false); |
157 assertEquals(desc.writable, true); | 157 assertEquals(desc.writable, true); |
158 assertEquals(Array.of.length, 0); | 158 assertEquals(Array.of.length, 0); |
159 assertThrows(function() { new Array.of() }, TypeError); // not a constructor | 159 assertThrows(function() { new Array.of() }, TypeError); // not a constructor |
160 | 160 |
161 // When the this-value passed in is not a constructor, the result is an array. | 161 // When the this-value passed in is not a constructor, the result is an array. |
162 [undefined, null, false, "cow"].forEach(function(val) { | 162 [ |
163 assertEquals(Array.isArray(Array.of(val)), true); | 163 undefined, |
| 164 null, |
| 165 false, |
| 166 "cow", |
| 167 NaN, |
| 168 67, |
| 169 Infinity, |
| 170 -Infinity, |
| 171 Math.cos, // builtin functions with no [[Construct]] slot |
| 172 Math.cos.bind(Math) // bound builtin functions with no [[Construct]] slot |
| 173 ].forEach(function(val) { |
| 174 assertEquals(Array.isArray(Array.of.call(val, val)), true); |
164 }); | 175 }); |
| 176 |
| 177 |
| 178 (function testBoundConstructor() { |
| 179 var boundFn = (function() {}).bind(null); |
| 180 var instance = Array.of.call(boundFn, 1, 2, 3); |
| 181 assertEquals(instance.length, 3); |
| 182 assertEquals(instance instanceof boundFn, true); |
| 183 assertEquals(Array.isArray(instance), false); |
| 184 })(); |
OLD | NEW |