A framework for building native macOS apps with React.
Перейти к файлу
Ramanpreet Nara 5e68a98c3d Make TurboModuleProviderFunctionType not depend on TurboModuleManager instance
Summary:
## Description
The C++ lambda that JS invokes to create TurboModules uses `TurboModuleManager`. It is possible for this lambda to outlive the `TurboModuleManager` instance because we delete `TurboModuleManager` on the JS Thread before we schedule the deletion of `CatalystInstanceImpl` object on a neutral third-party background thread. `CatalystInstanceImpl` owns the JS VM instance that owns the C++ lambda.

## [CatalystInstanceImpl.java](https://fburl.com/diffusion/vt4pwjwa)
```
public void destroy() {
  // ...

  getReactQueueConfiguration()
    .getJSQueueThread()
    .runOnQueue(
        new Runnable() {
          Override
          public void run() {
            // We need to destroy the TurboModuleManager on the JS Thread
            if (turboModuleManager != null) {
              turboModuleManager.onCatalystInstanceDestroy();
            }

            getReactQueueConfiguration()
                .getUIQueueThread()
                .runOnQueue(
                    new Runnable() {
                      Override
                      public void run() {
                        // AsyncTask.execute must be executed from the UI Thread
                        AsyncTask.execute(
                            new Runnable() {
                              Override
                              public void run() {
                                // Kill non-UI threads from neutral third party
                                // potentially expensive, so don't run on UI thread

                                // contextHolder is used as a lock to guard against
                                // other users of the JS VM having the VM destroyed
                                // underneath them, so notify them before we reset
                                // Native
                                mJavaScriptContextHolder.clear();

                                mHybridData.resetNative();
                                getReactQueueConfiguration().destroy();
                                Log.d(
                                    ReactConstants.TAG,
                                    "CatalystInstanceImpl.destroy() end");
                                ReactMarker.logMarker(
                                    ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
                              }
                            });
                      }
                    });
          }
        });
    }
  });

  // ...
}
```

The JS thread is also terminated in the neutral third-party thread. Therefore, it should be possible for JS to request a `TurboModule` after `TurboModuleManager` has been destroyed (i.e: JS can try to access memory that was freed). This is why I think we're getting a segfault in T54298358.

## Fix
The fix was to wrap all the member variables of TurboModuleManager we use in `TurboModuleProviderFunctionType` in weak references. This way, we can make sure that the memory is valid before using it.

Reviewed By: fkgozali

Differential Revision: D17539761

fbshipit-source-id: fe527383458a019a4cb9107ec5c3ddd6295ae41c
2019-09-26 09:34:41 -07:00
.appveyor Bump Android NDK to r19c (#25140) 2019-06-04 13:59:36 -07:00
.circleci Update CircleCI config as per support request (#26329) 2019-09-09 06:42:29 -07:00
.github update bug_report.md template (#25623) 2019-07-19 13:45:09 -07:00
IntegrationTests Clean-up $TEMPORARY$object in xplat/js/react-native-github 2019-08-21 09:58:24 -07:00
Libraries Remove unused flow suppressions 2019-09-26 08:16:24 -07:00
RNTester Make setting useNativeDriver required. Add runtime warning if not specified 2019-09-25 13:36:27 -07:00
React Split up createTimer into two methods, createTimer and createTimerForNextFrame 2019-09-25 15:31:26 -07:00
ReactAndroid Make TurboModuleProviderFunctionType not depend on TurboModuleManager instance 2019-09-26 09:34:41 -07:00
ReactCommon Fabric: Enforcing const-correctness around ImageResponseObserverCoordinator 2019-09-23 15:59:45 -07:00
bots Bots cleanup, avoid leaving inline reviews when N>5 (#24923) 2019-05-21 19:38:54 -07:00
docs Generate doc info for RN components 2019-09-19 18:36:25 -07:00
flow fix jest's test.table flow type 2019-07-18 09:38:47 -07:00
flow-typed/npm remove deprecated utilities 2019-01-15 13:59:31 -08:00
gradle/wrapper Update Gradle wrapper to 5.6.2 (#26349) 2019-09-06 00:25:53 -07:00
jest Mock createAnimatedComponent (#26109) 2019-09-02 06:11:23 -07:00
keystores Use fb_native_wrapper for all targets 2018-10-31 11:47:42 -07:00
local-cli Update references to the CLI (#23052) 2019-01-21 09:13:08 -08:00
packages Update codegen test fixtures to use HostComponent 2019-09-25 13:16:04 -07:00
scripts Rename JSCallInvoker{,Holder} to CallInvoker{,Holder} 2019-09-20 10:52:56 -07:00
template Upgrade all dependencies in package.json template (#26563) 2019-09-25 22:03:45 -07:00
third-party-podspecs TM iOS: Set up CocoaPods specs for the TM specs 2019-07-01 15:20:01 -07:00
tools/build_defs Combine rn_debug_flags and rn_feature_flags 2019-09-12 13:09:29 -07:00
.buckconfig Bump Android SDK to 28, Build Tools to 28.0.2, Gradle to 4.7, Gradle Plugin to 3.2.0 (#21632) 2018-12-05 09:06:31 -08:00
.buckjavaargs limiting BUCK's memory for CI 2016-02-01 10:49:33 -08:00
.clang-format Moving ObjC specific clang-format rules to the common config 2019-02-11 13:07:09 -08:00
.editorconfig https link to EditorConfig.org (#25267) 2019-06-18 01:58:07 -07:00
.eslintignore Eliminate eslint npm version mismatch warnings and bump some to latest (#23969) 2019-03-19 11:14:30 -07:00
.eslintrc Add a lint rule to disallow Haste imports (#25058) 2019-05-30 07:45:16 -07:00
.flowconfig Make RelativeImageStub regex match images in scoped packages (#26567) 2019-09-25 18:27:27 -07:00
.flowconfig.android Make RelativeImageStub regex match images in scoped packages (#26567) 2019-09-25 18:27:27 -07:00
.gitattributes Added a .gitattributes file, ensuring that Bash script source files (gradlew and 2015-10-13 23:10:39 -04:00
.gitignore iOS Pods: use tar.gz offline mirrors instead of pods replica 2019-09-20 16:20:16 -07:00
.nvmrc Add .nvmrc + fix node version for eslint 5 compat (#20109) 2018-07-31 02:34:16 -07:00
.prettierrc Set the Prettier config so it is not forced on users of @react-native-community/eslint-config (#24635) 2019-04-29 09:44:51 -07:00
CODE_OF_CONDUCT.md Adopt Contributor Covenant 2019-08-29 23:21:10 -07:00
CONTRIBUTING.md chore: Link to CLA wiki and CLA form. (#26016) 2019-08-12 02:22:12 -07:00
ECOSYSTEM.md Add document describing the RN ecosystem. (#24493) 2019-04-17 09:06:37 -07:00
LICENSE Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
LICENSE-docs More licenses 2015-03-24 19:59:10 -07:00
README.md Minor fix (#25385) 2019-06-26 10:05:30 -07:00
React-Core.podspec Change podspec name of yoga to Yoga 2019-08-30 07:12:34 -07:00
React.podspec Remove 's.static_framework = true' requirement for podspec (#25816) 2019-07-25 11:46:43 -07:00
Releases.md Fix typo in Releases.md (#20487) 2018-08-01 07:16:56 -07:00
build.gradle.kts bump android gradle plugin to 3.5.0 (#26129) 2019-08-29 07:35:41 -07:00
cli.js Show full price instead of monthly price within the lead form 2019-03-28 16:07:19 -07:00
gradlew Update Gradle wrapper to 5.6.2 (#26349) 2019-09-06 00:25:53 -07:00
gradlew.bat Update Gradle wrapper to 5.6 (#26079) 2019-08-26 12:13:37 -07:00
index.js Add HostComponent to the public API of React Native 2019-09-25 11:44:38 -07:00
interface.js Move `react-native-implementation.js` to `index.js` 2019-09-12 03:29:51 -07:00
jest-preset.js Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper (#24811) 2019-06-05 10:55:08 -07:00
jest.config.js Delete hasteImpl, providesModuleNodeModules, and modulePathNameMapper (#24811) 2019-06-05 10:55:08 -07:00
metro.config.js Use latest React Native CLI (#24517) 2019-04-24 05:09:10 -07:00
package.json Upgrade eslint-plugin-relay to 1.3.12 2019-09-25 16:00:05 -07:00
react-native.config.js deprecate iOS .xcodeproj (#25583) 2019-07-11 12:02:39 -07:00
react.gradle fix build with hermes on windows (#26556) 2019-09-25 17:51:48 -07:00
rn-get-polyfills.js Remove Polyfills from RN Open Source 2019-04-04 15:20:33 -07:00
runXcodeTests.sh deprecate iOS .xcodeproj (#25583) 2019-07-11 12:02:39 -07:00
settings.gradle.kts Gradle KTS (#24631) 2019-04-29 02:41:05 -07:00
template.config.js Improvement: Adjust template to match new init command (#24138) 2019-04-01 16:25:48 -07:00
yarn.lock Upgrade eslint-plugin-relay to 1.3.12 2019-09-25 16:00:05 -07:00

README.md

React Native

Learn once, write anywhere:
Build mobile apps with React.

React Native is released under the MIT license. Current CircleCI build status. Current Appveyor build status. Current npm package version. PRs welcome! Follow @reactnative

Getting Started · Learn the Basics · Showcase · Contribute · Community · Support

React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.

  • Declarative. React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
  • Component-Based. Build encapsulated components that manage their own state, then compose them to make complex UIs.
  • Developer Velocity. See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
  • Portability. Reuse code across iOS, Android, and other platforms.

React Native is developed and supported by many companies and individual core contributors. Find out more in our ecosystem overview.

Contents

📋 Requirements

React Native apps may target iOS 9.0 and Android 4.1 (API 16) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like Expo can be used to work around this.

🎉 Building your first React Native app

Follow the Getting Started guide. The recommended way to install React Native depends on your project. Here you can find short guides for the most common scenarios:

📖 Documentation

The full documentation for React Native can be found on our website.

The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the React documentation.

The source for the React Native documentation and website is hosted on a separate repo, @facebook/react-native-website.

🚀 Upgrading

Upgrading to new versions of React Native may give you access to more APIs, views, developer tools and other goodies. See the Upgrading Guide for instructions.

React Native releases are discussed in the React Native Community, @react-native-community/react-native-releases.

👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React Native.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native.

Open Source Roadmap

You can learn more about our vision for React Native in the Roadmap.

Good First Issues

We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Discussions

Larger discussions and proposals are discussed in @react-native-community/discussions-and-proposals.

📄 License

React Native is MIT licensed, as found in the LICENSE file.

React Native documentation is Creative Commons licensed, as found in the LICENSE-docs file.