Chromium Code Reviews| 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: --allow-natives-syntax | 5 // Flags: --allow-natives-syntax |
| 6 | 6 |
| 7 function test(mode) { | 7 function testAdd(mode) { |
| 8 var a = []; | 8 var a = []; |
| 9 Object.defineProperty(a, "length", { writable : false}); | 9 Object.defineProperty(a, "length", { writable : false}); |
| 10 | 10 |
| 11 function check(f) { | 11 function check(f) { |
| 12 try { | 12 assertThrows(function() { f(a) }, TypeError); |
| 13 f(a); | |
| 14 } catch(e) { } | |
| 15 assertFalse(0 in a); | 13 assertFalse(0 in a); |
| 16 assertEquals(0, a.length); | 14 assertEquals(0, a.length); |
| 17 } | 15 } |
| 18 | 16 |
| 19 function push(a) { | 17 function push(a) { |
| 20 a.push(3); | 18 a.push(3); |
| 21 } | 19 } |
| 22 | 20 |
| 23 if (mode == "fast properties") %ToFastProperties(a); | 21 if (mode == "fast properties") %ToFastProperties(a); |
| 24 | 22 |
| 25 check(push); | 23 check(push); |
| 26 check(push); | 24 check(push); |
| 27 check(push); | 25 check(push); |
| 28 %OptimizeFunctionOnNextCall(push); | 26 %OptimizeFunctionOnNextCall(push); |
| 29 check(push); | 27 check(push); |
| 30 | 28 |
| 31 function unshift(a) { | 29 function unshift(a) { |
| 32 a.unshift(3); | 30 a.unshift(3); |
| 33 } | 31 } |
| 34 | 32 |
| 35 check(unshift); | 33 check(unshift); |
| 36 check(unshift); | 34 check(unshift); |
| 37 check(unshift); | 35 check(unshift); |
| 38 %OptimizeFunctionOnNextCall(unshift); | 36 %OptimizeFunctionOnNextCall(unshift); |
| 39 check(unshift); | 37 check(unshift); |
| 38 | |
| 39 function splice(a) { | |
| 40 a.splice(0, 0, 3); | |
| 41 } | |
| 42 | |
| 43 check(splice); | |
| 44 check(splice); | |
| 45 check(splice); | |
| 46 %OptimizeFunctionOnNextCall(splice); | |
| 47 check(splice); | |
| 40 } | 48 } |
| 41 | 49 |
| 42 test("fast properties"); | 50 testAdd("fast properties"); |
| 43 | 51 |
| 44 test("normalized"); | 52 testAdd("normalized"); |
| 53 | |
| 54 function testRemove(mode) { | |
| 55 var a = [1, 2, 3]; | |
| 56 Object.defineProperty(a, "length", { writable : false}); | |
| 57 | |
| 58 function check(f) { | |
| 59 assertThrows(function() { f(a) }, TypeError); | |
| 60 assertEquals(3, a.length); | |
| 61 } | |
| 62 | |
| 63 if (mode == "fast properties") %ToFastProperties(a); | |
| 64 | |
| 65 function pop(a) { | |
| 66 a.pop(); | |
| 67 } | |
| 68 | |
| 69 check(pop); | |
| 70 check(pop); | |
| 71 check(pop); | |
| 72 %OptimizeFunctionOnNextCall(pop); | |
| 73 check(pop); | |
| 74 | |
| 75 function shift(a) { | |
| 76 a.shift(); | |
| 77 } | |
| 78 | |
| 79 check(shift); | |
| 80 check(shift); | |
| 81 check(shift); | |
| 82 %OptimizeFunctionOnNextCall(shift); | |
| 83 check(shift); | |
| 84 | |
| 85 function splice(a) { | |
| 86 a.splice(0, 1); | |
| 87 } | |
| 88 | |
| 89 check(splice); | |
| 90 check(splice); | |
| 91 check(splice); | |
| 92 %OptimizeFunctionOnNextCall(splice); | |
| 93 check(splice); | |
| 94 } | |
| 95 | |
| 96 testRemove("fast properties"); | |
| 97 | |
| 98 testRemove("normalized"); | |
| 45 | 99 |
| 46 var b = []; | 100 var b = []; |
| 47 Object.defineProperty(b.__proto__, "0", { | 101 Object.defineProperty(b.__proto__, "0", { |
| 48 set : function(v) { | 102 set : function(v) { |
| 49 b.x = v; | 103 b.x = v; |
| 50 Object.defineProperty(b, "length", { writable : false }); | 104 Object.defineProperty(b, "length", { writable : false }); |
| 51 }, | 105 }, |
| 52 get: function() { | 106 get: function() { |
| 53 return b.x; | 107 return b.x; |
| 54 } | 108 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 }, | 144 }, |
| 91 get: function() { | 145 get: function() { |
| 92 return b.z; | 146 return b.z; |
| 93 } | 147 } |
| 94 }); | 148 }); |
| 95 | 149 |
| 96 try { | 150 try { |
| 97 b.unshift(3, 4, 5); | 151 b.unshift(3, 4, 5); |
| 98 } catch(e) { } | 152 } catch(e) { } |
| 99 | 153 |
| 100 // TODO(ulan): According to the ECMA-262 unshift should throw an exception | 154 assertFalse(2 in b); |
|
adamk
2014/11/13 23:43:29
These have since been fixed.
Michael Starzinger
2014/11/14 17:00:22
Acknowledged. Awesome.
| |
| 101 // when moving b[0] to b[3] (see 15.4.4.13 step 6.d.ii). This is difficult | 155 assertFalse(3 in b); |
| 102 // to do with our current implementation of SmartMove() in src/array.js and | 156 assertEquals(2, b.length); |
| 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 |