Commit 87249a1
committed
[MERGE #5914 @boingoing] Class members which capture super via dot (super.constructor) end up getting the wrong value
Merge pull request #5914 from boingoing:super_capture_ts
Class members which capture super via dot (super.constructor) end up getting the wrong value
We were using the wrong bytecode register when emitting LdHomeObjProto in the case of a lambda capturing super via a dot reference. Consider this Javascript:
```javascript
class A { }
class B extends A {
foo() {
const _s = () => super.constructor;
console.log(_s().name);
}
}
```
The member function foo correctly stashes this and super but the lambda needs to load them from the environment and it was loading them into the same register. Here's the incorrect bytecode:
```
Function _s ( (#1.5), #6) (In0) (size: 8 [8])
5 locals (2 temps from R3), 1 inline cache
Constant Table:
======== =====
R1 LdRoot
Line 13: super.constructor
Col 26: ^
0000 ProfiledLdEnvSlot R3 = [1][2] <0>
0006 ProfiledLdEnvSlot R3 = [1][3] <1>
000c LdHomeObjProto R4 R3
0011 ProfiledLdSuperFld R0 = R4(this=R3). #0 <0>
0019 Br x:001e ( 2)
001c LdUndef R0
```
With the fix in this PR, here's the bytecode we get for _s:
```
Function _s ( (#1.5), #6) (In0) (size: 8 [8])
6 locals (3 temps from R3), 1 inline cache
Constant Table:
======== =====
R1 LdRoot
Line 56: super.constructor
Col 26: ^
0000 ProfiledLdEnvSlot R3 = [1][2] <0>
0006 ProfiledLdEnvSlot R4 = [1][3] <1>
000c LdHomeObjProto R5 R3
0011 ProfiledLdSuperFld R0 = R5(this=R4). #0 <0>
0019 Br x:001e ( 2)
001c LdUndef R0
```File tree
3 files changed
+1613
-1532
lines changed- lib/Runtime/ByteCode
- test/es6
3 files changed
+1613
-1532
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10833 | 10833 | | |
10834 | 10834 | | |
10835 | 10835 | | |
10836 | | - | |
10837 | | - | |
10838 | | - | |
10839 | 10836 | | |
10840 | 10837 | | |
10841 | 10838 | | |
10842 | 10839 | | |
| 10840 | + | |
| 10841 | + | |
| 10842 | + | |
| 10843 | + | |
| 10844 | + | |
| 10845 | + | |
| 10846 | + | |
| 10847 | + | |
| 10848 | + | |
| 10849 | + | |
| 10850 | + | |
| 10851 | + | |
10843 | 10852 | | |
10844 | 10853 | | |
10845 | | - | |
10846 | 10854 | | |
10847 | 10855 | | |
10848 | 10856 | | |
10849 | 10857 | | |
10850 | | - | |
10851 | | - | |
10852 | | - | |
10853 | | - | |
10854 | | - | |
10855 | | - | |
10856 | | - | |
10857 | 10858 | | |
10858 | 10859 | | |
| 10860 | + | |
| 10861 | + | |
| 10862 | + | |
| 10863 | + | |
10859 | 10864 | | |
10860 | 10865 | | |
10861 | | - | |
10862 | | - | |
10863 | | - | |
10864 | | - | |
10865 | | - | |
10866 | | - | |
10867 | | - | |
10868 | | - | |
10869 | | - | |
10870 | | - | |
10871 | | - | |
10872 | | - | |
10873 | | - | |
| 10866 | + | |
10874 | 10867 | | |
10875 | 10868 | | |
10876 | 10869 | | |
| |||
0 commit comments