Skip to content

Commit

Permalink
[expo] Fix crash on v8 (#19843)
Browse files Browse the repository at this point in the history
# Why

react-native-v8 app will crash on sdk 47 app

# How

the `NativeModules` is a host object, and in react-native-v8, there are some internal data structures for a host object. after monkey patching the `NativeModules`, it is now a proxy object. from the `Reflect.get(target, prop, receiver)` call, it will use host object getter but pass the proxy object (not the original host object). the crash happens at [the react-native-v8 code here](https://github.com/Kudo/react-native-v8/blob/4821e303cf18d745d884510740a45a449afc1ec6/src/v8runtime/HostProxy.cpp#L32-L40)

we don't return something else from the proxied interceptor; using `target[prop]` is enough.

# Test Plan

create a v8 app and patch _node_modules/expo/build/proxies/NativeModules.js_
  • Loading branch information
Kudo committed Nov 3, 2022
1 parent cb30a98 commit daec5fc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/expo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### 🐛 Bug fixes

- Showing warnings for missing native modules rather than throwing errors. ([#19845](https://github.com/expo/expo/pull/19845) by [@kudo](https://github.com/kudo))
- Fixed crashes when running on react-native-v8 runtime. ([#19843](https://github.com/expo/expo/pull/19843) by [@kudo](https://github.com/kudo))

### 💡 Others

Expand Down
4 changes: 2 additions & 2 deletions packages/expo/build/proxies/NativeModules.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo/build/proxies/NativeModules.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/expo/src/proxies/NativeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export function createProxyForNativeModules(NativeModules: any) {
return NativeModules;
}
return new Proxy(NativeModules, {
get(target, prop, receiver) {
const value = Reflect.get(target, prop, receiver);
get(target, prop) {
const value = target[prop];
if (
enabled &&
typeof prop !== 'symbol' &&
Expand Down

0 comments on commit daec5fc

Please sign in to comment.