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

56 Коммитов

Автор SHA1 Сообщение Дата
Donald Webster 9a43e53a06 Revert D40613108: 4/n Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs - Try 2
Differential Revision:
D40613108 (5449148482)

Original commit changeset: f36c3b39a216

Original Phabricator Diff: D40613108 (5449148482)

fbshipit-source-id: 079deac137610eeebd231bd97930efda6b284fff
2022-10-24 08:56:55 -07:00
Paige Sun 5449148482 4/n Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs - Try 2
Summary:
Changelog: [iOS][Changed] Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs

-----

# A0) Bridge mode, Unhandled Exception, FBiOS
Unhandled exception goes to FBReactModule, but the JS Stack is not parsed correctly.
https://www.internalfb.com/code/fbsource/[312d5cbdd7278247a84619786b12a44c4400fcc0]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=1488%2C1493

See `****** FBReactModule handleFatalError` in the logs P539306390, and compare with correct behavior in (A1) in the Test Plan.

https://pxl.cl/2h6h3

{F782257996}

-----

# A) Before diff, rn-tester
Open to rn-tester -> APIs -> Crash Examples -> JS Crash.

Set `RCTParseUnhandledJSErrorStackNatively` to YES.
https://www.internalfb.com/code/fbsource/[98880e52ee78be3614e5d9a2ce3292f6a7b5e413]/xplat/js/react-native-github/React/Base/RCTConstants.m?lines=73

{F783395297}

----

build_on_commit[ios_fbios-arm64-dylibs-jackalope-iphoneos-production_build]

Reviewed By: RSNara

Differential Revision: D40613108

fbshipit-source-id: f36c3b39a2167402ee3730db8b40b53a0b80aa60
2022-10-23 16:42:00 -07:00
Donald Webster 9e68eea2c8 Revert D40387938: 4/n Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs
Differential Revision:
D40387938 (ff398e4e26)

Original commit changeset: 2abea657476d

Original Phabricator Diff: D40387938 (ff398e4e26)

fbshipit-source-id: 0b5dbe417abf25d5723c70337189dfb42570e56d
2022-10-21 12:59:54 -07:00
Paige Sun ff398e4e26 4/n Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs
Summary:
Changelog: [iOS][Changed] Display a RedBox with the JS stack (instead of native stack) when an unhandled JS exceptions occurs

-----

# A0) Bridge mode, Unhandled Exception, FBiOS
Unhandled exception goes to FBReactModule, but the JS Stack is not parsed correctly.
https://www.internalfb.com/code/fbsource/[312d5cbdd7278247a84619786b12a44c4400fcc0]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=1488%2C1493

See `****** FBReactModule handleFatalError` in the logs P539306390, and compare with correct behavior in (A1) in the Test Plan.

https://pxl.cl/2h6h3

{F782257996}

-----

# A) Before diff, rn-tester
Open to rn-tester -> APIs -> Crash Examples -> JS Crash.

Set `RCTParseUnhandledJSErrorStackNatively` to YES.
https://www.internalfb.com/code/fbsource/[98880e52ee78be3614e5d9a2ce3292f6a7b5e413]/xplat/js/react-native-github/React/Base/RCTConstants.m?lines=73

{F783395297}

Reviewed By: sammy-SC

Differential Revision: D40387938

fbshipit-source-id: 2abea657476d3bf61ad5b1c643f129e44c6f3f35
2022-10-20 21:12:41 -07:00
Christoph Purrer 9cb716ff76 Add additional Systrace support
Summary:
Adding support for application to hook into further tracing methods

## Changelog

[General][Added] - Add additional Systrace support

Reviewed By: NickGerleman

Differential Revision: D38673212

fbshipit-source-id: 55a90a0cd57809bca5f01da7acddcf253e5852ba
2022-09-14 16:29:20 -07:00
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
Scott Kyle 2f62c2892d Fix crash in RCTCoreModulesClassProvider during quit
Summary:
This intentionally leaks the static map, since it still might be accessed after static destructors are run. This is a common approach to this problem, see https://github.com/facebook/react-native/pull/22607 and https://github.com/facebook/componentkit/pull/906 as examples. It also sets up an autorelease pool from  `RCTNativeModule::invoke` as a precaution since there's no strict guarantee one exists when it is called.

Changelog:
[iOS][Fixed] - Fix crash in RCTCoreModulesClassProvider during quit

Reviewed By: RSNara

Differential Revision: D27932062

fbshipit-source-id: fa75da4b78290027a762440ac6943c81b8594a57
2021-04-28 13:29:06 -07:00
Valentin Shergin 1b994f9ddd Proxing NSException stack trace to NSError object
Summary:
When we catch an Objective-C exception and convert it to NSError we need to somehow represent the call stack from NSException instance in NSError instance. For now, we just attach the stack trace to `message` field.

The next step would be to figure out how to pass the Objective-C stack trace to error reporting infra to help it to display the stack trace nicely in the web interface.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D23557600

fbshipit-source-id: a080c2e186e719e42dcfc01bb12f5811e3c5b2e6
2020-09-08 13:22:54 -07:00
Ramanpreet Nara 4830085f40 Guard all NativeModulePerfLogger calls with a null check
Summary:
## Motivation
We got this crash T67304907, which shows a `EXC_BAD_ACCESS / KERN_INVALID_ADDRESS` when calling this line:
```
  NativeModulePerfLogger::getInstance().asyncMethodCallBatchPreprocessStart();
```
There are no arguments in that call, so I figured the only error could be when we try to invoke `getInstance()` or `asyncMethodCallBatchPreprocessStart()`.

This diff:
1. Removes the `NativeModulePerfLogger::getInstance()` bit. Now NativeModulePerfLogger is used via regular static C functions. So, there's no way that simply invoking one of the logging functions crashes the application: there's no vtable lookup.
2. Inside each logging function, when perf-logging is disabled, the global perflogger should be `nullptr`. This diff makes it so that in that case, we won't execute any code in the control group of the perf-logging experiment.

## Changes
**How do we enable NativeModule perf-logging?**
- Previously:
   - `NativeModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`
   - `TurboModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`.
- Now:
   - `BridgeNativeModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`
   - `TurboModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`

**How do we do NativeModule perf-logging now?**
- Previously:
   -  `NativeModulePerfLogger::getInstance().command(...args)`
   -  `TurboModulePerfLogger::getInstance().command(...args)`.
- Now:
   - `BridgeNativeModulePerfLogger::command(...args)`
   - `TurboModulePerfLogger::command(...args)`.

The benefit of this approach is that each method in `BridgeNativeModulePerfLogger` is guarded with an if check. Example:

```
void moduleCreateConstructStart(const char *moduleName, int32_t id) {
  NativeModulePerfLogger *logger = g_perfLogger.get();
  if (logger != nullptr) {
    logger->moduleCreateConstructStart(moduleName, id);
  }
}
```

Therefore, we don't actually execute any code when perf-logging is disabled.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D21669888

fbshipit-source-id: 80c73754c430ce787404b563878bad146295e01f
2020-05-20 20:19:30 -07:00
Ramanpreet Nara eb2a561ecb Rename <ReactCommon/NativeModulePerfLogger.h> to <reactperflogger/NativeModulePerfLogger.h>
Summary:
## Motivation
This rename will fix the following CircleCI build failures:
- [test_ios_unit_frameworks](https://circleci.com/gh/facebook/react-native/150473?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link)
- [test_ios_detox_frameworks](https://circleci.com/gh/facebook/react-native/150474?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link)

## Investigation
We have 4 podspec targets that map to the same header namespace (i.e: `header_dir`) `ReactCommon`:
- **New:** `React-perflogger`: Directory is `ReactCommon/preflogger`, and contains `NativeModulePerfLogger.{h,cpp}`.
- `React-runtimeexecutor`: Directory is `ReactCommon/runtimeexecutor`, and contains only `RuntimeExecutor.h`
- `React-callinvoker`: Directory is `ReactCommon/callinvoker`, and contains only `CallInvoker.h`
- `ReactCommon/turbomodule/core`: Directory is `ReactCommon/turbomodule`, and contains C++ files, as well has header files.

**The problem:**
We couldn't import headers from `React-perflogger` in `ReactCommon/turbomodule/core` files.

**The cause:**
I'm not entirely sure why, but I was able to discern the following two rules by playing around with the podspecs:
1. If your podspec target has a cpp file, it'll generate a framework when `USE_FRAMEWORKS=1`.
2. Two different frameworks cannot map to the same `module_name` or `header_dir`. (Why? No clue. But something breaks silently when this is the case).

So, this is what happened when I landed `React-perflogger` (D21443610):
1. The TurboModules code generates the `ReactCommon` framework that uses the `ReactCommon` header namespace.
2. `React-runtimeexecutor` and `React-callinvoker` also used the `ReactCommon` header namespace. However, neither generate a framework because of Rule 1.
3. When I comitted `React-perflogger`, I introduced a second framework that competed with the `ReactCommon` framework (i.e: TurboModules code) for the `ReactCommon` header namespace. Rule 2 violation.

## Thoughts on renaming
- `<perflogger/NativeModulePerfLogger.h>` is too generic, and the `perflogger` namepsace is used internally within FB.
- `<react/perflogger/NativeModulePerfLogger.h>` matches our fabric header format, but I'm pretty sure that slashes aren't allowed in `header_dir`: I tested this and it didn't work. IIRC, only alphanumeric and underscore are valid characters for `header_dir` or `module_name`. So, I opted to just use `reactperflogger`.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D21598852

fbshipit-source-id: 60da5d0f7758eaf13907a080b7d8756688f40723
2020-05-15 15:25:23 -07:00
Keegan Mendonca 2b0208b399 Revert D21585006: Rename <ReactCommon/NativeModulePerfLogger.h> to <reactperflogger/NativeModulePerfLogger.h>
Differential Revision:
D21585006

Original commit changeset: e3339273af5d

fbshipit-source-id: cb4ff227edcc16842c7539bf71c912cd4ec478e0
2020-05-14 21:48:44 -07:00
Ramanpreet Nara 9f3c7af400 Rename <ReactCommon/NativeModulePerfLogger.h> to <reactperflogger/NativeModulePerfLogger.h>
Summary:
## Motivation
This rename will fix the following CircleCI build failures:
- [test_ios_unit_frameworks](https://circleci.com/gh/facebook/react-native/150473?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link)
- [test_ios_detox_frameworks](https://circleci.com/gh/facebook/react-native/150474?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link)

## Investigation
We have 4 podspec targets that map to the same header namespace (i.e: `header_dir`) `ReactCommon`:
- **New:** `React-perflogger`: Directory is `ReactCommon/preflogger`, and contains `NativeModulePerfLogger.{h,cpp}`.
- `React-runtimeexecutor`: Directory is `ReactCommon/runtimeexecutor`, and contains only `RuntimeExecutor.h`
- `React-callinvoker`: Directory is `ReactCommon/callinvoker`, and contains only `CallInvoker.h`
- `ReactCommon/turbomodule/core`: Directory is `ReactCommon/turbomodule`, and contains C++ files, as well has header files.

**The problem:**
We couldn't import headers from `React-perflogger` in `ReactCommon/turbomodule/core` files.

**The cause:**
I'm not entirely sure why, but I was able to discern the following two rules by playing around with the podspecs:
1. If your podspec target has a cpp file, it'll generate a framework when `USE_FRAMEWORKS=1`.
2. Two different frameworks cannot map to the same `module_name` or `header_dir`. (Why? No clue. But something breaks silently when this is the case).

So, this is what happened when I landed `React-perflogger` (D21443610):
1. The TurboModules code generates the `ReactCommon` framework that uses the `ReactCommon` header namespace.
2. `React-runtimeexecutor` and `React-callinvoker` also used the `ReactCommon` header namespace. However, neither generate a framework because of Rule 1.
3. When I comitted `React-perflogger`, I introduced a second framework that competed with the `ReactCommon` framework (i.e: TurboModules code) for the `ReactCommon` header namespace. Rule 2 violation.

## Thoughts on renaming
- `<perflogger/NativeModulePerfLogger.h>` is too generic, and the `perflogger` namepsace is used internally within FB.
- `<react/perflogger/NativeModulePerfLogger.h>` matches our fabric header format, but I'm pretty sure that slashes aren't allowed in `header_dir`: I tested this and it didn't work. IIRC, only alphanumeric and underscore are valid characters for `header_dir` or `module_name`. So, I opted to just use `reactperflogger`.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D21585006

fbshipit-source-id: e3339273af5dfd65a1454d87213d1221de6a4651
2020-05-14 20:54:57 -07:00
Ramanpreet Nara 0b8a82a6ee Instrument sync and async method calls (#28893)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/28893

`JSIExecutor::callSerializableNativeHook` converts the arguments from `JSI::Value` to `folly::dynamic`. Then, `RCTNativeModule` converts the arguments from `folly::dynamic` to ObjC data structures in its `static invokeInner` function.

Therefore, I decided to start the sync markers inside `JSIExecutor::callSerializableNativeHook`, which required me to expose these two methode `ModuleRegistry::getModuleName` and `ModuleRegistry::getModuleSyncMethodName`. This shouldn't modify performance because we eagerly generate a NativeModule's methods when it's first required. So, at worst, this is doing a cache lookup.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D21443610

fbshipit-source-id: 67cf563b0b06153e56e63ba7e186eea31eafc853
2020-05-13 20:28:18 -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
Joe Loser ba18ee9b87 Replace folly::make_unique with std::make_unique (#26730)
Summary:
There is a mixed usage of `folly::make_unique` and `std::make_unique`. Soon, `folly::make_unique` may be removed (see [this PR](https://github.com/facebook/folly/pull/1150)). Since `react-native` only supports C++14-compilers and later, switch to always using `std::make_unique`.

## Changelog

[Internal] [Removed] - Replace folly::make_unique with std::make_unique
Pull Request resolved: https://github.com/facebook/react-native/pull/26730

Test Plan:
Running the existing test suite. No change in behavior is expected.

Joshua Gross: buck install -r fb4a, make sure MP Home and forced teardown works okay on android

Reviewed By: shergin

Differential Revision: D18062400

Pulled By: JoshuaGross

fbshipit-source-id: 978ca794c7e972db872a8dcc57c31bdec7451481
2019-10-22 12:21:41 -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
Anatolii Shevchenko d8e335df0e Remove ; from method implementation definition
Summary: Removing excessive semicolon ";" symbol from method implementation definition.

Reviewed By: adamjernst

Differential Revision: D16912006

fbshipit-source-id: 9c3e778a107e8fd0055f40a95ea9ca58d461e1c5
2019-08-21 15:49:16 -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
ericlewis 01033d16ec Silence Xcode warning (#23880)
Summary:
Fixes a warning in React Xcode proj. Should be a trivial change.

[iOS] [Fixed] - uncaptured lambda warning
Pull Request resolved: https://github.com/facebook/react-native/pull/23880

Differential Revision: D14435848

Pulled By: cpojer

fbshipit-source-id: 83c126c7401ac32b769ff17172f4f4ae576bd771
2019-03-12 22:08:21 -07:00
Pavlos Vinieratos 629708beda Crash reporting heaven (#23691)
Summary:
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
I have used RN for a long time, and for all this time, crash reporting has been less great than native development crash reporting. At some point, companies like sentry, bugsnag and a bunch of others started supporting sourcemaps for js crashes in RN, which helped a lot.
But native crashes were (and still are) much harder to diagnose.

..Until now :D

I have make a repo of a sample RN app, included this PR in it, and some code and screenshots to help.
The repo is [here](https://github.com/pvinis/react-native-project-with-crash-heaven-pr).

I was trying to get good crash reports from native crashes in iOS for a looong time. I spoke with people in sentry, in bugsnag and more, and I could not get this solved. There was no clear way to get the **native** crashed to display correctly.
I made two repos here, one for [sentry](https://github.com/pvinis/SentryBadStack) and one for [bugsnag](https://github.com/pvinis/BugsnagBadStack), demonstrating the correct js handling and the bad native handling.

After all this, and talks with their support, twitter etc, I investigated further, on **why** this was happening. I thought there must be some reason that native crashes look bad in all the tools, and in the same way. Maybe it's not their fault, or up to them to fix it, or maybe they didn't have the experience to fix it.

In a test project I created, I checked what's up with the `RCTFatalException`, and I found out that the React Native code is catching the `NSException`s that come from any native modules of a RN app and converting it into an string and sending it to `RCTFatal` that created an `NSError` out of that string. Then it checks if the app has set a fatal error handler and if not, goes ahead and throws that `NSError`.

The problem here is that `NSException` has a bunch more info that the resulting `NSError` is missing or is altering. Turning the callstack into a string renders crash reporting tools useless as they are missing the original place the exception was thrown, symbols, return addresses etc. In both repos above it can be seen that both tools were thinking that the error happened somewhere in the `RCTFatal` function, and it did, since we create it there, losing all the previous useful info of the original exception. That leaves us with just a very long name including a callstack, but very hard to actually map this to the code and dsym.

I added a fatal exception handler, that mirrors the fatal error handler, as the error handler is used around React Native internal code.

Then I stopped making a string out of the original `NSException` and calling `RCTFatal`, and I simply throw the exception. This way no info is lost!

Finally, I added some code examples of native and js crashes and added a part in the `RNTester` app, so people can see how a js and a native error look like while debugging, as well as try to compile the app in release mode and see how the crash report would look like if they connect it to bugsnag or sentry or their tool of choice.

I have attached some images at the bottom of this PR, and you can find some in the 3 repos I linked above.

[iOS] [Fixed] - Changed the way iOS native module exceptions get handled. Instead of making them into an `NSError` and lose the context and callstack, we keep them as `NSException`s and propagate them.
[General] [Added] - Example code for native crashes in iOS and Android, with buttons on RNTester, so developers can see how these look when debugging, as well as the crash reports in release mode.
Pull Request resolved: https://github.com/facebook/react-native/pull/23691

Reviewed By: fkgozali

Differential Revision: D14276366

Pulled By: cpojer

fbshipit-source-id: b308d5608e1432d7676447347ae77c0721094e62
2019-03-12 19:41:51 -07:00
aleclarson dc893756b8 Properly validate JS->native method calls (#23658)
Summary:
Between invalidating a bridge and suspending its JS thread, native modules may have their methods called.

Only warn when a native module has been invalidated, which happens right before its JS thread is suspended.

Avoid initializing a native module's instance if its bridge is invalidated.

/cc fkgozali f945212447 (commitcomment-32467567)

[iOS] [Fixed] - Properly validate JS->native method calls
Pull Request resolved: https://github.com/facebook/react-native/pull/23658

Differential Revision: D14287594

Pulled By: fkgozali

fbshipit-source-id: 89dd1906a0c55f3f48ba4ff220aac0cddf2eb822
2019-03-04 17:39:53 -08:00
Yedidya Feldblum fc91bccd53 Add assorted missing includes in xplat
Summary: Add assorted missing includes in `xplat` that would be exposed by future changes.

Reviewed By: ispeters, nlutsenko

Differential Revision: D14213660

fbshipit-source-id: 329f133784015fe20ee99feaec8ef05e117fe3a6
2019-02-28 00:52:48 -08:00
ericlewis 918620bdcb Fix xcode warnings (#23648)
Summary:
Fixes yet more Xcode warnings.

[iOS] [Fixed] - Xcode warnings
Pull Request resolved: https://github.com/facebook/react-native/pull/23648

Differential Revision: D14214231

Pulled By: hramos

fbshipit-source-id: 050ab8519ca77941894b650b1c56bfcbe86e2c69
2019-02-25 14:30:39 -08:00
Agustin Collazo 536045276c iOS downgrade invalid bridge warning (#23557)
Summary:
I downgrade the invalid bridge warning because I believe that it is a pain that every time that the JS gets refreshed this warnings are being thrown. If the project increase size and more and more NativeModules are added this warnings just spam the emulator or the device.

I understand the reason of validating if the bridge is valid. However in case of invalidness nothing is done, just the warning is thrown. Hence, the reason of downgrading it to improve the development process.

The error message still exist and it will be in the logs. But it will not spam the development screen

[iOS] [Changed] - Downgrade the Invalid bridge warning message to a log
Pull Request resolved: https://github.com/facebook/react-native/pull/23557

Differential Revision: D14161290

Pulled By: cpojer

fbshipit-source-id: e5608a9b2db5625309fd18d133fe69a9013043f3
2019-02-20 19:07:36 -08:00
Ramanpreet Nara f37093319b Start using getConstants
Summary:
TurboModules depend on a getConstants method. Existing ObjectiveC modules do not have this method. Therefore, I moved the contents of `constantsToExport` to `getConstants` and then had `constantsToExports` call `getConstants`.

facebook
Since all NativeModules will eventually need to be migrated to the TurboModule system, I didn't restrict this to just the NativeModules in Marketplace.

```
const fs = require('fs');

if (process.argv.length < 3) {
    throw new Error('Expected a file containing a list of native modules as the third param');
}

function read(filename) {
    return fs.readFileSync(filename, 'utf8');
}

const nativeModuleFilenames = read(process.argv[2]).split('\n').filter(Boolean);

nativeModuleFilenames.forEach((fileName) => {
    if (fileName.endsWith('.h')) {
        return;
    }

    const absPath = `${process.env.HOME}/${fileName}`;
    const fileSource = read(absPath);

    if (/(\n|^)-\s*\((.+)\)getConstants/.test(fileSource)) {
        return;
    }

    const constantsToExportRegex = /(\n|^)-\s*\((.+)\)constantsToExport/;
    const result = constantsToExportRegex.exec(fileSource);

    if (result == null) {
        throw new Error(`Didn't find a constantsToExport function inside NativeModule ${fileName}`);
    }

    const returnType = result[2];

    const newFileSource = fileSource.replace(
        constantsToExportRegex,
        '$1- ($2)constantsToExport\n' +
        '{\n' +
        `  return ${returnType.includes('ModuleConstants') ? '($2)' : ''}[self getConstants];\n` +
        '}\n' +
        '\n' +
        '- ($2)getConstants'
    );

    fs.writeFileSync(absPath, newFileSource);
});
```

```
> xbgs -l ')constantsToExport'
```

Reviewed By: fkgozali

Differential Revision: D13951197

fbshipit-source-id: 394a319d42aff466c56a3d748e17c335307a8f47
2019-02-04 17:46:56 -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 f945212447 iOS downgrade error to warning when invoking native module with invalid bridge
Summary: A bunch of flows including JS reload and e2e tests seem to hit the race condition, causing redbox. For now, make it a warning to unblock.

Differential Revision: D9327418

fbshipit-source-id: a72b378d88f7566268fd9415fbd34225c8b931e7
2018-08-14 18:19:01 -07:00
Kevin Gozali 29245e96cb iOS: prevent nativemodule access from JS if bridge is no longer valid
Summary: This helps prevent race condition where JS calls to NativeModules got queued and executed while the bridge is invalidating itself, causing assertion failures in test setup (for example). It won't prevent it 100% of the time, due to threading (and adding lock is expensive for each nativemodule call).

Reviewed By: yungsters

Differential Revision: D9231636

fbshipit-source-id: 298eaf52ffa4b84108184124e75b206b9ca7a41d
2018-08-09 12:17:07 -07: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
Alex Dvornikov 0ac5a5230c Make RCTNativeModule::invokeInner explicitely return folly::none in case of error
Differential Revision: D6347967

fbshipit-source-id: 88788da321ca75d20b6c1a8e3d41642af7c6155e
2017-11-17 03:17:20 -08:00
Alex Dvornikov d07279c978 Remove usage of "this" in a callback in RCTNativeModule
Summary: As RCTNativeModule can be destructed at any time, it's unsafe to capture "this" in a callback.

Reviewed By: javache

Differential Revision: D5963728

fbshipit-source-id: c80a01c851d97813e4fead2b31c442eaeb8ae204
2017-10-04 06:00:09 -07:00
Alex Dvornikov 47f6068b16 Log call stack symbols in case of native module method's failure
Differential Revision: D5921069

fbshipit-source-id: c386a836e6f3c314d668e02f3bae243dadcab6e3
2017-09-27 10:00:33 -07:00
Alex Dvornikov 29e7659111 Use const reference in RCTNativeModule::invokeInner
Reviewed By: mhorowitz

Differential Revision: D5909088

fbshipit-source-id: 3104e3d0a4b29d457c3c7fad2a29e2f0943b478d
2017-09-25 20:39:16 -07:00
Pieter De Baets 7b770556ac Improve RCTCxxBridge invalidation
Reviewed By: fromcelticpark

Differential Revision: D5536063

fbshipit-source-id: b0f19bebea839c7da84890c338ad4d38293bc99c
2017-09-11 04:30:31 -07:00
Dave Lee 0e3117c972 Fix format specifier used in RCTCxxMethod
Summary:
[`CxxModule::Method::callbacks`](2161f92aaf/ReactCommon/cxxreact/CxxModule.h (L66)) is `size_t` which uses `%zu` as the format specifier. Newer versions of clang can warn or error on this. This change prevents that from happening.

Local builds with clang 5.
Closes https://github.com/facebook/react-native/pull/15402

Differential Revision: D5583710

Pulled By: javache

fbshipit-source-id: 1d1e740c275fddfea177cf9476cd1d03b7e27330
2017-08-08 11:55:17 -07:00
Pieter De Baets d42ccca2e1 Allow native modules to customize the main-thread init behaviour
Summary:
We've simplified a lot of the conditions for eager of the module init so now we can introduce a final switch to allow modules to opt-out (and in the future opt-in if they still require the behaviour).

We now require you to be explicit about the intended behaviour and implement the `+ (BOOL)requiresMainQueueSetup` method on your module. When you return YES from this method, it tells the bridge the module needs to be created on the main thread (and to avoid deadlocks, we do so eagerly during bridge startup). When you return NO, the native module will be initialised when it's first accessed from JS.

The current behaviour is maintained but a warning is emitted until the new API is adopted.

Reviewed By: fkgozali

Differential Revision: D5527788

fbshipit-source-id: 56d38f81e58cf950547b9780e89bfac4667eeaaa
2017-08-07 07:04:36 -07:00
Pieter De Baets 1cd276ab5c Specialize JSCValueEncoder for id instead of NSArray
Reviewed By: kathryngray

Differential Revision: D5355723

fbshipit-source-id: a992514c92143fcac52f8e35824c665a1cb44ea4
2017-08-07 06:45:34 -07:00
Pieter De Baets cb12080179 Replace exported method registration with statically allocated struct
Reviewed By: fromcelticpark

Differential Revision: D5389383

fbshipit-source-id: 9eb29b254b616574966b43ad24aa880d44589652
2017-07-24 07:01:53 -07:00
Pieter De Baets f1cbb11620 Replace -[RCTConvert folly_dynamic:] with direct calls to convertIdToFollyDynamic
Reviewed By: kathryngray

Differential Revision: D5355734

fbshipit-source-id: 4ba1533b75c8e271a86a2d5cc3a3354e52f83db2
2017-07-10 05:31:04 -07:00
Viacheslav Radchenko 879edf0d05 Added RCTInspectorDevServerHelper call in FBReactJSExecutor. Added UTF8StringForSourceURL
Reviewed By: javache

Differential Revision: D5246399

fbshipit-source-id: 179ff0b69886c4ff71911fc7b1d3491ff4d5967d
2017-06-14 14:10:10 -07:00
Pieter De Baets 6221053179 Improve systrace markers
Reviewed By: mhorowitz

Differential Revision: D4860135

fbshipit-source-id: ce963010883e6b9cc8e34f7ff01b4018cd195eba
2017-05-12 18:07:49 -07:00
Alex Dvornikov db0c22192c Added support for synchronous methods in native modules on iOS
Reviewed By: javache

Differential Revision: D4947556

fbshipit-source-id: 0ef73dc5d741201e59fef1fc048809afc65c75b5
2017-04-27 12:03:30 -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 9d1c62669b Add extra guards to DispatchMessageQueueThread
Reviewed By: bnham

Differential Revision: D4868432

fbshipit-source-id: 23d6c996aa97db82ea5e0e166e1988f4ce378b6f
2017-04-11 12:25:39 -07:00
Pieter De Baets 2336ac299c Improve constant extraction from RCTNativeModule
Reviewed By: dcaspi

Differential Revision: D4829671

fbshipit-source-id: 6b1cef1d31c7d8981c6f1e304d3742e885f8a83b
2017-04-08 15:18:08 -07:00
Pieter De Baets f3dfd616f4 Allow lazy Cxx modules to not initialize
Reviewed By: mhorowitz

Differential Revision: D4851596

fbshipit-source-id: cf5f5c51b9aaa0da96f7ab6fba1277b72c988400
2017-04-08 15:18:08 -07:00
Pieter De Baets ceac54ebe9 Use forward declaration in RCTCxxModule
Reviewed By: mhorowitz

Differential Revision: D4821449

fbshipit-source-id: 8e75a7b17e0986bc9416a0afde0d7dfa179d4fed
2017-04-07 09:30:33 -07:00
Pieter De Baets b2647ea335 Allow ModuleRegistry initialization to complete lazily
Reviewed By: mhorowitz

Differential Revision: D4794794

fbshipit-source-id: f3b7a5d02587b4cd4e214aa6b0368a0d214fb63f
2017-04-07 09:30:33 -07:00
Pieter De Baets ce270220e4 Extract module registry creation to helper
Reviewed By: mhorowitz

Differential Revision: D4721817

fbshipit-source-id: 2fa17ca5317a57d429aa75d6c1865932af27e02f
2017-03-17 07:08:14 -07:00