OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 | 28 // Flags: --optimize-for-in --allow-natives-syntax |
29 | 29 |
30 // Test for-in support in Crankshaft. For simplicity this tests assumes certain | 30 // Test for-in support in Crankshaft. For simplicity this tests assumes certain |
31 // fixed iteration order for properties and will have to be adjusted if V8 | 31 // fixed iteration order for properties and will have to be adjusted if V8 |
32 // stops following insertion order. | 32 // stops following insertion order. |
33 | 33 |
34 | 34 |
35 function a(t) { | 35 function a(t) { |
36 var result = []; | 36 var result = []; |
37 for (var i in t) { | 37 for (var i in t) { |
38 result.push(i + t[i]); | 38 result.push(i + t[i]); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 }, function (t) { | 240 }, function (t) { |
241 var r = []; | 241 var r = []; |
242 for (var i in t) r.push(i + t[i]); | 242 for (var i in t) r.push(i + t[i]); |
243 return r.join(''); | 243 return r.join(''); |
244 }); | 244 }); |
245 | 245 |
246 // Test OSR inside for-in. | 246 // Test OSR inside for-in. |
247 function osr_inner(t, limit) { | 247 function osr_inner(t, limit) { |
248 var r = 1; | 248 var r = 1; |
249 for (var x in t) { | 249 for (var x in t) { |
250 for (var i = 0; i < t[x].length; i++) { | 250 if (t.hasOwnProperty(x)) { |
251 r += t[x][i]; | 251 for (var i = 0; i < t[x].length; i++) { |
252 if (i === limit) { | 252 » r += t[x][i]; |
fschneider
2012/02/27 13:53:06
Replace \t with spaces.
| |
253 %OptimizeFunctionOnNextCall(osr_inner, "osr"); | 253 » if (i === limit) { |
254 %OptimizeFunctionOnNextCall(osr_inner, "osr"); | |
255 » } | |
254 } | 256 } |
257 r += x; | |
255 } | 258 } |
256 r += x; | |
257 } | 259 } |
258 return r; | 260 return r; |
259 } | 261 } |
260 | 262 |
261 function osr_outer(t, osr_after) { | 263 function osr_outer(t, osr_after) { |
262 var r = 1; | 264 var r = 1; |
263 for (var x in t) { | 265 for (var x in t) { |
264 for (var i = 0; i < t[x].length; i++) { | 266 for (var i = 0; i < t[x].length; i++) { |
265 r += t[x][i]; | 267 r += t[x][i]; |
266 } | 268 } |
(...skipping 16 matching lines...) Expand all Loading... | |
283 return r; | 285 return r; |
284 } | 286 } |
285 | 287 |
286 function test_osr() { | 288 function test_osr() { |
287 with ({}) {} // Disable optimizations of this function. | 289 with ({}) {} // Disable optimizations of this function. |
288 var arr = new Array(20); | 290 var arr = new Array(20); |
289 for (var i = 0; i < arr.length; i++) { | 291 for (var i = 0; i < arr.length; i++) { |
290 arr[i] = i + 1; | 292 arr[i] = i + 1; |
291 } | 293 } |
292 arr.push(":"); // Force deopt at the end of the loop. | 294 arr.push(":"); // Force deopt at the end of the loop. |
293 assertEquals("211:x", osr_inner({x: arr}, (arr.length / 2) | 0)); | 295 assertEquals("211:x1234567891011121314151617181920:y", osr_inner({x: arr, y: a rr}, (arr.length / 2) | 0)); |
294 assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x")); | 296 assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x")); |
295 assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5")); | 297 assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5")); |
296 } | 298 } |
297 | 299 |
298 test_osr(); | 300 test_osr(); |
OLD | NEW |