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 // Test that Array builtins can be called on primitive values. |
| 6 var values = [ 23, 4.2, true, false, 0/0 ]; |
| 7 for (var i = 0; i < values.length; ++i) { |
| 8 var v = values[i]; |
| 9 Array.prototype.pop.call(v); |
| 10 Array.prototype.push.call(v); |
| 11 Array.prototype.shift.call(v); |
| 12 Array.prototype.unshift.call(v); |
| 13 } |
| 14 |
| 15 // Test that ToObject on primitive values is only called once. |
| 16 var length_receiver, element_receiver; |
| 17 function length() { length_receiver = this; return 1; } |
| 18 function element() { element_receiver = this; return "x"; } |
| 19 Object.defineProperty(Number.prototype, "length", { get:length, set:length }); |
| 20 Object.defineProperty(Number.prototype, "0", { get:element, set:element }); |
| 21 Object.defineProperty(Number.prototype, "1", { get:element, set:element }); |
| 22 |
| 23 assertDoesNotThrow("Array.prototype.pop.call(23)"); |
| 24 assertEquals(new Number(23), length_receiver); |
| 25 assertSame(length_receiver, element_receiver); |
| 26 |
| 27 assertDoesNotThrow("Array.prototype.push.call(42, 'y')"); |
| 28 assertEquals(new Number(42), length_receiver); |
| 29 assertSame(length_receiver, element_receiver); |
| 30 |
| 31 assertDoesNotThrow("Array.prototype.shift.call(65)"); |
| 32 assertEquals(new Number(65), length_receiver); |
| 33 assertSame(length_receiver, element_receiver); |
| 34 |
| 35 assertDoesNotThrow("Array.prototype.unshift.call(99, 'z')"); |
| 36 assertEquals(new Number(99), length_receiver); |
| 37 assertSame(length_receiver, element_receiver); |
OLD | NEW |