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

39 Коммитов

Автор SHA1 Сообщение Дата
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Ramanpreet Nara db3625a3b0 Refactor: Move RuntimeExecutor into Instance.cpp
Summary:
RuntimeExecutor is currently declared inside NativeToJsBridge. It doesn't need to be: Instance.cpp can use NativeToJsBridge::runOnExecutorQueue to schedule work on the JS Thread. So, this diff moves RuntimeExecutor out of NativeToJsBridge into Instance.cpp. Now, both the JS CallInvoker and the RuntimeExecutor are declared in the same file.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D27975840

fbshipit-source-id: aa06f479fa24bb7a15bfd21712df5414a183266c
2021-04-23 18:16:03 -07:00
Emily Janzer a4a47b9a1e Expose RuntimeExecutor on CatalystInstance (#28851)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/28851

This diff creates a RuntimeExecutor that uses the bridge and exposes it on CatalystInstanceImpl.

Changelog: [Internal]

Reviewed By: mdvacca, RSNara

Differential Revision: D21051949

fbshipit-source-id: b3977fc14fa19089f33e297d29cedba0d067526d
2020-05-08 16:13:42 -07:00
Ramanpreet Nara eb4e2baaa9 Rename Instance::getNativeCallinvoker to Instance::getDecoratedNativeCallInvoker
Summary:
Now, instead of accepting a `std::function` that schedules work, and returning a `CallInvoker`, `Instance::getDecoratedNativeCallInvoker`  will accept a `CallInvoker` that schedules work, and return a decorated `CallInvoker`.

I think this change will help with readability. It also clarifies that the bridge is adding additional behaviour to the native `CallInvoker`.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20826885

fbshipit-source-id: a2c5681d10a4544ee3d2a0d1f1cbd386ef06d0e6
2020-04-03 09:47:41 -07:00
maciej simka 6f627f684b Split loadApplicationScript into initializeRuntime and loadBundle (#27844)
Summary:
This is the first of three PRs related to enabling multi-bundle support in React Native. More details, motivation and reasoning behind it can be found in RFC [here](https://github.com/react-native-community/discussions-and-proposals/issues/152).

Logic responsible for installing globals was pulled out from `loadApplicationScript` to `initializeRuntime` since it should be ran only once, what was left was renamed to `loadBundle`.

It's based on dratwas work from [here](https://github.com/callstack/react-native/tree/feat/multibundle/split-load-application), but applied to current `master` to avoid rebasing 3-months old branch and issues that come with that.

## Changelog

[Internal] [Changed] - split `loadApplicationScript` into `initializeRuntime` and `loadBundle` to enable multi-bundle support in the future
Pull Request resolved: https://github.com/facebook/react-native/pull/27844

Test Plan: Initialized new RN app with CLI, set RN to build from source and verified the still app builds and runs OK using code from this branch.

Reviewed By: rickhanlonii

Differential Revision: D19888605

Pulled By: ejanzer

fbshipit-source-id: 24ace48ffe8978796591fe7c6cf53a61b127cce6
2020-04-01 17:52:39 -07:00
Ramanpreet Nara 9b94a541d8 Get CallInvokers from the bridge
Summary:
## Context
For now, assume TurboModules doesn't exist.

**What happens when we call an async NativeModule method?**
Everytime JS calls an async NativeModule method, we don't immediately execute it. The legacy infra pushes the call into some queue managed by `MessageQueue.js`. This queue is "flushed" or "emptied" by the following events:
- **Flushed:** A C++ -> JS call. NativeModule async methods can called with an `onSuccess` and/or `onFail` callback(s). Calling `NativeToJsBridge::invokeCallback` to invoke one of these callbacks is one way for ObjC++/C++/Java to call into JS. Another way is via JSModule method calls, which are initiated by `NativeToJsBridge::callFunction`.
- **Flushed:** When `JSIExecutor::flush` is called. Since TurboModules don't exist, this only happens when we call `JSIExecutor::loadApplicationScript`.
- **Emptied:** When more than 5 ms have passed, and the queue hasn't been flushed/emptied, on the next async NativeModule method call, we add to the queue. Afterwards, we empty it, and invoke all the NativeModule method calls.

**So, what's the difference between flushed and emptied?**
> Note: These are two terms I just made up, but the distinction is important.

If the queue was "flushed", and it contained at least one NativeModule method call, `JsToNativeBridge` dispatches the `onBatchComplete` event. On Android, the UIManager module is the only module that listens to this event. This `onBatchComplete` event doesn't fire if the queue was "emptied".

**Why does any of this matter?**
1. TurboModules exist.
2. We need the TurboModules infra to have `JsToNativeBridge` dispatch `onBatchComplete`, which depends on:
   - **Problem 1:** The queue being flushed on calls into JS from Java/C++/ObjC++.
   - **Problem 2:** There being queued up NativeModule async method calls when the queue is flushed.

In D14656466, fkgozali fixed Problem 1 by making every C++/Java/Obj -> JS call from TurboModules also execute `JSIExecutor::flush()`. This means that, with TurboModules, we flush the NativeModule async method call queue as often as we do without TurboModules. So far, so good. However, we still have one big problem: As we convert more NativeModules to TurboModules, the average size of the queue of NativeModule method calls will become smaller and smaller, because more NativeModule method calls will be TurboModule method calls. This queue will more often be empty than not. Therefore, we'll end up dispatching the `onBatchComplete` event less often with TurboModules enabled. So, somehow, when we're about to flush the NativeModule method call queue, we need `JsToNativeBridge` to understand that we've executed TurboModule method calls in the batch. These calls would have normally been queued, which would have led the queue size to be non-zero. So if, during a batch, some TurboModule async method calls were executed, `JsToNativeBridge` should dispatch `onBatchComplete`.

**So, what does this diff do?**
1. Make `Instance` responsible for creating the JS `CallInvoker`.
2. Make `NativeToJsBridge` responsible for creating the native `CallInvoker`. `Instance` calls into `NativeToJsBridge` to get  the native `CallInvoker`.
3. Hook up `CatalystInstanceImpl`, the Android bridge, with the new JS `CallInvoker`, and the new native `CallInvoker`. This fixes `onBatchComplete` on Android. iOS work is pending.

Changelog:
[Android][Fixed] - Ensure `onBatchComplete` is dispatched correctly with TurboModules

Reviewed By: mdvacca

Differential Revision: D20717931

fbshipit-source-id: bc3ccbd6c135b7f084edbc6ddb4d1e3c0c7e0875
2020-04-01 11:39:18 -07:00
Valentin Shergin ede2c5031f Codemod: Clang-format for all files in `ReactCommon` directory
Summary:
We are moving towards 100%-prettified files. That's the first step when we apply Clang Format for `ReactCommon`.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20110895

fbshipit-source-id: 0a0ce4997cf1c3721b0b07ef78c1a57ce87d20f9
2020-02-25 19:52:27 -08:00
Andres Suarez 722feeb02b Tidy up license headers [1/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952695

fbshipit-source-id: 81aa607612ba1357ef7814ef20371335151afe7e
2019-10-16 10:06:33 -07:00
Anandraj 75a7a52db4 fixing ATOMIC_VAR_INIT call (#26238)
Summary:
We're trying to build react-native on Windows (part of the Microsoft\react-native-windows project) with MSVC compiler with WITH_FBSYSTRACE set to true (to route the traces to ETW). This change is to fix a compilation error due to the non standard usage of ATOMIC_VAR_INIT macro called with no parameters. It's not absolutely clear to me the objective of this macro in the standard at all (to be used in c context ?), and which compiler does support this parameterless version (gcc?).

Also, I'm more inclined towards changing the statement to just "std::atomic_uint_least32_t m_systraceCookie{};". Please confirm.

## Changelog

[General] [Fixed] - Removing the non-standard usage of ATOMIC_VAR_INIT macro from code with systrace enabled
Pull Request resolved: https://github.com/facebook/react-native/pull/26238

Test Plan: Build verification should suffice as there is no semantic change introduced by this change.

Differential Revision: D17259213

Pulled By: cpojer

fbshipit-source-id: 9fe44f9220f18399a58f94f0f01d5fa93e6458e0
2019-09-09 07:55:25 -07:00
Marc Horowitz 0735873fbc Make isInspectable safe to call from any thread
Summary: The bridge was not properly isolating isInspectable onto the JS thread.

Reviewed By: fkgozali

Differential Revision: D14991970

fbshipit-source-id: 92a06c90bade8f92bfa81fa3b7dfb23b17db6117
2019-04-17 21:23:19 -07:00
Kevin Gozali a43e666a34 TM iOS: force flush message queue when calling into JS from native
Summary: When calling into JS (e.g. promise resolve/reject, callback) in TurboModule, we bypass the bridge's message queue. At times this causes race condition, where there are a bunch of pending UI operations (in RCTUImanager) waiting to be flushed, but nothing adds calls to the message queue. Usually tapping the screen will trigger the flush because we're sending down touch events to JS.

Reviewed By: JoshuaGross

Differential Revision: D14656466

fbshipit-source-id: cb3a174e97542bf80f0a37b4170b6a8e6780fa35
2019-03-29 01:39:39 -07:00
zhongwuzw d55558e138 Fix isBatchActive of RCTCxxBridge (#22785)
Summary:
Seems we lost handler of `isBatchActive` from [RCTBatchedBridge a86171a](a86171a482/React/Base/RCTBatchedBridge.m) to [RCTCxxBridge 5bc7e39](b774820dc2 (diff-a2a67635fffd7b690d14dc17ae563a71)).

Changelog:
----------

[iOS] [fixed] - Fix isBatchActive of RCTCxxBridge
Pull Request resolved: https://github.com/facebook/react-native/pull/22785

Reviewed By: mhorowitz

Differential Revision: D13731897

Pulled By: cpojer

fbshipit-source-id: 8d6b85bcea8fe8997a93b4e1ac8b8007422ca20e
2019-01-21 00:28:48 -08: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 201ba8c69d Catch JS bundle load failure and prevent calls to JS after that
Summary: There are cases where JS bundle fails to be evaluated, which throws an exception already, but then there were pending calls into JS which would fail in a weird way. This prevents those calls (because it's mostly meaningless at that point). For now, those extra calls will still throw an exception, but with a specific message so that it doesn't confuse people.

Reviewed By: yungsters

Differential Revision: D8961622

fbshipit-source-id: 3f67fb63fdfa9fc5b249de0096e893b07956776a
2018-07-24 19:48:32 -07:00
Héctor Ramos da7873563b Migrate Android sources to MIT license header
Reviewed By: fkgozali

Differential Revision: D8065619

fbshipit-source-id: 719c303b40c96950bab8e5dde9a75f449b2956c6
2018-05-31 15:37:30 -07:00
Marc Horowitz 042449f24a simplify handleMemoryPressure conditionalization, delete some dead code
Reviewed By: javache

Differential Revision: D7803912

fbshipit-source-id: 0bab4be07fc006a208caa75f94b5716c99b5d265
2018-05-09 22:12:03 -07: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
Ben Nham 15cd98b782 add isInspectable property
Reviewed By: Hypuk

Differential Revision: D6578736

fbshipit-source-id: a4229c3766125ff55cff50a49893b2385f9c8a6a
2017-12-18 13:32:36 -08:00
Alex Dvornikov cff0d8e0e5 Register split segment paths with RAMBundleRegistry
Differential Revision: D6284466

fbshipit-source-id: c80cf929af38f92f06cca5b366c58785ae992d83
2017-11-09 12:23:46 -08:00
Alex Dvornikov 7d115730dc Configure JSExector with BundleRegistry instead of JSModulesUnbundle
Differential Revision: D5890458

fbshipit-source-id: 968be95786ffbf53aa98928d4d3e3bd52a84b3dc
2017-09-22 09:58:46 -07:00
Jia Li 0aa12939fd Revert D5850968: Configure JSExector with BundleRegistry instead of JSModulesUnbundle.
Differential Revision: D5850968

fbshipit-source-id: f4c9dc8d5f14cdd32195463e8786242e708770e9
2017-09-21 21:22:39 -07:00
Alex Dvornikov 79821917fa Configure JSExector with BundleRegistry instead of JSModulesUnbundle.
Differential Revision: D5850968

fbshipit-source-id: e5e7ad92c2347c2641551fcf820f061ffde5fed6
2017-09-21 08:51:00 -07:00
Pieter De Baets ed3c018ee4 Remove legacy JSC profiler
Reviewed By: bnham

Differential Revision: D5433406

fbshipit-source-id: 8cbea8b9b46a0d9f29c57a5bcf605e6bb61ed8a7
2017-07-20 04:21:16 -07:00
Pieter De Baets 83faa4b608 Simplify Catalyst handleMemoryPressure
Reviewed By: cwdick

Differential Revision: D5200555

fbshipit-source-id: 86f12acca33ece265d3482ba52de9afcc83173cd
2017-06-26 06:01:14 -07:00
Pieter De Baets e2628f93b5 Rename Executor to JSExecutor
Summary:
* Cleanup some header files so we use more forward declarations
* Rename Executor to JSExecutor.h
* Move some typedefs to more appropriate locations

Reviewed By: mhorowitz

Differential Revision: D5301913

fbshipit-source-id: e75154797eb3f531d2f42a5e95409f4062b85f91
2017-06-23 17:01:25 -07:00
Pieter De Baets 34bc6bd2ae Drop support for webworkers
Reviewed By: AaaChiuuu

Differential Revision: D4916449

fbshipit-source-id: a447233d3b7cfee98db2ce00f1c0505d513e2429
2017-04-25 05:37:54 -07:00
Pieter De Baets d7b37c4050 Remove JsToNativeBridge's nativeQueue
Reviewed By: mhorowitz

Differential Revision: D4589737

fbshipit-source-id: 3b2730417d99c4f98cfaad386bc50328f2551592
2017-03-17 07:08:14 -07:00
Ashok Menon 14dc219810 Deleting Optimized Bundle!
Reviewed By: javache

Differential Revision: D4566164

fbshipit-source-id: 1fbd3dd04f24399e93e3c6ec58956e6e18f1683f
2017-02-16 13:30:55 -08:00
Sean Kinsey c38d56d9db Expose the bridge instance to CxxModule via a weak_ptr
Summary:
In order for `CxxModule` modules to be able to do things like emit events, we need to expose the bridge instance.

To allow classes derived from `CxxModule` in other projects to include `<cxxreact/Instance.h> I also needed to convert all the header includes to non-relative  ones.

Reviewed By: javache

Differential Revision: D4564145

fbshipit-source-id: a5bc28dd9b40e2b141af9e867105c56083fbdcdc
2017-02-15 10:04:17 -08:00
Alexander Blom ddb8cb7cf0 Move JSCHelpers.h and Value.h into separate package
Reviewed By: javache

Differential Revision: D3950748

fbshipit-source-id: 6315ea07f3217b485aeb4374b5f6e36333957848
2016-11-01 11:44:10 -07:00
Marc Horowitz d7a2d3a957 Add API for sync function calls
Reviewed By: javache

Differential Revision: D3897526

fbshipit-source-id: cadead316996ca7c1dd2b0d60d87945f5452640c
2016-09-26 16:14:11 -07:00
Marc Horowitz 6071e8ca2c Support sync loading of the initial bundle/source
Reviewed By: javache

Differential Revision: D3897521

fbshipit-source-id: a4f234c7003a5f4be952d315eb62f382836e24dc
2016-09-26 16:14:11 -07:00
Marc Horowitz 971cda8794 Move thread jump for js loading into NativeToJSBridge, out of platform code
Reviewed By: javache

Differential Revision: D3906009

fbshipit-source-id: b9782a6c209e3c1626899dac7fd50233cdef87f3
2016-09-26 16:14:10 -07:00
Michał Gregorczyk 3c0f428f05 Fix optimized bundle stuff.
Reviewed By: davidaurelio, tadeuzagallo

Differential Revision: D3563710

fbshipit-source-id: 2b0a982d388ee5f44b806f8e561ef49a3fd8c8ca
2016-07-14 15:28:46 -07:00
David Aurelio df01215006 Reverted commit D3545345
Reviewed By: tadeuzagallo

Differential Revision: D3545345

fbshipit-source-id: d655918be7dcadaf8143800497e85f3de44bd48a
2016-07-14 10:58:27 -07:00
Michał Gregorczyk 1331e20db5 add API to CatalystInstanceImpl for executing optimized bundle
Reviewed By: tadeuzagallo

Differential Revision: D3545345

fbshipit-source-id: 538fec77b816c3fd767e8c2eda81c78971996b17
2016-07-12 08:13:32 -07:00
Alexander Blom be0abd17e5 Remove a bunch of copies
Reviewed By: astreet

Differential Revision: D3475592

fbshipit-source-id: 37148bb8d8d47e9301ad549b183029337f7c4ca0
2016-07-07 09:00:01 -07:00
Alexander Blom 95401aba72 Create tracing name in C++ instead of Java
Reviewed By: mhorowitz

Differential Revision: D3469140

fbshipit-source-id: 77a00a7150573e44f219972556cbb936a57d7054
2016-07-07 09:00:00 -07:00
Chris Hopman 5e8f1716fc Build new bridge with gradle
Reviewed By: bestander

Differential Revision: D3324351

fbshipit-source-id: 41fa18a23c8661440a7deff244c93278f418e1d9
2016-05-27 16:13:37 -07:00