Commit 5ee4f7e
committed
fix[describeClassComponentFrame]: invoke constructor with new keyword (facebook#36455)
For JavaScript runtimes that do not have
[`Reflect`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect)
supported, we had a fall back that was calling the constructor with
overridden `this` context via
```
fn.apply(Fake.prototype);
```
In ES6, it is required to call constructor only with the `new` keyword,
otherwise the runtime is expected to throw a corresponding TypeError:
```
TypeError: Class constructor <> cannot be invoked without 'new'
```
We've observed this error in Hermes runtime, but this is applicable to
V8 or any other runtime. The only reason why V8 wasn't affected is
because it implemented Reflect APIs.
Instead of the incorrect call, we will fall back to calling `new fn()`,
but with a temporary patched prototype of the class, which would make a
trap out of the setter for `props` object. We use the same approach when
`Reflect` APIs are available, but instead of modifying the prototype, we
pass the fake context:
https://github.com/facebook/react/blob/d5736f098edee62c44f27b053e6e48f5fa443803/packages/shared/ReactComponentStackFrame.js#L129-L148
---
See tests implemented. Without the changes, the test would fail with the
`TypeError` mentioned above.
DiffTrain build for [8fc5763](facebook@8fc5763)1 parent 9f3e8fb commit 5ee4f7e
21 files changed
Lines changed: 328 additions & 84 deletions
File tree
- compiled-rn
- facebook-fbsource/xplat/js
- RKJSModules/vendor/react
- react-dom/cjs
- react-test-renderer/cjs
- react/cjs
- react-native-github/Libraries/Renderer
- implementations
- tools/eslint-plugin-react-hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | | - | |
| 413 | + | |
414 | 414 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
Lines changed: 30 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
719 | 719 | | |
720 | 720 | | |
721 | 721 | | |
722 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
723 | 746 | | |
724 | 747 | | |
725 | 748 | | |
| |||
31927 | 31950 | | |
31928 | 31951 | | |
31929 | 31952 | | |
31930 | | - | |
| 31953 | + | |
31931 | 31954 | | |
31932 | 31955 | | |
31933 | 31956 | | |
31934 | | - | |
| 31957 | + | |
31935 | 31958 | | |
31936 | 31959 | | |
31937 | 31960 | | |
| |||
31968 | 31991 | | |
31969 | 31992 | | |
31970 | 31993 | | |
31971 | | - | |
| 31994 | + | |
31972 | 31995 | | |
31973 | 31996 | | |
31974 | | - | |
| 31997 | + | |
31975 | 31998 | | |
31976 | 31999 | | |
31977 | 32000 | | |
| |||
32121 | 32144 | | |
32122 | 32145 | | |
32123 | 32146 | | |
32124 | | - | |
| 32147 | + | |
32125 | 32148 | | |
Lines changed: 26 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
547 | 566 | | |
548 | 567 | | |
549 | 568 | | |
| |||
19114 | 19133 | | |
19115 | 19134 | | |
19116 | 19135 | | |
19117 | | - | |
| 19136 | + | |
19118 | 19137 | | |
19119 | 19138 | | |
19120 | 19139 | | |
19121 | 19140 | | |
19122 | 19141 | | |
19123 | 19142 | | |
19124 | | - | |
| 19143 | + | |
19125 | 19144 | | |
19126 | 19145 | | |
19127 | 19146 | | |
| |||
19143 | 19162 | | |
19144 | 19163 | | |
19145 | 19164 | | |
19146 | | - | |
| 19165 | + | |
19147 | 19166 | | |
19148 | 19167 | | |
19149 | | - | |
| 19168 | + | |
19150 | 19169 | | |
19151 | 19170 | | |
19152 | 19171 | | |
| |||
19253 | 19272 | | |
19254 | 19273 | | |
19255 | 19274 | | |
19256 | | - | |
| 19275 | + | |
Lines changed: 26 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
547 | 566 | | |
548 | 567 | | |
549 | 568 | | |
| |||
21176 | 21195 | | |
21177 | 21196 | | |
21178 | 21197 | | |
21179 | | - | |
| 21198 | + | |
21180 | 21199 | | |
21181 | 21200 | | |
21182 | 21201 | | |
21183 | 21202 | | |
21184 | 21203 | | |
21185 | 21204 | | |
21186 | | - | |
| 21205 | + | |
21187 | 21206 | | |
21188 | 21207 | | |
21189 | 21208 | | |
| |||
21205 | 21224 | | |
21206 | 21225 | | |
21207 | 21226 | | |
21208 | | - | |
| 21227 | + | |
21209 | 21228 | | |
21210 | 21229 | | |
21211 | | - | |
| 21230 | + | |
21212 | 21231 | | |
21213 | 21232 | | |
21214 | 21233 | | |
| |||
21331 | 21350 | | |
21332 | 21351 | | |
21333 | 21352 | | |
21334 | | - | |
| 21353 | + | |
Lines changed: 30 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
727 | 727 | | |
728 | 728 | | |
729 | 729 | | |
730 | | - | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
731 | 754 | | |
732 | 755 | | |
733 | 756 | | |
| |||
31989 | 32012 | | |
31990 | 32013 | | |
31991 | 32014 | | |
31992 | | - | |
| 32015 | + | |
31993 | 32016 | | |
31994 | 32017 | | |
31995 | 32018 | | |
31996 | | - | |
| 32019 | + | |
31997 | 32020 | | |
31998 | 32021 | | |
31999 | 32022 | | |
| |||
32030 | 32053 | | |
32031 | 32054 | | |
32032 | 32055 | | |
32033 | | - | |
| 32056 | + | |
32034 | 32057 | | |
32035 | 32058 | | |
32036 | | - | |
| 32059 | + | |
32037 | 32060 | | |
32038 | 32061 | | |
32039 | 32062 | | |
| |||
32499 | 32522 | | |
32500 | 32523 | | |
32501 | 32524 | | |
32502 | | - | |
| 32525 | + | |
32503 | 32526 | | |
32504 | 32527 | | |
32505 | 32528 | | |
| |||
0 commit comments