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: --allow-natives-syntax |
| 6 |
| 7 function test(mode) { |
| 8 var a = []; |
| 9 Object.defineProperty(a, "length", { writable : false}); |
| 10 |
| 11 function check(f) { |
| 12 try { |
| 13 f(a); |
| 14 } catch(e) { } |
| 15 assertFalse(0 in a); |
| 16 assertEquals(0, a.length); |
| 17 } |
| 18 |
| 19 function push(a) { |
| 20 a.push(3); |
| 21 } |
| 22 |
| 23 if (mode == "fast properties") %ToFastProperties(a); |
| 24 |
| 25 check(push); |
| 26 check(push); |
| 27 check(push); |
| 28 %OptimizeFunctionOnNextCall(push); |
| 29 check(push); |
| 30 |
| 31 function unshift(a) { |
| 32 a.unshift(3); |
| 33 } |
| 34 |
| 35 check(unshift); |
| 36 check(unshift); |
| 37 check(unshift); |
| 38 %OptimizeFunctionOnNextCall(unshift); |
| 39 check(unshift); |
| 40 } |
| 41 |
| 42 test("fast properties"); |
| 43 |
| 44 test("normalized"); |
| 45 |
| 46 var b = []; |
| 47 Object.defineProperty(b.__proto__, "0", { |
| 48 set : function(v) { |
| 49 b.x = v; |
| 50 Object.defineProperty(b, "length", { writable : false }); |
| 51 }, |
| 52 get: function() { |
| 53 return b.x; |
| 54 } |
| 55 }); |
| 56 |
| 57 b = []; |
| 58 try { |
| 59 b.push(3, 4, 5); |
| 60 } catch(e) { } |
| 61 assertFalse(1 in b); |
| 62 assertFalse(2 in b); |
| 63 assertEquals(0, b.length); |
| 64 |
| 65 b = []; |
| 66 try { |
| 67 b.unshift(3, 4, 5); |
| 68 } catch(e) { } |
| 69 assertFalse(1 in b); |
| 70 assertFalse(2 in b); |
| 71 assertEquals(0, b.length); |
| 72 |
| 73 b = [1, 2]; |
| 74 try { |
| 75 b.unshift(3, 4, 5); |
| 76 } catch(e) { } |
| 77 assertEquals(3, b[0]); |
| 78 assertEquals(4, b[1]); |
| 79 assertEquals(5, b[2]); |
| 80 assertEquals(1, b[3]); |
| 81 assertEquals(2, b[4]); |
| 82 assertEquals(5, b.length); |
| 83 |
| 84 b = [1, 2]; |
| 85 |
| 86 Object.defineProperty(b.__proto__, "4", { |
| 87 set : function(v) { |
| 88 b.z = v; |
| 89 Object.defineProperty(b, "length", { writable : false }); |
| 90 }, |
| 91 get: function() { |
| 92 return b.z; |
| 93 } |
| 94 }); |
| 95 |
| 96 try { |
| 97 b.unshift(3, 4, 5); |
| 98 } catch(e) { } |
| 99 |
| 100 // TODO(ulan): According to the ECMA-262 unshift should throw an exception |
| 101 // when moving b[0] to b[3] (see 15.4.4.13 step 6.d.ii). This is difficult |
| 102 // to do with our current implementation of SmartMove() in src/array.js and |
| 103 // it will regress performance. Uncomment the following line once acceptable |
| 104 // solution is found: |
| 105 // assertFalse(2 in b); |
| 106 // assertFalse(3 in b); |
| 107 // assertEquals(2, b.length); |
OLD | NEW |