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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 }); | 175 }); |
176 | 176 |
177 | 177 |
178 (function testBoundConstructor() { | 178 (function testBoundConstructor() { |
179 var boundFn = (function() {}).bind(null); | 179 var boundFn = (function() {}).bind(null); |
180 var instance = Array.of.call(boundFn, 1, 2, 3); | 180 var instance = Array.of.call(boundFn, 1, 2, 3); |
181 assertEquals(instance.length, 3); | 181 assertEquals(instance.length, 3); |
182 assertEquals(instance instanceof boundFn, true); | 182 assertEquals(instance instanceof boundFn, true); |
183 assertEquals(Array.isArray(instance), false); | 183 assertEquals(Array.isArray(instance), false); |
184 })(); | 184 })(); |
| 185 |
| 186 // Assert that [[DefineOwnProperty]] is used in ArrayFrom, meaning a |
| 187 // setter isn't called, and a failed [[DefineOwnProperty]] will throw. |
| 188 (function testDefinesOwnProperty() { |
| 189 var setterCalled = 0; |
| 190 function exotic() { |
| 191 Object.defineProperty(this, '0', { |
| 192 get: function() { return 2; }, |
| 193 set: function() { setterCalled++; } |
| 194 }); |
| 195 } |
| 196 // Check that exotic was defined right |
| 197 var instance = new exotic(); |
| 198 assertEquals(2, instance[0]); |
| 199 instance[0] = 1; |
| 200 assertEquals(2, instance[0]); |
| 201 assertEquals(1, setterCalled); |
| 202 // Accessor properties can't be overwritten with DefineOwnProperty |
| 203 assertThrows(function () { Array.of.call(exotic, 1); }, TypeError); |
| 204 assertEquals(1, setterCalled); |
| 205 })(); |
OLD | NEW |