fpizlo@apple.com | 45e4565 | 2016-01-07 21:20:37 +0000 | [diff] [blame] | 1 | function foo(o, p) { |
| 2 | var x = 100; |
| 3 | var result = 101; |
| 4 | var pf = p.g; |
| 5 | try { |
| 6 | x = 102; |
| 7 | pf++; |
| 8 | result = o.f; |
| 9 | o = 104; |
| 10 | pf++; |
| 11 | x = 106; |
| 12 | } catch (e) { |
| 13 | return {outcome: "exception", values: [o, pf, x, result]}; |
| 14 | } |
| 15 | return {outcome: "return", values: [o, pf, x, result]}; |
| 16 | } |
| 17 | |
| 18 | noInline(foo); |
| 19 | |
| 20 | // Warm up foo() with polymorphic objects and non-object types. |
| 21 | for (var i = 0; i < 100000; ++i) { |
| 22 | var o; |
| 23 | var isObject = i & 1; |
| 24 | if (isObject) { |
| 25 | o = {f:107}; |
| 26 | o["i" + i] = i; // Make it polymorphic. |
| 27 | } else |
| 28 | o = 42; |
| 29 | var result = foo(o, {g:200}); |
| 30 | if (result.outcome !== "return") |
| 31 | throw "Error in loop: bad outcome: " + result.outcome; |
| 32 | if (result.values.length !== 4) |
| 33 | throw "Error in loop: bad number of values: " + result.values.length; |
| 34 | if (result.values[0] !== 104) |
| 35 | throw "Error in loop: bad values[0]: " + result.values[0]; |
| 36 | if (result.values[1] !== 202) |
| 37 | throw "Error in loop: bad values[1]: " + result.values[1]; |
| 38 | if (result.values[2] !== 106) |
| 39 | throw "Error in loop: bad values[2]: " + result.values[2]; |
| 40 | if (isObject) { |
| 41 | if (result.values[3] !== 107) |
| 42 | throw "Error in loop: bad values[3]: " + result.values[3]; |
| 43 | } else { |
| 44 | if (result.values[3] !== void 0) |
| 45 | throw "Error in loop: bad values[3]: " + result.values[3]; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Now throw an exception. |
| 50 | var result = foo(null, {g:300}); |
| 51 | if (result.outcome !== "exception") |
| 52 | throw "Error at end: bad outcome: " + result.outcome; |
| 53 | if (result.values.length !== 4) |
| 54 | throw "Error at end: bad number of values: " + result.values.length; |
| 55 | if (result.values[0] !== null) |
| 56 | throw "Error at end: bad values[0]: " + result.values[0]; |
| 57 | if (result.values[1] !== 301) |
| 58 | throw "Error at end: bad values[1]: " + result.values[1]; |
| 59 | if (result.values[2] !== 102) |
| 60 | throw "Error at end: bad values[2]: " + result.values[2]; |
| 61 | if (result.values[3] !== 101) |
| 62 | throw "Error at end: bad values[3]: " + result.values[3]; |
| 63 | |