utatane.tea@gmail.com | b711316 | 2017-12-18 11:49:33 +0000 | [diff] [blame] | 1 | function assert(b) { |
| 2 | if (!b) |
| 3 | throw new Error("Bad assertion!"); |
| 4 | } |
| 5 | noInline(assert); |
| 6 | |
| 7 | let value = false; |
| 8 | |
| 9 | function baz(x) { |
| 10 | if (typeof x !== "number") { |
| 11 | value = true; |
| 12 | } |
| 13 | return x; |
| 14 | } |
| 15 | noInline(baz); |
| 16 | |
| 17 | function bar(...args) { |
| 18 | return args; |
| 19 | } |
| 20 | |
| 21 | let didEffects = false; |
| 22 | function effects() { didEffects = true; } |
| 23 | noInline(effects); |
| 24 | |
| 25 | function foo(a) { |
| 26 | let args = [1]; |
| 27 | let theArgs = [...args, a, ...args]; |
| 28 | baz(a); |
| 29 | if (value) { |
| 30 | effects(); |
| 31 | } |
| 32 | let r = bar.apply(null, theArgs); |
| 33 | return r; |
| 34 | } |
| 35 | noInline(foo); |
| 36 | |
| 37 | for (let i = 0; i < 100000; i++) { |
| 38 | foo(i); |
| 39 | assert(!didEffects); |
| 40 | } |
| 41 | let o = {}; |
| 42 | let [a, b, c] = foo(o); |
| 43 | assert(a === 1); |
| 44 | assert(b === o); |
| 45 | assert(c === 1); |
| 46 | assert(didEffects); |