sbarati@apple.com | 23315d6 | 2016-05-09 20:17:23 +0000 | [diff] [blame] | 1 | function assert(b, m = "Bad!") { |
| 2 | if (!b) { |
| 3 | throw new Error(m); |
| 4 | } |
| 5 | } |
| 6 | |
| 7 | function test(f, iters = 1000) { |
| 8 | for (let i = 0; i < iters; i++) |
| 9 | f(); |
| 10 | } |
| 11 | |
| 12 | test(function() { |
| 13 | function fooProp() { return 'foo'; } |
| 14 | noInline(fooProp); |
| 15 | |
| 16 | let shouldThrow = false; |
| 17 | class A { |
| 18 | get foo() { |
| 19 | if (shouldThrow) |
| 20 | throw new Error; |
| 21 | return 20; |
| 22 | } |
| 23 | get x() { return this._x; } |
| 24 | } |
| 25 | |
| 26 | class B extends A { |
| 27 | constructor(x) { |
| 28 | super(); |
| 29 | this._x = x; |
| 30 | } |
| 31 | |
| 32 | bar() { |
| 33 | this._x = super.foo; |
| 34 | } |
| 35 | |
| 36 | baz() { |
| 37 | this._x = super[fooProp()]; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | function foo(i) { |
| 42 | let b = new B(i); |
| 43 | noInline(b.__lookupGetter__('foo')); |
| 44 | let threw = false; |
| 45 | try { |
| 46 | b.bar(); |
| 47 | } catch(e) { |
| 48 | threw = true; |
| 49 | } |
| 50 | if (threw) |
| 51 | assert(b.x === i); |
| 52 | else |
| 53 | assert(b.x === 20); |
| 54 | } |
| 55 | function bar(i) { |
| 56 | let b = new B(i); |
| 57 | noInline(b.__lookupGetter__('foo')); |
| 58 | let threw = false; |
| 59 | try { |
| 60 | b.baz(); |
| 61 | } catch(e) { |
| 62 | threw = true; |
| 63 | } |
| 64 | if (threw) |
| 65 | assert(b.x === i); |
| 66 | else |
| 67 | assert(b.x === 20, "b.x " + b.x + " " + i); |
| 68 | } |
| 69 | noInline(bar); |
| 70 | |
| 71 | for (let i = 0; i < 10000; i++) { |
| 72 | foo(i); |
| 73 | bar(i); |
| 74 | } |
| 75 | shouldThrow = true; |
| 76 | foo(23); |
| 77 | bar(24); |
| 78 | |
| 79 | }, 1); |
| 80 | |
| 81 | test(function() { |
| 82 | function fooProp() { return 'foo'; } |
| 83 | noInline(fooProp); |
| 84 | |
| 85 | function func(i) { |
| 86 | if (shouldThrow) |
| 87 | throw new Error(); |
| 88 | return i; |
| 89 | } |
| 90 | noInline(func); |
| 91 | |
| 92 | let shouldThrow = false; |
| 93 | class A { |
| 94 | set foo(x) { |
| 95 | this._x = x; |
| 96 | } |
| 97 | get x() { return this._x; } |
| 98 | } |
| 99 | |
| 100 | class B extends A { |
| 101 | constructor(x) { |
| 102 | super(); |
| 103 | this._x = x; |
| 104 | } |
| 105 | |
| 106 | bar(x) { |
| 107 | super.foo = func(x); |
| 108 | } |
| 109 | |
| 110 | baz(x) { |
| 111 | super[fooProp()] = func(x); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | function foo(i) { |
| 116 | let b = new B(i); |
| 117 | noInline(b.__lookupGetter__('foo')); |
| 118 | let threw = false; |
| 119 | try { |
| 120 | b.bar(i + 1); |
| 121 | } catch(e) { |
| 122 | threw = true; |
| 123 | } |
| 124 | if (threw) |
| 125 | assert(b.x === i); |
| 126 | else |
| 127 | assert(b.x === i + 1); |
| 128 | } |
| 129 | function bar(i) { |
| 130 | let b = new B(i); |
| 131 | noInline(b.__lookupGetter__('foo')); |
| 132 | let threw = false; |
| 133 | try { |
| 134 | b.baz(i + 1); |
| 135 | } catch(e) { |
| 136 | threw = true; |
| 137 | } |
| 138 | if (threw) |
| 139 | assert(b.x === i); |
| 140 | else |
| 141 | assert(b.x === i + 1); |
| 142 | } |
| 143 | noInline(bar); |
| 144 | |
| 145 | for (let i = 0; i < 10000; i++) { |
| 146 | foo(i); |
| 147 | bar(i); |
| 148 | } |
| 149 | shouldThrow = true; |
| 150 | foo(23); |
| 151 | bar(24); |
| 152 | |
| 153 | }, 1); |