mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
b145a82964
Summary:
JSIExecutor::NativeModuleProxy is an object created by JSIExecutor and essentially representing that in JavaScript world. Before this change, JSIExecutor::NativeModuleProxy had a raw reference to JSIExecutor which (I believe) caused a crash because JSIExecutor can be deallocated before JSIExecutor::NativeModuleProxy. Now, instead of storing a pointer to JSIExecutor, we store a weak pointer to JSINativeModules which we can safely validate before calling on it.
Changelog: [Internal] Fixed crash in JSIExecutor
Now the configuration looks like this:
```
+ - - - - - - - - - - - - - - - - - - - - -
Something else |
| shared_ptr<jsi::Runtime> runtime --+
| |
+ - - - - - - - - - - - - - - - - - - - - - |
|
|
+------------------------------------------+ |
| | |
| JSExecutorFactory | | +--------------------------------+-------------------------------+
| | +-----------------------+ | | |
+------------------------------------------+ | | v |
| | +------------------------------------------+ |
+--------------------------+ | | | |
| | | | ModuleRegistry | |
v | | | | |
+------------------------------------------+ | | +------------------------------------------+ |
| HermesRuntimeImpl | | | | |
| (jsi::Runtime) |--+ | | +->+------------------------------------------+ |
| | | | | | |std::unordered_map<std::string, size_t> | |
+------------------------------------------+ | | | | |modulesByName_ | |
| | | | | | |
| | | | +------------------------------------------+ |
| | | +->+------------------------------------------+ |
+-----------------------+ | | |std::vector<std::unique_ptr<NativeModule>>| |
| | | |modules_ | |
| | | | | |
v | | +------------------------------------------+ |
+------------------------------------------+ | | |
| | | | |
| JSIExecutor::NativeModuleProxy | | | |
| | | | |
+------------------------------------------+ | | |
+------------------------------------------+ | | | |
| | +->+------------------------------------------+ | | |
| NativeToJsBridge | |shared_ptr<JSINativeModules> | | | |
| | |nativeModules_ | | | |
+------------------------------------------+ +------------------------------------------+--+-----+------------------------------------+ |
| | | | |
+->+------------------------------------------+ | | | |
| |unique_ptr<JSExecutor> | | | | |
| |m_executor | | | | |
| |(`::destroy()` resets it.) | | | | |
| +------------------------------------------+--------------------------------+ | | | |
+->+------------------------------------------+ | | | | |
| |shared_ptr<JsToNativeBridge> | | | | | |
| |m_delegate | | | | | |
| +------------------------------------------+--+ v | | | |
+->+------------------------------------------+ | +------------------------------------------+ | | | |
|shared_ptr<MessageQueueThread> | | | | | | | |
|m_executorMessageQueueThread | | | HermesExecutor: JSIExecutor: JSExecutor | | | | |
+------------------------------------------+ | | | | | | |
| +------------------------------------------+ | | | |
| | | | | |
| +->+------------------------------------------+ | | | |
| | |shared_ptr<jsi::Runtime> | | | | |
| | |runtime_ | | | | |
| | +------------------------------------------+--+ | | |
| +->+------------------------------------------+ | | |
| | |shared_ptr<JSINativeModules> | | | |
| | |nativeModules_ | | | |
| | +------------------------------------------+--------+------------------------------------+ |
+--------------------------+ +->+------------------------------------------+ | | |
| |std::shared_ptr<ExecutorDelegate> | | v |
| |delegate_ | | +------------------------------------------+ |
| +------------------------------------------+--+ | | | |
| | | | JSINativeModules | |
| | | | | |
| | | +------------------------------------------+ |
| | | | |
| | | +-->+------------------------------------------+ |
+-----------------------------------------------------------------------------------+ | |m_moduleRegistry | |
| | |(shared_ptr) | |
| | +------------------------------------------+--+
| |
| |
v |
+------------------------------------------+ |
| | |
| JsToNativeBridge: ExecutorDelegate | |
| | |
+------------------------------------------+ |
| |
+->+------------------------------------------+ |
|shared_ptr<ModuleRegistry> | |
|m_registry | |
+------------------------------------------+-----------------------------------------------------------------+
```
Reviewed By: RSNara
Differential Revision: D20817257
fbshipit-source-id: 9ae378dbe880aaabfef7ae783dae2f94ee4b0af5