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 // Flags: --allow-natives-syntax |
| 29 |
28 var s = "test test test"; | 30 var s = "test test test"; |
29 | 31 |
30 assertEquals(0, s.indexOf("t")); | 32 assertEquals(0, s.indexOf("t")); |
31 assertEquals(3, s.indexOf("t", 1)); | 33 assertEquals(3, s.indexOf("t", 1)); |
32 assertEquals(5, s.indexOf("t", 4)); | 34 assertEquals(5, s.indexOf("t", 4)); |
33 assertEquals(5, s.indexOf("t", 4.1)); | 35 assertEquals(5, s.indexOf("t", 4.1)); |
34 assertEquals(0, s.indexOf("t", 0)); | 36 assertEquals(0, s.indexOf("t", 0)); |
35 assertEquals(0, s.indexOf("t", -1)); | 37 assertEquals(0, s.indexOf("t", -1)); |
36 assertEquals(0, s.indexOf("t", -1)); | 38 assertEquals(0, s.indexOf("t", -1)); |
37 assertEquals(0, s.indexOf("t", -1.1)); | 39 assertEquals(0, s.indexOf("t", -1.1)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 })(); | 200 })(); |
199 | 201 |
200 (function nonStringPosition() { | 202 (function nonStringPosition() { |
201 assertEquals(0, "aba".indexOf("a", false)); | 203 assertEquals(0, "aba".indexOf("a", false)); |
202 assertEquals(2, "aba".indexOf("a", true)); | 204 assertEquals(2, "aba".indexOf("a", true)); |
203 assertEquals(2, "aba".indexOf("a", "1")); | 205 assertEquals(2, "aba".indexOf("a", "1")); |
204 assertEquals(2, "aba".indexOf("a", "1.00000")); | 206 assertEquals(2, "aba".indexOf("a", "1.00000")); |
205 assertEquals(2, "aba".indexOf("a", "2.00000")); | 207 assertEquals(2, "aba".indexOf("a", "2.00000")); |
206 assertEquals(-1, "aba".indexOf("a", "3.00000")); | 208 assertEquals(-1, "aba".indexOf("a", "3.00000")); |
207 })(); | 209 })(); |
| 210 |
| 211 (function optimize() { |
| 212 function f() { |
| 213 return 'abc'.indexOf('a'); |
| 214 } |
| 215 assertEquals(0, f()); |
| 216 assertEquals(0, f()); |
| 217 assertEquals(0, f()); |
| 218 % OptimizeFunctionOnNextCall(f); |
| 219 assertEquals(0, f()); |
| 220 |
| 221 function f2() { |
| 222 return 'abc'.indexOf('a', 1); |
| 223 } |
| 224 assertEquals(-1, f2()); |
| 225 assertEquals(-1, f2()); |
| 226 assertEquals(-1, f2()); |
| 227 % OptimizeFunctionOnNextCall(f2); |
| 228 assertEquals(-1, f2()); |
| 229 |
| 230 function f3() { |
| 231 return 'abc'.indexOf('a'); |
| 232 } |
| 233 assertEquals(0, f3()); |
| 234 assertEquals(0, f3()); |
| 235 assertEquals(0, f3()); |
| 236 % OptimizeFunctionOnNextCall(f3); |
| 237 assertEquals(0, f3()); |
| 238 |
| 239 function f4() { |
| 240 return 'abcbc'.indexOf('bc', 2); |
| 241 } |
| 242 assertEquals(3, f4()); |
| 243 assertEquals(3, f4()); |
| 244 assertEquals(3, f4()); |
| 245 % OptimizeFunctionOnNextCall(f4); |
| 246 assertEquals(3, f4()); |
| 247 })(); |
| 248 |
| 249 (function optimizeOSR() { |
| 250 function f() { |
| 251 var result; |
| 252 for (var i = 0; i < 100000; i++) { |
| 253 result = 'abc'.indexOf('a'); |
| 254 } |
| 255 return result; |
| 256 } |
| 257 assertEquals(0, f()); |
| 258 |
| 259 function f2() { |
| 260 var result; |
| 261 for (var i = 0; i < 100000; i++) { |
| 262 result = 'abc'.indexOf('a', 1); |
| 263 } |
| 264 return result; |
| 265 } |
| 266 assertEquals(-1, f2()); |
| 267 |
| 268 function f3() { |
| 269 var result; |
| 270 for (var i = 0; i < 100000; i++) { |
| 271 result = 'abc'.indexOf('a'); |
| 272 } |
| 273 return result; |
| 274 } |
| 275 assertEquals(0, f3()); |
| 276 |
| 277 function f4() { |
| 278 var result; |
| 279 for (var i = 0; i < 100000; i++) { |
| 280 result = 'abcbc'.indexOf('bc', 2); |
| 281 } |
| 282 return result; |
| 283 } |
| 284 assertEquals(3, f4()); |
| 285 })(); |
OLD | NEW |