Граф коммитов

99 Коммитов

Автор SHA1 Сообщение Дата
Ramanpreet Nara e36bfef0f1 Conditionally disable TurboModuleManager delegate locking
Summary:
## Context
Whenever the TurboModuleManager calls into its delegate, it [acquires a lock](https://www.internalfb.com/code/fbsource/[f14548634e72009989c844a2ef025915ef74159e]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=429%2C513). We initially introduced this mutex (in D21170099 (2c473e1a38)). It serializes access to the TurboModuleManager delegate during TurboModule create.

## Problems
- When we call into the delegate, we acquire a lock, and call into arbitrary product code: getModuleClassFromName, getModuleInstanceFromClass. If any of these two product methods create another TurboModule, the application will deadlock, because we'll acquire the same std::mutex twice.

## Fix
The delegate methods of TurboModuleManager are usually implemented as [switch cases over the NativeModule names or NativeModule classes](https://www.internalfb.com/code/fbsource/[f015e461de4e7a18d0d52a697a53086fe6a3b91c]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=1481-1488%2C1490-1537%2C1539-1577). So, it should be safe to call into them concurrently for two different modules.

So, while we could fix the problem by migrating the TurboModuleManager to an std::recursive_mutex, one could make an argument that this locking shouldn't even be necessary in the first place. We don't have this locking in the Android TurboModule system.

## Changes
This diff introduces a flag in React Native that allows to to safely remove this TurboModuleManager delegate locking in production.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D30754875

fbshipit-source-id: d04a831c18a2a8b46e9bc07ddf690d8e4d0be8e0
2021-09-08 12:53:17 -07:00
Ramanpreet Nara 32bfd7a857 Stop sharing LongLivedObjectCollection with the bridge
Summary:
## Context
Previously, when you'd call TurboModule methods with JavaScript callbacks, we'd [store the callbacks](https://www.internalfb.com/code/fbsource/[c503ff1b38621aebca87b2bbebeae088b01886c4]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModule.mm?lines=173%2C248-249) into [this global LongLivedObjectCollection collection](https://www.internalfb.com/code/fbsource/[c503ff1b38621aebca87b2bbebeae088b01886c4]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h?lines=65). Then, when React Native's JavaScript VM got torn down, we'd [clear the global collection](https://www.internalfb.com/code/fbsource/[e26f476ce208c578f05b1edb7639d1dad5612c7d]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp?lines=49), which would ensure that we deleted all held jsi::Functions, before deleting the jsi::Runtime.

## Problem
With bridgeless mode enabled, there can be two TurboModule systems. Further, it is possible to tear down bridgeless mode, or the bridge, without tearing down the other initialization infra. In this scenario, the jsi::Function for the other initialization infra would also get deleted, which could lead to mysterious problems.

## Fix
In this diff, I refactored the jsi::Function cleanup in the TurboModule system. Now, there are 3 modes:
- kGlobalScope: Everything works as it did before
- kRCTGlobalScopeUsingRetainJSCallback: We still use the global LongLivedObjectCollection, but we do it through invoking a block passed to every ObjCTurboModule by the TurboModuleManager. This group exists to assess the impact of having each TurboModule retain/use the block. I suspect this will be negligible, but it'd be good to have actual data to back this claim.
- kRCTTurboModuleManagerScope: Every TurboModule uses a LongLivedObjectCollection that is owned by its TurboModuleManager. This should effectively fix the problem I outlined above.

Changelog: [Internal]

Reviewed By: p-sun

Differential Revision: D30019833

fbshipit-source-id: da50d884c7e37190107f570d8ed70eeda7d9ae83
2021-08-02 11:22:22 -07:00
Samuel Susla d472efbd72 Remove feature flag for promises block guard
Summary:
Changelog: [internal]

Promises block guard is shipped. Let's remove gating.

Reviewed By: RSNara

Differential Revision: D29262010

fbshipit-source-id: c15e033573b11f0a3470b1ddfbef07b6f03ba069
2021-06-24 03:33:05 -07:00
Samuel Susla e4b6392ee7 Remove gating for block guard
Summary: Changelog: Remove gating around leak fix in TurboModules infra

Reviewed By: RSNara

Differential Revision: D28253054

fbshipit-source-id: 9b3c236d3752b5ca042f83127e42e69250ccd112
2021-05-06 20:00:15 -07:00
Samuel Susla 10a9a4ed89 Enable block guard for promises
Summary:
Changelog: Resolve memory leak in promises on iOS

Enable block guard for promises

Reviewed By: RSNara

Differential Revision: D28252977

fbshipit-source-id: 052fefca0a6ac54597a46922fc467a2a39f7976f
2021-05-06 20:00:15 -07:00
Ramanpreet Nara e5080e6171 Pull RCTViewRegistry attachment out of TurboModuleManager
Summary:
## Rationale
The TurboModuleManager should only be concerned with modules. The bridge and RCTInstance integrate the TurboModuleManager with the rest of React Native. Therefore, abstractions used by TurboModules that reach into the rest of React Native should be attached by the bridge or by RCTInstance.

## Changes
In this diff, we pull RCTViewRegistry attachment out of the TurboModuleManager. In bridge mode, it'll be attached to TurboModule by the bridge. In bridgeless mode, it'll be attached to TurboModules by the RCTInstance.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D28086320

fbshipit-source-id: 9d99835bdbb66bb6a41fbd0d8a3970cefae16b81
2021-04-30 16:40:16 -07:00
Samuel Susla f7d006e60c Fix memory leak convertJSIFunctionToCallback
Summary:
changelog: [internal]

### When does leak happen?
Leak happens anytime a callback isn't executed inside native module, it will never get cleaned up.
Imagine a native module with method that takes onSuccess and onFail callbacks. Only one of them will be called at any time and the other one will leak.

### Why does it leak?
It leaks because when `CallbackWrapper` is created using `CallbackWrapper::createWeak`. Inside `CallbackWrapper::createWeak`, the newly created object is inserted into `LongLivedObjectCollection`. This object collection will keep it alive until `CallbackWrapper::destroy` is called, which isn't called in case closure isn't executed.

### Solution
Introduce class RCTBlockGuard which ties cleanup of resources to lifetime of the block.

Reviewed By: RSNara

Differential Revision: D26664173

fbshipit-source-id: 9348f7c39eb317cf1e8e5d59e77a378e5e04f3eb
2021-02-27 04:55:52 -08:00
Ramanpreet Nara a156ee9b73 Delete JS TurboModule Codegen Gating
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25915171

fbshipit-source-id: b59e21f834a7172055e180eddb9bf15737a6cf0f
2021-01-14 19:14:23 -08:00
Ramanpreet Nara 5275895af5 Roll out TurboModule block copy
Summary:
## Description
During TurboModule method invocation, when we convert JavaScript callbacks (i.e: jsi::Functions) into ObjC blocks inside the TurboModule jsi::HostObject, we [push them into an array](https://fburl.com/diffusion/r1n75ikx) that [gets cleared after the method gets invoked](https://fburl.com/diffusion/ubbvdmfs).

Prior to this experiment, we pushed these ObjC blocks into the array without copying them first. This goes contrary to ObjC best practices, which suggest that if you need to retain a block past its creation context for later invocation, you should defensively copy it to prevent it from being freed early. See the [Apple docs](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Blocks/Articles/bxUsing.html#//apple_ref/doc/uid/TP40007502-CH5-SW1):
> Typically, you shouldn’t need to copy (or retain) a block. You only need to make a copy when you expect the block to be used after destruction of the scope within which it was declared. Copying moves a block to the heap.

The diff that introduced the fix: D23764329 (9b76e217bb).

Reviewed By: PeteTheHeat

Differential Revision: D25617672

fbshipit-source-id: 24863b31a2d82c8d39a91c8ea8eb3a62724b800a
2020-12-17 17:27:09 -08:00
Ramanpreet Nara cb7f3f4499 Setup TurboModule JS Codegen experiment
Summary:
## Android API
```
// Before we initialize TurboModuleManager
ReactFeatureFlags.useTurboModuleJSCodegen = true
```

## iOS API
```
// Before we initialize RCTBridge
RCTEnableTurboModuleJSCodegen(true);
```

## How is the JS Codegen actually enabled?
The above native flags are translated to the following global variable in JavaScript:
```
global.RN$JSTurboModuleCodegenEnabled = true;
```

Then, all our NativeModule specs are transpiled to contain this logic:
```
interface Foo extends TurboModule {
  // ...
}

function __getModuleSchema() {
  if (!global.RN$JSTurboModuleCodegenEnabled) {
    return undefined;
  }

  // Return the schema of this spec.
  return {...};
}

export default TurboModuleRegistry.get<Foo>('foo', __getModuleSchema());
```

Then, in our C++ JavaTurboModule, and ObjCTurboModule classes, we use the TurboModule JS codegen when the jsi::Object schema is provided from JavaScript in the TurboModuleRegistry.get call.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D24636307

fbshipit-source-id: 80dcd604cc1121b8a69df875bbfc87e9bb8e4814
2020-11-06 13:28:15 -08:00
Lulu Wu ea93151f21 Make RCTEventDispatcher TurboModule-compatible
Summary:
This diff ended up being a bit more complicated than I anticipated, since the source files in `ReactInternal` were depending on `RCTEventDispatcher`. I made the following changes:
1. Make `RCTEventDispatcher` a `protocol`, keep it in `ReactInternal`.
2. Rename the `RCTEventDispatcher` NativeModule to `RCTEventDispatcherModule`, make it conform to the `RCTEventEmitter` `protocol`, and move it to `CoreModules`.
3. Where necessary, replace categories of `RCTEventDispatcher` with functions.

Changelog:
[iOS][Added] - Make RCTEventDispatcher TurboModule-comaptible

Reviewed By: fkgozali

Differential Revision: D18439488

fbshipit-source-id: b3da15c29459fddf884519f33b0c3b8c036b5539
2020-10-14 02:40:10 -07:00
Ramanpreet Nara 5535031ba4 Gate TurboModule block copy behind an MC
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24145506

fbshipit-source-id: 7e374c3bd2378cc1dcd9372d7cbb10ae445a2582
2020-10-06 18:40:20 -07:00
Ramanpreet Nara f5c246d50e Use reader/writer lock for TurboModule cache access
Summary:
Right now, when two threads require two NativeModules, both threads fight for the same `std::mutex`. Why? Because NativeModule require can read from/write to the shared `std::unordered_map<std::string, TurboModuleHolder*>`.

**A Few Thoughts:**
- All threads should be able to read from the TurboModule cache concurrently, without issue. Only writes into the cache require exclusive access. *With our current setup, both reads and writes acquire exclusive access.*
- During the lifetime of an application, there will only be tens of NativeModule create events (i.e: writes into the TurboModule cache). However, there may be hundreds, if not thousands of TurboModule cache lookups. *We don't need to serialize those hundreds/thousands of TurboModule cache reads.*

This is a potential optimization opportunity for the TurboModule infra.

## Changes
This diff introduces a `std::shared_mutex` inside `RCTTurboModuleManager`. We use either the regular `std::mutex` or the `std::shared_mutex`, depending on whether `RCTTurboModuleSharedMutexInitEnabled()` is `YES`.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23413118

fbshipit-source-id: 0880413c691b141db98a2715648f0c3e05983307
2020-09-09 09:31:38 -07:00
Peter Argany 9d3cefbbca Delete unused RCTAdditionalJavaScriptDidLoadNotification
Summary:
This notification was never used, I'd rather not have someone start relying on it, and need to figure out how to migrate them in bridgeless mode.

Changelog:[Internal]

Reviewed By: cpojer, RSNara

Differential Revision: D22513602

fbshipit-source-id: 80b179af8408abc6646a73380b4a66cade3f75f2
2020-07-23 17:11:32 -07:00
Ramanpreet Nara e549f6984e Gate TurboModule eager initialization
Summary:
TurboModule eager initialization is a bit dangerous if we get it wrong, which we did (twice): T69449176.

This diff gates TurboModule eager init behind a MC, so that we can control (i.e: turn off/on, and do gradually rollout of) TurobModule eager initialization in isolation from the larger TurboModules experiment.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D22460359

fbshipit-source-id: 3b8dce0529f1739bd68b8b16d6a28aa572d82c2c
2020-07-09 16:24:31 -07:00
Ramanpreet Nara a27c295f53 Rename RCTTurboModuleLookupDelegate to RCTTurboModuleRegistry
Summary:
## Why?
1. RCTTurboModuleLookupDelegate sounds a bit nebulous.
2. In JS and Java, we use a `TurboModuleRegistry` interface to require TurboModules. So, this diff will make JS, Java, and ObjC consistent.

Changelog:
[Internal]

Reviewed By: PeteTheHeat

Differential Revision: D22405754

fbshipit-source-id: 30c85c246b39d198c5b8c6ca4432a3196ca0ebfd
2020-07-07 16:25:11 -07:00
Christoph Nakazawa ad879e50bc Add `RCTDevSplitBundleLoader` native module
Reviewed By: ejanzer

Differential Revision: D21302418

fbshipit-source-id: a868f6dad3306190c7add26e8f9a976866c16aef
2020-06-08 09:07:42 -07:00
Valentin Shergin d0871d0a9a Clang format for all React Native files
Summary:
Buckle up, this enables clang-format prettifier for all files in React Native opensource repo.

Changelog: [Internal] Clang-format codemod.

Reviewed By: mdvacca

Differential Revision: D20331210

fbshipit-source-id: 8da0f94700be0c35bfd399e0c48f1706de04f5b1
2020-03-08 23:01:17 -07:00
Peter Argany 5ca0df64a1 Deprecate RCTBridgeWillReloadNotification [3/n]
Summary:
`RCTBridgeWillReloadNotification` has one job: whenever bridge reloads - trigger a reload in `RCTSurfacePresenter`.

Diff 1/2 deprecated bridge reloading APIs, and replaced them with `RCTReloadCommand`. Use that in `RCTSurfacePresenter` instead .

Changelog: [iOS][Deprecate] Deprecate RCTBridgeWillReloadNotification

Reviewed By: shergin

Differential Revision: D17880926

fbshipit-source-id: 00adc4d56d11d40ab371d81bb17a05609c184769
2019-10-30 12:23:24 -07:00
Peter Argany ffe2306164 Deprecate bridge reload API [1/n]
Summary:
Testing the waters with an idea for unifying RN lifecycle with/without bridge.

### Motivation/Background

RN bridge is being reloaded from [several different places](https://fburl.com/codesearch/ae3zeatt). When this happens, the bridge does a bunch of things:
1. Post `RCTBridgeWillReloadNotification` (RCTSurfacePresenter listens to this and reloads)
2. Invalidate batched bridge, which does:
    a. invalidate display link
    b. post `RCTBridgeWillInvalidateModules/RCTBridgeDidInvalidateModules` (TurboModuleManager listens to this and reloads modules)
    c. clear js thread state
    d. clear some local caches
3. Set up (reload bundle and batched bridge)

In a bridgeless world, there isn't one thing which owns all these peices of infra, and can reload them.

### Plan

Use `RCTReloadCommand` to handle reloads. This light class previously only handled CMD+R. The new workflow looks like this:
1. Anything which cares about reloads can register itself as a listener. (RCTBridge, RCTSurfacePresenter, TurboModuleManager...)
2. Anything that previously called `bridge reload` now calls `RCTTriggerReloadCommandListeners`.
3. Delete old notifications

### Alternate Plan

Use yet another NSNotification. I like `RCTReloadCommand` better.

### Unknowns

Looks like we log the reason for bridge reloading [here](https://fburl.com/diffusion/lc9jj8la), do we want to save this behaviour? Does anyone look at why bridge is being reloaded cc/Rick? If so, I can add back that functionality to `RCTReloadCommand`.

It should be possible to customize the order/priority of what gets reloaded first. There may be some racy behaviour that I haven't thought about yet.

Changelog: [iOS][Deprecated] Deprecate [bridge reload] API - prefer RCTReloadCommand

Reviewed By: shergin

Differential Revision: D17869635

fbshipit-source-id: 81f39eaa2c3ce08ea1bc6f2193684c2630d81a2d
2019-10-30 12:23:24 -07:00
Valentin Shergin 7a20964e9d Introducing `RCTBridgeWillBeInvalidatedNotification`
Summary:
This diff introduces a new broadcasting event for Bridge that communicates that the bridge is being invalidated. This notification can be used by interested parties as a signal to start tearing down all bridge-dependant processes.

The biggest difference between the new event and `RCTBridgeWillInvalidateModulesNotification` is that the latter is being called asynchronously on the JavaScript thread, whereas the new one is being called on whatever thread caused the Bridge invalidation (deallocation) *synchronously*. In most cases that happens on the main thread that allows destroying strictly-main-threaded infra (mostly UI) synchronously and avoids races.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D18050889

fbshipit-source-id: 9364c820ea2b0358edf45f0e2b3e16a13d730a9c
2019-10-24 17:45:40 -07:00
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00
Rick Hanlon d0324f693c Move reason to a constant
Summary: Moves the reason to a constant because APPARENTLY this is a best practice in this establishment

Reviewed By: sammy-SC

Differential Revision: D17627819

fbshipit-source-id: 328fad8b7482d0e379a41b5f8c841f71db2bb5ac
2019-09-30 07:03:51 -07:00
Rick Hanlon 2d95668aa8 Add fastRefresh to NativeDevSettings
Summary: This diff adds a method to call whenever a fast refresh happens. Right now this is only useful for reporting.

Reviewed By: cpojer

Differential Revision: D17528033

fbshipit-source-id: 17e82abe7a3e2bab6829de5adecda853fe5335c5
2019-09-30 07:03:51 -07:00
Rick Hanlon 2ccc8fbc28 Add and use reloadWithReason to iOS
Summary:
This diff adds a new reloading method reloadWithReason that allows callers to provide a reason for why a reload was requested.

This reason is useful for understanding why users are reloading, and why Fast Refresh is bailing out to a full reload. I also updated the places we reload with the reasons listed below.

**Standard native reasons:**
- Redbox
- Command
- Global hotkey
- Profiling controls
- Dev menu - reload
- Dev menu - reset to default
- Dev menu - apply changes

**From JavaScript (added in a later diff):**
- Fast Refresh - Unrecoverable
- Fast Refresh - No root boundary
- Fast Refresh - Invalidated boundary
- Fast Refresh - Invalidated root boundary

**Misc reasons and fallback for when a reason is unavailable:**
- Unknown from JS
- Uncategorized from JS
- Unknown from bridge
- Unknown from cxx bridge
- Requested from bridge
- Custom executor class reset

Reviewed By: cpojer

Differential Revision: D17499339

fbshipit-source-id: 12a21ffa05708c9b921d93911f190cdffc5c78d5
2019-09-30 07:03:50 -07:00
Min ho Kim 84f5ebe4f9 Fix typos (#25770)
Summary:
Fix typos mostly in comments and some string literals.

## Changelog

[General] [Fixed] - Fix typos
Pull Request resolved: https://github.com/facebook/react-native/pull/25770

Differential Revision: D16437857

Pulled By: cpojer

fbshipit-source-id: ffeb4d6b175e341381352091134f7c97d78c679f
2019-07-23 03:23:11 -07:00
Kevin Gozali 01a42bc368 TM iOS: Prevent module cache invalidation race
Summary: There are still race condition during bridge invalidation. Some modules may be accessing other modules during invalidation, but it's racing with the TM manager clearing the cache.

Reviewed By: JoshuaGross

Differential Revision: D15947488

fbshipit-source-id: 3bd51382264f538a03ca565b0f099da40c3daadf
2019-06-21 15:54:01 -07:00
Kevin Gozali 8662d9d3b0 TM iOS: Added backward-compatible ObjC invalidation logic
Summary:
Some ObjC NativeModules conform to `RCTInvalidating` protocol and implements `invalidate` method. This is typically used to clean things up during bridge teardown or reload. In TurboModule system the invalidate method can be replaced by pure destructors, but for backward compatibility, we call existing invalidate method on each module during teardown.

This also cleans up all existing LongLivedObject's.

Reviewed By: mdvacca, RSNara

Differential Revision: D15365655

fbshipit-source-id: 802844b39b5b7adb54970ea541f4d744bbf9e480
2019-05-15 17:36:05 -07:00
RCiesielczuk cd2f8c567b Introduce TurboModule Setup Metric (#24732)
Summary:
With the introduction of TurboModules, it would be beneficial to measure the setup time of these modules, as we currently have it in place for NativeModules.

The instantiation of the TMs occurs in the `RCTTurboModuleManager`. In order to successfully measure the time it took to setup the module, we need to ensure that we don't take into account cached modules. As such, we need to:

1. Check if module is in `_turboModuleCache`
  a. Start mark for `RCTPLTurboModuleSetup` tag if not found
2. Get the TM via `[self provideTurboModule:]`
3. Check if module is in `_turboModuleCache`
   a. Stop mark for `RCTPLTurboModuleSetup` if we did not find module in cache prior to **step 2** and if it's now present in the cache.
   b. Notify about setup time if the above is true.
4. Return TM

## Changelog

[iOS] [Added] - Gain insights on the the turbo module setup times by observing `RCTDidSetupModuleNotification`. The userInfo dictionary will contain the module name and setup time in milliseconds. These values can be extracted via `RCTDidSetupModuleNotificationModuleNameKey` and `RCTDidSetupModuleNotificationSetupTimeKey`.
Pull Request resolved: https://github.com/facebook/react-native/pull/24732

Differential Revision: D15362088

Pulled By: RSNara

fbshipit-source-id: e6a8044e4aba5a12ae63e9c7dbf707a17ec00180
2019-05-15 15:28:10 -07:00
Rafi Ciesielczuk e2bf843d86 Introduce Module Setup Metric (#23859)
Summary:
The `RCTBridge` contains numerous definitions of notification names, which we can observe in order to get insights into the React Native performance.

The Android implementation is a little different, such that you can listen for any of the [following](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java) marker constants, simply by including the following code:

```java
ReactMarker.addListener(new ReactMarker.MarkerListener() {
  Override
  public void logMarker(ReactMarkerConstants name, Nullable String tag, int instanceKey) {
    Log.d("ReactNativeEvent", "name: "+ name.name() + " tag: " + tag);
  }
});
```
This will allow you to perform the necessary processing, calculations as required.

 ---

This PR enables observing for the module setup event (`RCTDidSetupModuleNotification`) by including the respective module's name & setup time in milliseconds.

[iOS] [Added] - Gain insights on the module setup times by observing `RCTDidSetupModuleNotification`. The `userInfo` dictionary will contain the module name and setup time in milliseconds. These values can be extracted via `RCTDidSetupModuleNotificationModuleNameKey ` and `RCTDidSetupModuleNotificationSetupTimeKey`.
Pull Request resolved: https://github.com/facebook/react-native/pull/23859

Differential Revision: D14579066

Pulled By: PeteTheHeat

fbshipit-source-id: 52645127c3fc6aa5bd73e3bd471fccd79cb05c14
2019-03-22 10:43:00 -07:00
Ramanpreet Nara 0ceefb40d5 Enable module lookup in TurboModules
Summary:
NativeModules are instantiated by the bridge. If they choose, they can capture the bridge instance that instantiated them. From within the NativeModule, the bridge can then be used to lookup other NativeModules. TurboModules have no way to do such a lookup.

Both NativeModules and TurboModules need to be able to query for one another. Therefore, we have four cases:
1. NativeModule accesses NativeModule.
2. NativeModule accesses TurboModule.
3. TurboModule accesses NativeModule.
4. TurboModule accesses TurboModule.

In summary, this solution extends the bridge to support querying TurboModules. It also introduces a `RCTTurboModuleLookupDelegate` protocol, which, implemented by `RCTTurboModuleManager`, supports querying TurboModules:
```
protocol RCTTurboModuleLookupDelegate <NSObject>
- (id)moduleForName:(NSString *)moduleName;
- (id)moduleForName:(NSString *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure;
- (BOOL)moduleIsInitialized:(NSString *)moduleName
end
```

If TurboModules want to query other TurboModules, then they need to implement this protocol and synthesize `turboModuleLookupDelegate`:

```
protocol RCTTurboModuleWithLookupCapabilities
property (nonatomic, weak) id<RCTTurboModuleLookupDelegate> turboModuleLookupDelegate;
end
```

NativeModules will continue to use `RCTBridge` to access other NativeModules. Nothing needs to change.

When we attach the bridge to `RCTTurboModuleManager`, we also attach `RCTTurboModuleManager` to the bridge as a `RCTTurboModuleLookupDelegate`. This allows the bridge to query TurboModules, which enables our NativeModules to transparently (i.e: without any NativeModule code modification) query TurboModules.

In an ideal world, all modules would be TurboModules. Until then, we're going to require that TurboModules use the bridge to query for NativeModules or TurboModules.

`RCTTurboModuleManager` keeps a map of all TurboModules that we instantiated. We simply search in this map and return the TurboModule.

This setup allows us to switch NativeModules to TurboModules without compromising their ability to use the bridge to search for other NativeModules (and TurboModules). When we write new TurboModules, we can have them use `RCTTurboModuleLookupDelegate` to do access other TurboModules. Eventually, after we migrate all NativeModules to TurboModules, we can migrate all old callsites to use `RCTTurboModuleLookupDelegate`.

Reviewed By: fkgozali

Differential Revision: D13553186

fbshipit-source-id: 4d0488eef081332c8b70782e1337eccf10717dae
2019-01-31 11:35:05 -08:00
Kevin Gozali aad83cc238 iOS TM: RCTEnableJSINativeModule => RCTEnableTurboModule
Summary: Leftover name change from previous codemod.

Reviewed By: shergin

Differential Revision: D13117615

fbshipit-source-id: 2584a2a90d3db6ed9a9e9cb8727c51da34f0927c
2018-11-20 01:20:59 -08:00
Kevin Gozali 39b8fa95a3 iOS TM: Rename RCTJSINativeModule => RCTTurboModule
Summary: Simple codemod to rename RCTJSINativeModule => RCTTurboModule (the protocol) for less confusion.

Reviewed By: PeteTheHeat

Differential Revision: D13054206

fbshipit-source-id: 4829dc69838c623336475ea8ee11be815d79711c
2018-11-14 10:42:04 -08:00
Kevin Gozali d7a0c44590 iOS: add moduleForNameForcedLoad: to lookup modules by name and force load them
Summary:
Some module classes may not be loaded yet, so looking up via classes may not always give the correct instance. This diff added a new lookup method that delegate to the bridge delegate to force load the modules as needed.

The existing moduleForName: method was left untouched because it's solely used by RCTUIManager at the moment.

Reviewed By: dshahidehpour

Differential Revision: D13033876

fbshipit-source-id: 4082fcd68498004f678b4b95adc82b5b134fefdf
2018-11-13 20:11:47 -08:00
Marc Horowitz c49d3653ef iOS changes to switch to JSI
Summary:
change RCTCxxBridge to use JSIExecutorFactory+JSCRuntime
instead of JSCExecutorFactory.  Also remove JSC usage from RN in other
files.  This allows deleting files, too, which is done further down
the stack.

Reviewed By: RSNara

Differential Revision: D9369111

fbshipit-source-id: 67ef3146e3abe5244b6cf3249a0268598f91b277
2018-10-18 01:06:24 -07:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
Kevin Gozali 6a1f48e06d TM iOS: rollout strategy 1 - added RCTEnableJSINativeModule(BOOL)
Summary:
To be able to test out new approach for NativeModules, introduce a simple runtime flag to enable the new system (doesn't exist yet). In addition, each module should declare a static `+ (BOOL)allowJSIBinding` in the objc class to be considered for the new approach. Doing so skips the processing of the module during bridge startup.

Note: this doesn't do anything special for `- (NSArray *)extraModulesForBridge:(RCTBridge *)bridge` impl yet.

Differential Revision: D9554296

fbshipit-source-id: 3508db6589e9f72367f62aa7ca15fce3d3adda72
2018-08-29 15:48:59 -07:00
David Aurelio edd22bf49d Log bridge description for e2e reloads
Reviewed By: mhorowitz

Differential Revision: D7577953

fbshipit-source-id: 96871c664cb7ec84570bc76f2edb36ff8c8c6aeb
2018-04-10 19:29:58 -07:00
David Aurelio 48c339ddc7 Add `RCTJavaScriptWillStartExecutingNotification`
Summary:
`RCTJavaScriptWillStartLoadingNotification` is being posted when starting the bridge, not when starting to execute JS code.

Here, we add `RCTJavaScriptWillStartExecutingNotification`, and in post it before executing JS with `RCTCxxBridge`.

Reviewed By: fromcelticpark

Differential Revision: D7153659

fbshipit-source-id: 902075308d54a47bef43b6f57edf2e624f621ceb
2018-03-06 11:05:25 -08:00
Dan Zimmerman 19a4a7d3cb Remove callFunctionSync experimental APIs
Reviewed By: michalgr

Differential Revision: D6124038

fbshipit-source-id: 219afe30783da92cf10f800dc35e64823b61cf4b
2018-03-05 14:32:00 -08:00
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00
Kevin Gozali 5f48bd84aa iOS: allow getting an instance of a js-bound module via the bridge
Reviewed By: sebmarkbage

Differential Revision: D6982785

fbshipit-source-id: 7bbcc5416e1d1a3a577328349a7c18af5c0f8577
2018-02-13 22:38:55 -08:00
Semen Zhydenko d2c569795c Typos in comments and log messages
Summary:
No code changes, no testing required.

alligned -> aligned
allignment -> alignment
completly -> completely
conseptually -> conceptually
decendents -> descendants
indefinetly -> indefinitely
dimention -> dimension
doesnt -> doesn't
safegaurd -> safeguard
intialization -> initialization
hierachy -> hierarchy
happend -> happened
gaurd -> guard
programatically -> programmatically
initalized -> initialized
immidiately -> immediately
occured -> occurred
unkown -> unknown
neccessary -> necessary
neccesarily -> necessarily
occuring -> occurring
comoponent -> component
propogate -> propagate
recieved -> received
referece -> reference
perfomance -> performance
recieving -> receiving
subsquently -> subsequently
scoll -> scroll
suprisingly -> surprisingly
targetting -> targeting
tranform -> transform
symetrical -> symmetrical
wtih -> with
Closes https://github.com/facebook/react-native/pull/17578

Differential Revision: D6718791

Pulled By: shergin

fbshipit-source-id: 4ab79c1131ec5971d35a0c7199eba7ec0a0918ad
2018-01-12 22:18:45 -08:00
Yujie Liu 0b1e6444bb remove embeddedBundleURL
Reviewed By: fromcelticpark

Differential Revision: D6501542

fbshipit-source-id: c6f1adddc4e671f73195afde927face28ee79342
2017-12-12 13:11:14 -08:00
Alex Dvornikov 681278947e Adopt new split segments registration approach on iOS
Differential Revision: D6284479

fbshipit-source-id: d0d7e8c6a6ce4ecab63739149be69f25df7fbe6f
2017-11-09 12:23:49 -08:00
Yujie Liu ae5ef653cb Rename bundleSource to embeddedBundle
Reviewed By: fromcelticpark

Differential Revision: D6274101

fbshipit-source-id: f62da158d165cb3ce4a510ebc4eed24a8a719381
2017-11-09 09:33:00 -08:00
Yujie Liu b983de9c54 Share bundled source URL to RN
Differential Revision: D6192988

fbshipit-source-id: efa584ee2340a34156956990d6cd96d37ba4ab60
2017-11-07 16:46:53 -08:00
Dan Zimmerman 55f75dfd65 Remove the experimental concept of whitelisted modules
Reviewed By: dcaspi

Differential Revision: D6124036

fbshipit-source-id: af3771ce2204b3695f79265d5aade7e321e12a3e
2017-10-25 08:20:48 -07:00
Ben Nham 259161f872 add files changed count to reload metrics
Reviewed By: alexeylang

Differential Revision: D5694813

fbshipit-source-id: 2e2517e60a7547e261a7c15a3a9138dbb3cb9783
2017-08-31 05:34:48 -07:00
Ben Nham 1ce7e4c1e5 add notifications for dev reload
Reviewed By: alexeylang

Differential Revision: D5630472

fbshipit-source-id: 1c44a52fddead361b43551384bbfc73e2d89438f
2017-08-17 17:16:19 -07:00