react-native-macos/ReactCommon
Valentin Shergin b145a82964 Fixed crash in JSIExecutor::NativeModuleProxy
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
2020-04-02 11:16:13 -07:00
..
better Replace fbsource// with // in xplat/js/ files [1] 2020-03-25 21:55:47 -07:00
callinvoker Get CallInvokers from the bridge 2020-04-01 11:39:18 -07:00
config Replace fbsource// with // in xplat/js/ files [1] 2020-03-25 21:55:47 -07:00
cxxreact Split loadApplicationScript into initializeRuntime and loadBundle (#27844) 2020-04-01 17:52:39 -07:00
fabric Back out "Fix controlled TextInput with child nodes" 2020-04-02 08:26:04 -07:00
hermes Plumb through memory allocation profiler feature to Chrome Inspector 2020-03-31 11:02:41 -07:00
jscallinvoker The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jsengineinstance The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jsi Make HermesRuntime::description() always include "HermesRuntime" 2020-04-01 13:42:56 -07:00
jsiexecutor Fixed crash in JSIExecutor::NativeModuleProxy 2020-04-02 11:16:13 -07:00
jsinspector make RN infra labels public 2020-02-28 12:46:49 -08:00
microprofiler make RN infra labels public 2020-02-28 12:46:49 -08:00
turbomodule Get CallInvokers from the bridge 2020-04-01 11:39:18 -07:00
utils RuntimeExecutor helpers that modify the way of the callback is being executed. 2020-03-30 19:35:08 -07:00
yoga Fix Yoga flexshrink with min-width sizing issue 2020-04-01 14:41:38 -07:00
React-Fabric.podspec Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
ReactCommon.podspec Get CallInvokers from the bridge 2020-04-01 11:39:18 -07:00
common.mk More robust hermes-engine lookup logic in makefiles (#26820) 2019-10-14 19:21:43 -07:00