| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 var a = [0,1,2,3]; | 28 var a = [0,1,2,3]; |
| 29 a.length = 0; | 29 assertEquals(0, a.length = 0); |
| 30 | 30 |
| 31 assertEquals('undefined', typeof a[0]); | 31 assertEquals('undefined', typeof a[0]); |
| 32 assertEquals('undefined', typeof a[1]); | 32 assertEquals('undefined', typeof a[1]); |
| 33 assertEquals('undefined', typeof a[2]); | 33 assertEquals('undefined', typeof a[2]); |
| 34 assertEquals('undefined', typeof a[3]); | 34 assertEquals('undefined', typeof a[3]); |
| 35 | 35 |
| 36 | 36 |
| 37 var a = [0,1,2,3]; | 37 var a = [0,1,2,3]; |
| 38 a.length = 2; | 38 assertEquals(2, a.length = 2); |
| 39 | 39 |
| 40 assertEquals(0, a[0]); | 40 assertEquals(0, a[0]); |
| 41 assertEquals(1, a[1]); | 41 assertEquals(1, a[1]); |
| 42 assertEquals('undefined', typeof a[2]); | 42 assertEquals('undefined', typeof a[2]); |
| 43 assertEquals('undefined', typeof a[3]); | 43 assertEquals('undefined', typeof a[3]); |
| 44 | 44 |
| 45 | 45 |
| 46 var a = new Array(); | 46 var a = new Array(); |
| 47 a[0] = 0; | 47 a[0] = 0; |
| 48 a[1000] = 1000; | 48 a[1000] = 1000; |
| 49 a[1000000] = 1000000; | 49 a[1000000] = 1000000; |
| 50 a[2000000] = 2000000; | 50 a[2000000] = 2000000; |
| 51 | 51 |
| 52 assertEquals(2000001, a.length); | 52 assertEquals(2000001, a.length); |
| 53 a.length = 0; | 53 assertEquals(0, a.length = 0); |
| 54 assertEquals(0, a.length); | 54 assertEquals(0, a.length); |
| 55 assertEquals('undefined', typeof a[0]); | 55 assertEquals('undefined', typeof a[0]); |
| 56 assertEquals('undefined', typeof a[1000]); | 56 assertEquals('undefined', typeof a[1000]); |
| 57 assertEquals('undefined', typeof a[1000000]); | 57 assertEquals('undefined', typeof a[1000000]); |
| 58 assertEquals('undefined', typeof a[2000000]); | 58 assertEquals('undefined', typeof a[2000000]); |
| 59 | 59 |
| 60 | 60 |
| 61 var a = new Array(); | 61 var a = new Array(); |
| 62 a[0] = 0; | 62 a[0] = 0; |
| 63 a[1000] = 1000; | 63 a[1000] = 1000; |
| 64 a[1000000] = 1000000; | 64 a[1000000] = 1000000; |
| 65 a[2000000] = 2000000; | 65 a[2000000] = 2000000; |
| 66 | 66 |
| 67 assertEquals(2000001, a.length); | 67 assertEquals(2000001, a.length); |
| 68 a.length = 2000; | 68 assertEquals(2000, a.length = 2000); |
| 69 assertEquals(2000, a.length); | 69 assertEquals(2000, a.length); |
| 70 assertEquals(0, a[0]); | 70 assertEquals(0, a[0]); |
| 71 assertEquals(1000, a[1000]); | 71 assertEquals(1000, a[1000]); |
| 72 assertEquals('undefined', typeof a[1000000]); | 72 assertEquals('undefined', typeof a[1000000]); |
| 73 assertEquals('undefined', typeof a[2000000]); | 73 assertEquals('undefined', typeof a[2000000]); |
| 74 | 74 |
| 75 | 75 |
| 76 var a = new Array(); | 76 var a = new Array(); |
| 77 a[Math.pow(2,31)-1] = 0; | 77 a[Math.pow(2,31)-1] = 0; |
| 78 a[Math.pow(2,30)-1] = 0; | 78 a[Math.pow(2,30)-1] = 0; |
| 79 assertEquals(Math.pow(2,31), a.length); | 79 assertEquals(Math.pow(2,31), a.length); |
| 80 | 80 |
| 81 | 81 |
| 82 var a = new Array(); | 82 var a = new Array(); |
| 83 a[0] = 0; | 83 a[0] = 0; |
| 84 a[1000] = 1000; | 84 a[1000] = 1000; |
| 85 a[Math.pow(2,30)-1] = Math.pow(2,30)-1; | 85 a[Math.pow(2,30)-1] = Math.pow(2,30)-1; |
| 86 a[Math.pow(2,31)-1] = Math.pow(2,31)-1; | 86 a[Math.pow(2,31)-1] = Math.pow(2,31)-1; |
| 87 a[Math.pow(2,32)-2] = Math.pow(2,32)-2; | 87 a[Math.pow(2,32)-2] = Math.pow(2,32)-2; |
| 88 | 88 |
| 89 assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]); | 89 assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]); |
| 90 assertEquals(Math.pow(2,31)-1, a[Math.pow(2,31)-1]); | 90 assertEquals(Math.pow(2,31)-1, a[Math.pow(2,31)-1]); |
| 91 assertEquals(Math.pow(2,32)-2, a[Math.pow(2,32)-2]); | 91 assertEquals(Math.pow(2,32)-2, a[Math.pow(2,32)-2]); |
| 92 | 92 |
| 93 assertEquals(Math.pow(2,32)-1, a.length); | 93 assertEquals(Math.pow(2,32)-1, a.length); |
| 94 a.length = Math.pow(2,30)+1; // not a smi! | 94 assertEquals(Math.pow(2,30) + 1, a.length = Math.pow(2,30)+1); // not a smi! |
| 95 assertEquals(Math.pow(2,30)+1, a.length); | 95 assertEquals(Math.pow(2,30)+1, a.length); |
| 96 | 96 |
| 97 assertEquals(0, a[0]); | 97 assertEquals(0, a[0]); |
| 98 assertEquals(1000, a[1000]); | 98 assertEquals(1000, a[1000]); |
| 99 assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]); | 99 assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]); |
| 100 assertEquals('undefined', typeof a[Math.pow(2,31)-1]); | 100 assertEquals('undefined', typeof a[Math.pow(2,31)-1]); |
| 101 assertEquals('undefined', typeof a[Math.pow(2,32)-2], "top"); | 101 assertEquals('undefined', typeof a[Math.pow(2,32)-2], "top"); |
| 102 | 102 |
| 103 | 103 |
| 104 var a = new Array(); | 104 var a = new Array(); |
| 105 a.length = new Number(12); | 105 assertEquals(12, a.length = new Number(12)); |
| 106 assertEquals(12, a.length); | 106 assertEquals(12, a.length); |
| 107 | 107 |
| 108 | 108 |
| 109 var o = { length: -23 }; | 109 var o = { length: -23 }; |
| 110 Array.prototype.pop.apply(o); | 110 Array.prototype.pop.apply(o); |
| 111 assertEquals(4294967272, o.length); | 111 assertEquals(4294967272, o.length); |
| 112 |
| 113 // Check case of compiled stubs. |
| 114 var a = []; |
| 115 for (var i = 0; i < 7; i++) { |
| 116 assertEquals(3, a.length = 3); |
| 117 |
| 118 var t = 239; |
| 119 t = a.length = 7; |
| 120 assertEquals(7, t); |
| 121 } |
| OLD | NEW |