| 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 array = [1,2,3,1,2,3,1,2,3,1,2,3]; | 28 var array = [1,2,3,1,2,3,1,2,3,1,2,3]; |
| 29 var undef_array = [0,,2,undefined,4,,6,undefined,8,,10]; | 29 var undef_array = [0,,2,undefined,4,,6,undefined,8,,10]; |
| 30 // Sparse arrays with lenght 42000. | 30 // Sparse arrays with length 42000. |
| 31 var sparse_array = []; | 31 var sparse_array = []; |
| 32 sparse_array[100] = 3; | 32 sparse_array[100] = 3; |
| 33 sparse_array[200] = undefined; | 33 sparse_array[200] = undefined; |
| 34 sparse_array[300] = 4; | 34 sparse_array[300] = 4; |
| 35 sparse_array[400] = 5; | 35 sparse_array[400] = 5; |
| 36 sparse_array[500] = 6; | 36 sparse_array[500] = 6; |
| 37 sparse_array[600] = 5; | 37 sparse_array[600] = 5; |
| 38 sparse_array[700] = 4; | 38 sparse_array[700] = 4; |
| 39 sparse_array[800] = undefined; | 39 sparse_array[800] = undefined; |
| 40 sparse_array[900] = 3 | 40 sparse_array[900] = 3 |
| 41 sparse_array[41999] = "filler"; | 41 sparse_array[41999] = "filler"; |
| 42 | 42 |
| 43 var dense_object = { 0: 42, 1: 37, length: 2 }; |
| 44 var sparse_object = { 0: 42, 100000: 37, length: 200000 }; |
| 45 var funky_object = { 10:42, 100000: 42, 100001: 37, length: 50000 }; |
| 46 var infinite_object = { 10: 42, 100000: 37, length: Infinity }; |
| 47 |
| 43 // ---------------------------------------------------------------------- | 48 // ---------------------------------------------------------------------- |
| 44 // Array.prototype.indexOf. | 49 // Array.prototype.indexOf. |
| 45 // ---------------------------------------------------------------------- | 50 // ---------------------------------------------------------------------- |
| 46 | 51 |
| 47 // Negative cases. | 52 // Negative cases. |
| 48 assertEquals(-1, [].indexOf(1)); | 53 assertEquals(-1, [].indexOf(1)); |
| 49 assertEquals(-1, array.indexOf(4)); | 54 assertEquals(-1, array.indexOf(4)); |
| 50 assertEquals(-1, array.indexOf(3, array.length)); | 55 assertEquals(-1, array.indexOf(3, array.length)); |
| 51 | 56 |
| 52 assertEquals(2, array.indexOf(3)); | 57 assertEquals(2, array.indexOf(3)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 assertEquals(700, sparse_array.indexOf(4, 301 - 42000)); | 91 assertEquals(700, sparse_array.indexOf(4, 301 - 42000)); |
| 87 assertEquals(-1, sparse_array.indexOf(4, 701 - 42000)); | 92 assertEquals(-1, sparse_array.indexOf(4, 701 - 42000)); |
| 88 | 93 |
| 89 assertEquals(200, sparse_array.indexOf(undefined)); | 94 assertEquals(200, sparse_array.indexOf(undefined)); |
| 90 assertEquals(800, sparse_array.indexOf(undefined, 201)); | 95 assertEquals(800, sparse_array.indexOf(undefined, 201)); |
| 91 assertEquals(-1, sparse_array.indexOf(undefined, 801)); | 96 assertEquals(-1, sparse_array.indexOf(undefined, 801)); |
| 92 assertEquals(200, sparse_array.indexOf(undefined, -42000)); | 97 assertEquals(200, sparse_array.indexOf(undefined, -42000)); |
| 93 assertEquals(800, sparse_array.indexOf(undefined, 201 - 42000)); | 98 assertEquals(800, sparse_array.indexOf(undefined, 201 - 42000)); |
| 94 assertEquals(-1, sparse_array.indexOf(undefined, 801 - 42000)); | 99 assertEquals(-1, sparse_array.indexOf(undefined, 801 - 42000)); |
| 95 | 100 |
| 101 // Find in non-arrays. |
| 102 assertEquals(0, Array.prototype.indexOf.call(dense_object, 42)); |
| 103 assertEquals(1, Array.prototype.indexOf.call(dense_object, 37)); |
| 104 assertEquals(-1, Array.prototype.indexOf.call(dense_object, 87)); |
| 105 |
| 106 assertEquals(0, Array.prototype.indexOf.call(sparse_object, 42)); |
| 107 assertEquals(100000, Array.prototype.indexOf.call(sparse_object, 37)); |
| 108 assertEquals(-1, Array.prototype.indexOf.call(sparse_object, 87)); |
| 109 |
| 110 assertEquals(10, Array.prototype.indexOf.call(funky_object, 42)); |
| 111 assertEquals(-1, Array.prototype.indexOf.call(funky_object, 42, 15)); |
| 112 assertEquals(-1, Array.prototype.indexOf.call(funky_object, 37)); |
| 113 |
| 114 assertEquals(-1, Array.prototype.indexOf.call(infinite_object, 42)); |
| 96 | 115 |
| 97 // ---------------------------------------------------------------------- | 116 // ---------------------------------------------------------------------- |
| 98 // Array.prototype.lastIndexOf. | 117 // Array.prototype.lastIndexOf. |
| 99 // ---------------------------------------------------------------------- | 118 // ---------------------------------------------------------------------- |
| 100 | 119 |
| 101 // Negative cases. | 120 // Negative cases. |
| 102 assertEquals(-1, [].lastIndexOf(1)); | 121 assertEquals(-1, [].lastIndexOf(1)); |
| 103 assertEquals(-1, array.lastIndexOf(1, -17)); | 122 assertEquals(-1, array.lastIndexOf(1, -17)); |
| 104 | 123 |
| 105 assertEquals(9, array.lastIndexOf(1)); | 124 assertEquals(9, array.lastIndexOf(1)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 assertEquals(700, sparse_array.lastIndexOf(4, -1)); | 157 assertEquals(700, sparse_array.lastIndexOf(4, -1)); |
| 139 assertEquals(300, sparse_array.lastIndexOf(4, 699 - 42000)); | 158 assertEquals(300, sparse_array.lastIndexOf(4, 699 - 42000)); |
| 140 assertEquals(-1, sparse_array.lastIndexOf(4, 299 - 42000)); | 159 assertEquals(-1, sparse_array.lastIndexOf(4, 299 - 42000)); |
| 141 | 160 |
| 142 assertEquals(800, sparse_array.lastIndexOf(undefined)); | 161 assertEquals(800, sparse_array.lastIndexOf(undefined)); |
| 143 assertEquals(200, sparse_array.lastIndexOf(undefined, 799)); | 162 assertEquals(200, sparse_array.lastIndexOf(undefined, 799)); |
| 144 assertEquals(-1, sparse_array.lastIndexOf(undefined, 199)); | 163 assertEquals(-1, sparse_array.lastIndexOf(undefined, 199)); |
| 145 assertEquals(800, sparse_array.lastIndexOf(undefined, -1)); | 164 assertEquals(800, sparse_array.lastIndexOf(undefined, -1)); |
| 146 assertEquals(200, sparse_array.lastIndexOf(undefined, 799 - 42000)); | 165 assertEquals(200, sparse_array.lastIndexOf(undefined, 799 - 42000)); |
| 147 assertEquals(-1, sparse_array.lastIndexOf(undefined, 199 - 42000)); | 166 assertEquals(-1, sparse_array.lastIndexOf(undefined, 199 - 42000)); |
| 167 |
| 168 assertEquals(0, Array.prototype.lastIndexOf.call(dense_object, 42)); |
| 169 assertEquals(1, Array.prototype.lastIndexOf.call(dense_object, 37)); |
| 170 assertEquals(0, Array.prototype.lastIndexOf.call(sparse_object, 42)); |
| 171 assertEquals(100000, Array.prototype.lastIndexOf.call(sparse_object, 37)); |
| 172 |
| 173 //Find in non-arrays. |
| 174 assertEquals(0, Array.prototype.lastIndexOf.call(dense_object, 42)); |
| 175 assertEquals(1, Array.prototype.lastIndexOf.call(dense_object, 37)); |
| 176 assertEquals(-1, Array.prototype.lastIndexOf.call(dense_object, 87)); |
| 177 |
| 178 assertEquals(0, Array.prototype.lastIndexOf.call(sparse_object, 42)); |
| 179 assertEquals(100000, Array.prototype.lastIndexOf.call(sparse_object, 37)); |
| 180 assertEquals(-1, Array.prototype.lastIndexOf.call(sparse_object, 87)); |
| 181 |
| 182 assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42, 15)); |
| 183 assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42)); |
| 184 assertEquals(-1, Array.prototype.lastIndexOf.call(funky_object, 37)); |
| 185 |
| 186 assertEquals(-1, Array.prototype.lastIndexOf.call(infinite_object, 42)); |
| OLD | NEW |