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

122 Коммитов

Автор SHA1 Сообщение Дата
Christoph Purrer 5dcad6a116 jsi.h Fix typo
Summary:
Changelog:
[Internal][Fixed] - I have been reading this header file recently and discovered some typos

Reviewed By: kodafb

Differential Revision: D32455214

fbshipit-source-id: c27291943476014b787ee1641fd8642056bdbc5a
2021-11-16 08:56:53 -08:00
Joshua Gross b60e229d7f Remove compiler_flags from BUCK modules
Summary:
Nearly all of these are identical and these compiler_flags are now centralized in rn_defs.bzl. This should have NO CHANGE on build configuration, the flags have just moved for now.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D31631766

fbshipit-source-id: be40ebeb70ae52b7ded07ca08c4a29f10a0ed925
2021-10-14 15:34:29 -07:00
Kevin Gozali b0c8a4eee8 Link RCT-Folly against libc++abi
Summary:
Folly now depends on libc++abi. This solves linker error for RCT-Folly.podspec like this:

```
Undefined symbols for architecture arm64:
  "___cxa_increment_exception_refcount", referenced from:
      folly::exception_ptr_get_type(std::exception_ptr const&) in libRCT-Folly.a(Exception.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

See https://github.com/react-native-community/releases/issues/251

Note: RNTester was not affected by this bug for some reason, so the only way to verify is via the new app generated via `npx react-native init`.

Changelog: [Fixed][iOS] Unbreak Folly linker error

Reviewed By: lunaleaps

Differential Revision: D30950944

fbshipit-source-id: 3eb146e23faa308a02363761d08849d6801e21ca
2021-09-16 22:24:10 -07:00
Neil Dhar 1bc885b8b8 Make JSI a dynamic library
Summary:
Ship libjsi as a standalone dynamic library. This prevents problems
with exception handling caused by duplicate typeinfo across multiple
shared libs, and reduces bundle size by removing duplicate copies of
JSI.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D30599215

fbshipit-source-id: abad1398342a5328daa825f3f684e0067cad7a96
2021-08-27 17:16:49 -07:00
Chatura Atapattu 8258f5e271 Remove BUILD FILE SYNTAX from build files
Summary: Changelog: [Internal]

Reviewed By: zertosh

Differential Revision: D30410441

fbshipit-source-id: 62deebb502121f23270bfa18286b155ad161af2d
2021-08-19 15:25:19 -07:00
Kudo Chien b77948e33b Upgrade folly to 2021.06.28.00 and boost to 1.76.0 (#31840)
Summary:
1. [ios] upgrade folly to 2021.06.28.00 which aligned to android.
2. folly compile setting from c++14 -> c++17: _this folly requires c++17 for `std::unordered_map::insert_or_assign`._
3. boost 1.63.0 -> 1.76.0:  _the old boost does not support c++17._
4. deprecating react-native-community/boost-for-react-native: _by cocoapods installer, we could download the official target._

## Changelog

[iOS] [Changed] - Upgrade folly to 2021.06.28.00 and boost to 1.76.0

Pull Request resolved: https://github.com/facebook/react-native/pull/31840

Test Plan: CI passed

Reviewed By: fkgozali

Differential Revision: D29668480

Pulled By: yungsters

fbshipit-source-id: 98eae9ca47f489dcea91974e6f5e9dcb4d66c40c
2021-07-16 15:13:12 -07:00
Neil Dhar 257e83f664 Remove custom MAP_TAG from FileBuffer
Summary:
Custom tags made with `VM_MAKE_TAG` are meant to be used to tag
anonymous mappings, and should be passed in as the file descriptor.
We can't use them for file backed mappings.

Changelog: [Internal]

Reviewed By: kodafb

Differential Revision: D29038256

fbshipit-source-id: 11324a3e798e695709d7d340e84e5fe6f7ffaad3
2021-06-18 12:01:00 -07:00
Peter Argany 36b58a824e Bump Flipper-Folly to 2.5.3 and RCT-Folly to 2021.04.26.00
Summary:
This fixes an error where folly fails to build on Xcode 12.5, by bumping the various folly deps in RN to builds with a fix.

Next step is to commit this to 0.64 release branch

allow-large-files

Changelog: [iOS] Fix builds on Xcode 12.5

Reviewed By: fkgozali

Differential Revision: D28071808

fbshipit-source-id: 236b66bf8294db0c76ff25b11632c1bf89525921
2021-04-29 10:39:25 -07:00
Xuan Huang bddff73790 Introduce drainMicrotasks to JSI
Summary:
Changelog:
[Internal][Added] - Introduce drainMicrotasks to JSI

This diff proposed a new JSI API `drainMicrotasks` to define
how hosts may integrate with the JSVMs' internal microtask
queue (a.k.a. job queue) and hence their native Promise.

The name `drainMicrotasks` is slightly preferred over `drainJobs`
to favor *host-friendliness* over *engine-friendliness*.

This diff auto implement the new API in JSC and Hermes as stubs
to make sure things compiled.

Please refer to the doc-comments in the `jsi.h` for a detailed
documentation on the semantics and the design of this API.

### Notes on the existing APIs from JSVMs

The presence of such queue and APIs to operate on them are
ubiquitous:
- Hermes: `Runtime::drainJobs`
- V8: `MicrotaskQueue::PerformCheckpoint`
- JSC: `VM::drainMicrotasks`
- QuickJS: `JS_ExecutePendingJob`

The only exception is ChakraCore, which requires hosts to provide
the queue and set up the `JsSetPromiseContinuationCallback`,
but a JSI implementation can provide that queue trivially.

### Extra note on ECMA-262

ECMA-262 changed the spec at Mar 2020 from "asking an ECMAScript
implementation to maintain a Job Queue" to "Ask the embedder to
define its event loop, including the job queue" so technically:
- the internal approach is closer to the old spec.
- the ChakraCore approach is closer to the current spec.

Reviewed By: mhorowitz

Differential Revision: D27727920

fbshipit-source-id: b839b959facbc009f7d14b781e9287c46ea64373
2021-04-23 02:43:06 -07:00
Héctor Ramos ae07c53d0b Resolve "fatal: not a git repository" error outside of git repositories
Summary:
CocoaPods will display a "fatal: not a git repository" when these podspecs are consumed within Facebook's internal Mercurial repository due to the reliance on `git` to obtain the current commit hash.

In these cases, the podspec is being consumed locally and the commit hash is unnecessary.

The error is removed by avoiding the use of `git` if the current working directory is not a git repository (or any of the parent directories).

Changelog:
[Internal] [iOS] - Remove CocoaPods error within Facebook's repository

Reviewed By: fkgozali

Differential Revision: D27750974

fbshipit-source-id: 99159611c580baf5526f116948c5ff60e1c02e5c
2021-04-15 13:30:31 -07:00
Samuel Susla 9ef995a14a Enable C++ 17 in React Native
Summary:
Changelog: [Internal] enable support for C++ 17.

C++ 17 in React Native targets.

Short and comprehensive list of C++ features:
https://github.com/AnthonyCalandra/modern-cpp-features#c17-language-features

Reviewed By: JoshuaGross

Differential Revision: D27431145

fbshipit-source-id: e8da6fe9d70e9b7343a8caec21cdbeb043478575
2021-04-01 04:50:59 -07:00
Riley Dulin a9bae13d07 Add sampling heap profiler APIs to JSI
Summary:
The sampling heap profiler will need to be enable-able by the
inspector, and the previous snapshot/profiling APIs are all
defined on `jsi::instrumentation`.

Follow their lead and define the new sampling heap profiler APIs on
`jsi::instrumentation` as well, and implement it for Hermes.

Changelog: [Internal]

Reviewed By: neildhar

Differential Revision: D26835152

fbshipit-source-id: 4625be3214297489e04a4ceea8a22622d14299c4
2021-03-18 10:40:41 -07:00
Daniel Andersson 42fa4a6a4e Fix incorrect comment about strictEquals
Summary:
The documentation of jsi::Value::strictEquals was confusing it with SameValue (which differs in treatment of signed zeroes and NaN). Fix it by referring to the correct part of the spec.

Changelog:
[Internal][Fixed] - Fix incorrect comment

Reviewed By: avp

Differential Revision: D26430216

fbshipit-source-id: 0ea4208fbdda40c87f8028231ddefb2323b6eb96
2021-03-10 15:33:31 -08:00
Riley Dulin 4db1b3e8cd Change JSI compiler options to be private
Summary:
JSI had its compiler options like `-Wno-non-virtual-dtor` exported to targets
that depended on the JSI library.
These flags should be private to the compiler invocation on the `jsi.cpp` translation
unit and don't need to be shared with any libraries pulling in `jsi.h`.

Fixes #448

Changelog:
[Internal] - Don't export C++ warnings from JSI CMake files

Reviewed By: Huxpro

Differential Revision: D26212636

fbshipit-source-id: bd95580f89694189975a49660c439e4e5f7c5afc
2021-02-03 10:42:59 -08:00
Haochen Li 201c107338 fix typo (#30777)
Summary:
fix typo in comments

## Changelog
fix typo in comments
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[CATEGORY] [TYPE] - Message

Pull Request resolved: https://github.com/facebook/react-native/pull/30777

Reviewed By: RSNara

Differential Revision: D26108277

Pulled By: PeteTheHeat

fbshipit-source-id: 616c89263c9320bd914b26c1b814eadf316cf6d8
2021-01-27 15:59:29 -08:00
Peter Argany a1d626739d Delete iOS10/tvOS10 support from React Native Libraries
Summary:
allow-large-files

Changelog: [iOS] Remove iOS10/tvOS10 suppport

Similar to D19265731 (674b591809) for iOS9.

I just ran this command:
`find . -type f -exec sed -i '' 's/{ :ios => "10.0" }/{ :ios => "11.0" }/' {} +`
and then updated pods

Reviewed By: fkgozali

Differential Revision: D25693227

fbshipit-source-id: 0073d57ecbb268c52d21962cef202316857bcbd2
2021-01-11 16:46:16 -08:00
Peter Argany 6a9525c9b0 Delete iOS9 BUCK workarounds
Summary:
Changelog: [Internal]

According to D19411886 (30491a2085), there were some deps that required a couple targets to stay at iOS9:

- `//fbobjc/Libraries/FBGraphQLQuery:FBGraphQLQuery --> //xplat/js/react-native-github:RCTCxxUtilsApple`
- `//fbobjc/Libraries/NativeTemplateKit:NativeTemplateKitJSExecutorPlugin --> //xplat/js/react-native-github/ReactCommon/jsi:JSCRuntimeApple`

These targets seem to build after this diff, so I guess they've been pushed past iOS9.

Reviewed By: fkgozali

Differential Revision: D25692640

fbshipit-source-id: 1ce94a452090032ef316a3daa79885a7c58d6eac
2021-01-11 13:00:31 -08:00
Andres Suarez 0f4f917663 Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861683

fbshipit-source-id: 616afca13ae64c76421053ce49286035e0687e36
2021-01-09 22:11:00 -08:00
Kevin Gozali 86ffbd0a27 RNTester Android: always compile Fabric files
Summary:
This commit makes both `:ReactAndroid` and `:rn-tester:android:app` always compile in Fabric codegen outputs. However, one may still enable/disable Fabric at runtime by setting `USE_FABRIC` env var (set to 1 or 0, default is 0).

Note that we can't register custom components specific to the app, yet, so only the components in react-native github repo is covered by this commit.

RNTester doesn't enable Fabric by default yet due to known UI bugs that haven't been addressed yet.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25674311

fbshipit-source-id: 8db660c959319250ebc683c84076677cf6489e94
2020-12-21 22:43:36 -08:00
Kevin Gozali 7cfc7d65f7 Codegen: Make react-native-codegen BUCK deps OSS-compatible
Summary:
Added a few FB vs OSS polyfills:
* react_native_root_target() to refer to the root FB react-native-github/ dir or repo dir in OSS
* react_native_xplat_synced_target() for anything xplat
* a few others

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24437245

fbshipit-source-id: ee290a87a98a8e9be67b102a96f2faac2a2cb92b
2020-10-22 17:09:29 -07:00
Marc Horowitz a8c90e6af4 Make conversions between folly::dynamic and JSI non-recursive
Summary:
Changelog:
[General][Fixed] - Fix handling of very deeply nested data across the bridge

fixes facebook/hermes#339

Reviewed By: sammy-SC

Differential Revision: D24182938

fbshipit-source-id: b674283a112b98cc63f20e436c538e3789ddf6dd
2020-10-21 20:54:55 -07:00
Riley Dulin d8b0e9d9ab Add HeapProfiler.lastSeenObjectId and HeapProfiler.heapStatsUpdate to inspector
Summary:
When taking a heap timeline, Hermes wasn't showing any data until the timeline
was written to disk and then reloaded.

Turns out we were missing support for two events:
* `HeapProfiler.lastSeenObjectId`: This event reports the most recently
allocated object ID. Used to know when objects were allocated in the
timeline.
* `HeapProfiler.heapStatsUpdate`: Report how many objects and bytes
exist for a "time fragment", represented by a fragment index. Later updates
to the same index can decrease the amount of live memory, which show up
as grey spikes instead of blue spikes

Previously, we only supported these by writing out to a file, and they didn't work
with a "live" profiling view. To fix this, I changed the periodic sampling thread
to instead be a periodic flush of a sample every few allocations. The performance
impact is tucked away only when profiling is turned on, and it's very non-invasive to
the rest of the GC. The flush calls a callback with the relevant information if the
inspector is on, and the inspector sends a message back to the browser.

Changelog: [Internal] Fix for Hermes heap timeline profiling

Reviewed By: neildhar

Differential Revision: D23993363

fbshipit-source-id: 8e0b571130cbb7e839dfb009b04f584f5179085d
2020-10-10 13:26:13 -07:00
simek 2160377574 remove most of tvOS remnants from the code (#29407)
Summary:
Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018

This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code.

In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

* **[Internal] [Removed]** - remove most of tvOS remnants from the code:
  * `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter`
* **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages
* **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method
* **[iOS] [Removed]** - remove deprecated and TV related props from View:
  * `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties`
* **[iOS] [Removed]** - remove `BackHandler` utility implementation

Pull Request resolved: https://github.com/facebook/react-native/pull/29407

Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required.

Reviewed By: PeteTheHeat

Differential Revision: D22619441

Pulled By: shergin

fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6
2020-09-28 21:26:41 -07:00
grabbou 311d4e9ef0 feat: enable bitcode (#365)
Summary:
Bitcode is turned on by default in React Native and so, setting it here as well.

Changelog: [iOS] [Changed] - Upgraded JSI with a new HERMES_ENABLE_BITCODE flag

Pull Request resolved: https://github.com/facebook/hermes/pull/365

Reviewed By: tmikov

Differential Revision: D23823228

Pulled By: Huxpro

fbshipit-source-id: d43638818a733f6a87b2f4a1ecadad8ea9c7a419
2020-09-22 14:42:23 -07:00
Riley Dulin 22804a6144 Add cause to jsi::instrumentation::collectGarbage
Summary:
Continuing the adding of a "cause" field for logging to GCs.
This allows embedders of Hermes (such as React Native) to specify
the cause of a call to `collectGarbage`.

Notably, this allows Hermes to know when a GC is triggered by a memory warning.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D23742099

fbshipit-source-id: 99453e632328c00045b92a72f789d41c898dc518
2020-09-18 10:36:19 -07:00
empyrical 300df59c77 Android: Ensure RN_FABRIC_ENABLED is defined when building with Fabric (#29939)
Summary:
This pull request tweaks the build script for `jsiruntime` to ensure that `RN_FABRIC_ENABLED` is defined when building for Android with Fabric enabled, and using the JavascriptCore JS engine. Without it, the `createWeakObject` and `lockWeakObject` methods in `JSCRuntime.cpp` will throw an exception.

## Changelog

[Internal] [Changed] - Android: Ensure RN_FABRIC_ENABLED is defined when building with Fabric

Pull Request resolved: https://github.com/facebook/react-native/pull/29939

Test Plan: RNTester with JSC now builds and runs on Android with Fabric enabled.

Reviewed By: hramos

Differential Revision: D23671070

Pulled By: fkgozali

fbshipit-source-id: 27e69364a9f709615543be7c20b72b5536443cd8
2020-09-14 10:08:51 -07:00
Eloy Durán 941bc0ec19 Upstream RN macOS Hermes integration bits (#29748)
Summary:
Microsoft’s RN for macOS fork supports the Hermes engine nowadays https://github.com/microsoft/react-native-macos/pull/473. As a longer term work item, we’ve started moving bits that are not invasive for iOS but _are_ a maintenance burden on us—mostly when merging—upstream. Seeing as this one is a recent addition, it seemed like a good candidate to start with.

As to the actual changes, these include:

* Sharing Android’s Hermes executor with the objc side of the codebase.
* Adding a CocoaPods subspec to build the Hermes inspector source and its dependencies (`Folly/Futures`, `libevent`).
* Adding the bits to the Xcode build phase script that creates the JS bundle for release builds to compile Hermes bytecode and source-maps…
* …coincidentally it turns out that the Xcode build phase script did _not_ by default output source-maps for iOS, which is now fixed too.

All of the Hermes bits are automatically enabled, on macOS, when providing the `hermes-engine-darwin` [npm package](https://www.npmjs.com/package/hermes-engine-darwin) and enabling the Hermes pods.

## Changelog

[General] [Added] - Upstream RN macOS Hermes integration bits

Pull Request resolved: https://github.com/facebook/react-native/pull/29748

Test Plan:
Building RNTester for iOS and Android still works as before.

To test the actual changes themselves, you’ll have to use the macOS target in RNTester in the macOS fork, or create a new application from `master`:

<img width="812" alt="Screenshot 2020-08-18 at 16 55 06" src="https://user-images.githubusercontent.com/2320/90547606-160f6480-e18c-11ea-9a98-edbbaa755800.png">

Reviewed By: TheSavior

Differential Revision: D23304618

Pulled By: fkgozali

fbshipit-source-id: 4ef0e0f60d909f3c59f9cfc87c667189df656a3b
2020-08-27 01:18:33 -07:00
Marc Horowitz 525e55f898 Look up HostObject computed properties on the right object in the prototype chain.
Summary:
The change in the hermes repository fixes the security vulnerability
CVE-2020-1911.  This vulnerability only affects applications which
allow evaluation of uncontrolled, untrusted JavaScript code not
shipped with the app, so React Native apps will generally not be affected.

This revision includes a test for the bug.  The test is generic JSI
code, so it is included in the hermes and react-native repositories.

Changelog: [Internal]

Reviewed By: tmikov

Differential Revision: D23322992 (0dee0e6036)

fbshipit-source-id: 4e88c974afe1ad33a263f9cac03e9dc98d33649a
2020-08-26 11:30:34 -07:00
Martin Sherburn 549563e8ab Allow Hermes to be built as a DLL on Windows
Summary:
On windows it is required to explicitly specify what symbols need to be exported from a DLL to make them accessible (using `__declspec(dllexport)`). I have added and expanded on existing macros to do this and added exports that were previously missing.

Changelog:
[Internal][Changed] - Allow Hermes to be compiled to a single DLL on windows

Reviewed By: mhorowitz

Differential Revision: D23084343

fbshipit-source-id: 832cb17b9e637e4c04dad479aae6c1fc190f968e
2020-08-24 06:07:19 -07:00
Eloy Durán ffa3d7f638 Build macOS framework and add CocoaPods podspec (#285)
Summary:
Supersedes https://github.com/facebook/hermes/issues/239

Currently used in our macOS fork of React Native https://github.com/microsoft/react-native-macos/pull/473. (Although we’re using a build of Hermes v0.4.1, as we’re at RN 0.62.0.)

* On Apple platforms build a [dynamic] framework bundle when `HERMES_BUILD_APPLE_FRAMEWORK` is set. When set to `FALSE` it will produce a `dylib`, like previously. Defaults to `TRUE`.
* On Apple platforms create a debugging symbols bundle.
* Add `HERMES_ENABLE_FUZZING`, which is enabled by default.
* Add `HERMES_ENABLE_TEST_SUITE`, which is enabled by default.
* Add a CocoaPods podspec that can build from source or use a binary.

A standalone macOS app that pulls in Hermes as a CocoaPods pod can be found here https://github.com/alloy/TestHermesMaster.

## Framework variant (default)

```
$ ./src/utils/build/configure.py --distribute --cmake-flags='-DCMAKE_INSTALL_PREFIX:PATH=../destroot_release' build
$ cd build && ninja install && cd ..
$ tree destroot_release/
destroot_release/
├── Library
│   └── Frameworks
│       ├── hermes.framework
│       │   ├── Headers -> Versions/Current/Headers
│       │   ├── Resources -> Versions/Current/Resources
│       │   ├── Versions
│       │   │   ├── 0
│       │   │   │   ├── Headers
│       │   │   │   │   ├── CompileJS.h
│       │   │   │   │   ├── DebuggerAPI.h
│       │   │   │   │   ├── Public
│       │   │   │   │   │   ├── Buffer.h
│       │   │   │   │   │   ├── CrashManager.h
│       │   │   │   │   │   ├── CtorConfig.h
│       │   │   │   │   │   ├── DebuggerTypes.h
│       │   │   │   │   │   ├── GCConfig.h
│       │   │   │   │   │   ├── GCTripwireContext.h
│       │   │   │   │   │   └── RuntimeConfig.h
│       │   │   │   │   ├── SynthTrace.h
│       │   │   │   │   ├── SynthTraceParser.h
│       │   │   │   │   ├── TraceInterpreter.h
│       │   │   │   │   ├── TracingRuntime.h
│       │   │   │   │   ├── hermes.h
│       │   │   │   │   └── hermes_tracing.h
│       │   │   │   ├── Resources
│       │   │   │   │   └── Info.plist
│       │   │   │   └── hermes
│       │   │   └── Current -> 0
│       │   └── hermes -> Versions/Current/hermes
│       └── hermes.framework.dSYM
│           └── Contents
│               ├── Info.plist
│               └── Resources
│                   └── DWARF
│                       └── hermes
├── bin
│   ├── hbcdump
│   ├── hdb
│   ├── hermes
│   ├── hermesc
│   └── hvm
└── include
    ├── hermes
    │   ├── CompileJS.h
    │   ├── DebuggerAPI.h
    │   ├── Public
    │   │   ├── Buffer.h
    │   │   ├── CrashManager.h
    │   │   ├── CtorConfig.h
    │   │   ├── DebuggerTypes.h
    │   │   ├── GCConfig.h
    │   │   ├── GCTripwireContext.h
    │   │   └── RuntimeConfig.h
    │   ├── SynthTrace.h
    │   ├── SynthTraceParser.h
    │   ├── TraceInterpreter.h
    │   ├── TracingRuntime.h
    │   ├── hermes.h
    │   └── hermes_tracing.h
    └── jsi
        ├── JSIDynamic.h
        ├── decorator.h
        ├── instrumentation.h
        ├── jsi-inl.h
        ├── jsi.h
        ├── jsilib.h
        └── threadsafe.h
```

# dylib variant

```
$ ./src/utils/build/configure.py --distribute --cmake-flags='-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=false -DCMAKE_INSTALL_PREFIX:PATH=../destroot_release' build
$ cd build && ninja install && cd ..
$ tree destroot_release/
destroot_release/
├── bin
│   ├── hbcdump
│   ├── hdb
│   ├── hermes
│   ├── hermesc
│   └── hvm
├── include
│   ├── hermes
│   │   ├── CompileJS.h
│   │   ├── DebuggerAPI.h
│   │   ├── Public
│   │   │   ├── Buffer.h
│   │   │   ├── CrashManager.h
│   │   │   ├── CtorConfig.h
│   │   │   ├── DebuggerTypes.h
│   │   │   ├── GCConfig.h
│   │   │   ├── GCTripwireContext.h
│   │   │   └── RuntimeConfig.h
│   │   ├── SynthTrace.h
│   │   ├── SynthTraceParser.h
│   │   ├── TraceInterpreter.h
│   │   ├── TracingRuntime.h
│   │   ├── hermes.h
│   │   └── hermes_tracing.h
│   └── jsi
│       ├── JSIDynamic.h
│       ├── decorator.h
│       ├── instrumentation.h
│       ├── jsi-inl.h
│       ├── jsi.h
│       ├── jsilib.h
│       └── threadsafe.h
└── lib
    ├── libhermes.dylib
    └── libhermes.dylib.dSYM
        └── Contents
            ├── Info.plist
            └── Resources
                └── DWARF
                    └── libhermes.dylib
```

Pull Request resolved: https://github.com/facebook/hermes/pull/285

Reviewed By: willholen

Differential Revision: D22398354

Pulled By: mhorowitz

fbshipit-source-id: 732524275cf273866171fc6e2ac2acb062185fbd
2020-07-08 17:15:09 -07:00
Ryan Tremblay 9c32140068 Enable array buffers in JSCRuntime.cpp (#28961)
Summary:
The JavaScriptCore implementation of JSI [does not currently support array buffers](https://github.com/facebook/react-native/blob/master/ReactCommon/jsi/JSCRuntime.cpp#L925-L943). The comments in the code suggest the JSC version used by React Native does not work with array buffers, but this seems to be out of date since the current version of JSC used by React Native does indeed support array buffers. This change just enables array buffers in JSCRuntime.cpp.

NOTE: See https://github.com/react-native-community/discussions-and-proposals/issues/91#issuecomment-632371219 for more background on this change.

## Changelog

[General] [Added] - Support for array buffers in the JavaScriptCore implementation of JSI
Pull Request resolved: https://github.com/facebook/react-native/pull/28961

Test Plan:
To test these changes, I just made some temporary changes to RNTester to use JSI to inject a test function into the JS runtime that reads from and writes to an array buffer, and call that function from the JS of the RNTester app (see 28152ce3f4).

For the JS side of this, specifically look at 28152ce3f4/RNTester/js/RNTesterApp.android.js (L13-L18)

For the native side of this, specifically look at 28152ce3f4/RNTester/android/app/src/main/cpp/JSITest.cpp (L22-L38)

Reviewed By: shergin

Differential Revision: D21717995

Pulled By: tmikov

fbshipit-source-id: 5788479bb33c24d01aa80fa7f509e0ff9dcefea6
2020-06-09 01:11:53 -07:00
Marc Horowitz 9baf6f2140 Handle stack overflow in JSError construction gracefully
Summary:
JSError creation can lead to further errors.  Make sure these cases
are handled and don't cause weird crashes or other issues.

This solution has a few parts:
 * include a ScopedNativeDepthTracker in checkStatus
 * If an exception object message or stack property is already a String, don't
   call JS String ctor on it
 * Verify that a jsi::Value is a String before calling getString on it.
 * Add more tests for JSError construction

Changelog: [Internal]

Reviewed By: dulinriley

Differential Revision: D21851645

fbshipit-source-id: 2d10da0e741ad4ede93cd806320f68ad512e5138
2020-06-03 18:14:18 -07:00
Christoph Purrer 8d6cc50d77 Change jsi::Runtime::lockWeakObject to take a mutable ref
Summary:
A key difference in WeakRefs with the Hades GC is that they are mutable,
in the sense that reading the value of a WeakRef while a GC is active might
clear the WeakRef.
For this reason, attempting to lock the WeakObject might mutate the backing
reference.

I preferred to communicate this change in behavior via the API rather than
`const_cast` it away inside the implementation.

Changelog: [Internal] Change jsi::WeakObject to be mutable in lockWeakObject

Reviewed By: mhorowitz

Differential Revision: D21485758

fbshipit-source-id: 3618928be8f8791aed56cb20673896ff5b786ded
2020-05-26 11:10:06 -07:00
Kevin Gozali f24b815fe6 use xplat BUCK attribution
Summary:
Internal code attribution update.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D21603406

fbshipit-source-id: c3da1823e26beb0092d97e66d731618c0433a2f7
2020-05-15 21:55:52 -07:00
Kevin Gozali 3c9013402e xplat code ownership
Summary:
For internal code attribution.

Changelog: [Internal]

Reviewed By: zlern2k

Differential Revision: D21496969

fbshipit-source-id: 9fa27a758df19c16fd2087ce964132eaa70dc91f
2020-05-11 10:24:35 -07:00
Pieter De Baets e566c7ec7b Add virtual destructor to JSError
Summary:
We consume Hermes through multiple .so's, which means we have multiple (weak) typeinfo definitions of facebook::jsi::JSError. Previously we were using gnustl, which would strcmp typeinfo to decide whether a certain exception handler applies, which meant this didn't cause any major issues. However since this is deprecated, we recently switched to libc++, which does not have this by behaviour (or it does, but behind a flag I'm not sure how to enable). This causes any JS exceptions to fall through from our exception handlers and fatal the app.

This problem is actually documented in the common Android NDK problems page: https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#rtti_exceptions-not-working-across-library-boundaries

The suggested solution is to ensure that any exception types have a key function defined (a non-pure, out-of-line virtual function). The simplest one to add is a virtual destructor. This makes the object file that holds the implementation of the destructor export a non-weak typeinfo definition which will at load time override the other weak versions.

I'm not sure why we're the first to hit this. RN's JSIExecutor doesn't explicitly reference JSError which probably helps (https://github.com/facebook/react-native/blob/master/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp#L256-L258) and they also don't use unguarded callbacks like we do.

Changelog: [Internal]

Reviewed By: mhorowitz

Differential Revision: D21426524

fbshipit-source-id: 474284ada1ca2810045dc4402c420879447f9308
2020-05-07 04:15:14 -07:00
Marc Horowitz 81734276b9 Allow use of std::tuple<> with decorators directly
Summary:
Previously, a derived class, WithTuple, was used.  This ran
into bugs in MSVC (see https://github.com/microsoft/STL/issues/121).
Instead, use specialization to get the same result using std::tuple
directly.  This avoids the bug, and is a cleaner API.

Changelog: [Internal]

Reviewed By: dulinriley

Differential Revision: D21233677

fbshipit-source-id: 1d75991847164e525b4ba70f65a90627e5f8cd56
2020-04-24 15:42:47 -07:00
Ryan Tremblay f5d00e5a29 Fix jsi cmake include dirs (#207)
Summary:
I'm trying to use JSI for a React Native custom module. I saw these existing examples where the JSI API is used in the context of a CMakeLists.txt:
https://github.com/terrysahaidak/host-object-test/blob/master/libs/android-jsi/test-jsi/src/main/cpp/CMakeLists.txt
https://github.com/ericlewis/react-native-hostobject-demo/pull/4/files#diff-834320be1b4e4016bac27c05dcd17fb9
In both cases, they manually grab the include directories and jsi.cpp from node_modules/react-native, but I also saw that node_modules/react-native/ReactCommon/jsi/jsi already has a CMakeLists.txt that appears to be intended to provide a jsi static lib, so I tried to pull this into my own CMakeLists.txt like this:
```
add_subdirectory(${RN_DIR}/ReactCommon/jsi/jsi ${CMAKE_CURRENT_BINARY_DIR}/jsi)
...
target_link_libraries(MyLib jsi)
```
Unfortunately when doing this, the consuming project still doesn't see the correct include directories. The change I'm proposing here is to use `target_include_directories` and declare that `..` is a public (to consumers) include directory for the library named `jsi`. With this change, you can do what I showed above to consume the jsi lib by just pulling in the CMakeLists.txt file into your own CMakeLists.txt file.

Changelog: [General][Fixed] Fix jsi cmake include dirs

Pull Request resolved: https://github.com/facebook/hermes/pull/207

Reviewed By: willholen

Differential Revision: D21074270

Pulled By: tmikov

fbshipit-source-id: 7d9ec3255f57a16c0b2be489dffa4540727738a1
2020-04-16 16:34:41 -07:00
Marc Horowitz 8970ee9f32 Make HermesRuntime::description() always include "HermesRuntime"
Summary:
If name is passed in as part of RuntimeConfig, that is included
in the description, too.
Changelog: [Internal]

Reviewed By: dulinriley

Differential Revision: D20716320

fbshipit-source-id: f2fba6df32f496090dee787d8b7f55a6a4dd8ed8
2020-04-01 13:42:56 -07:00
Jacob Bower ed3054927c Plumb through memory allocation profiler feature to Chrome Inspector
Summary: Changelog: Make allocation profiler feature of Chome Inspector work

Reviewed By: dulinriley

Differential Revision: D20383003

fbshipit-source-id: 8a10c310d5a639a6644763adb53f2f0017057587
2020-03-31 11:02:41 -07:00
Kevin Gozali 25f7aea86c Replace fbsource// with // in xplat/js/ files [1]
Summary:
`fbsource//xplat` and `//xplat` are equivalent for FB BUCK targets. Removing extra prefix for consistency.

Changelog: [Internal]

Reviewed By: scottrice

Differential Revision: D20495655

fbshipit-source-id: a57b72f694c533e2e16dffe74eccb8fdec1f55f5
2020-03-25 21:55:47 -07:00
Marc Horowitz 05c17c76da Add a little headroom to the stack when converting an exception JS -> C++
Summary:
This was causing an exception cascade leading to production
errors.  Added a test which repros the problem and passes with the
fix.

Changelog: [Internal]

Reviewed By: tmikov

Differential Revision: D20408858

fbshipit-source-id: 3fa9b8669bf3bf7617bfc05ef8f23d52bc969b4e
2020-03-14 00:13:29 -07:00
Marc Horowitz 409c276474 Remove remaining external references to JSC
Summary: Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20319757

fbshipit-source-id: 4ac3952175fd1b78957b01de279135af122d5bf1
2020-03-11 21:13:01 -07:00
David Detlefs 07c4980267 Add unit test for multiple levels of DecoratedHostObject.
Summary:
I was unsure how, or if, DecoratedHostObjects worked.  Marc had created the linked task to make sure that things worked right with multiple levels of decorated host objects.  I decided to do that, thinking it would show a bug; instead it showed me that the pattern did work, and let me figure out how.

Changelog: [Internal]

Reviewed By: mhorowitz

Differential Revision: D20263797

fbshipit-source-id: 8bbe71cba1b6ef5b2673566759112320dd1894b8
2020-03-09 22:08:00 -07:00
Kevin Gozali 30822e3923 make RN infra labels public
Summary:
Internal build target labeling.

Changelog: [Internal]

Reviewed By: zlern2k

Differential Revision: D20152676

fbshipit-source-id: 89615a0b3a6f3994b18f2c07b86d0ae93e052327
2020-02-28 12:46:49 -08: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
Gabriel Nunes 8ad67de59e Update documentation for Function::call to reflect how 'this' behaves in non-strict mode
Summary: The `Function::call` method says it leaves the JS `this` object undefined. According to my tests, that's not completely true: if the function is defined to use strict mode via `"use strict"` either inside itself or in the file it was defined in, it does leave it `undefined`, but if the function is defined in non-strict mode, it sets `this` to the global object instead. This diff updates the documentation to reflect this.

Reviewed By: mhorowitz

Differential Revision: D19613483

fbshipit-source-id: 4b9ecf81c6318592be05a216748dcb22e32989f8
2020-02-25 13:02:32 -08:00
Marc Horowitz afc77bd843 make JSCRuntime SystemJSCAPITestFactory build only on apple platforms
Summary: Changelog: [Internal]

Reviewed By: jbower-fb

Differential Revision: D19874225

fbshipit-source-id: ca730391ea4734bdc98f91d8307bd9d622f27772
2020-02-24 19:14:29 -08:00
Rachel Nabors c0d8c1db90 Updating the URLs to point at new domain name reactnative.dev
Summary:
We recently updated React Native's docs site to have its own domain reactnative.dev and needed to update the URLs in the source code

CHANGELOG:
[INTERNAL]

Reviewed By: hramos

Differential Revision: D20072842

fbshipit-source-id: 1970d9214c872a6e7abf697d99f8f5360b3b308e
2020-02-24 13:09:11 -08:00
Radek Pietruszewski 24e0bad8be Make JSCRuntime::createValue 35% faster (#27016)
Summary:
JSC does some sort of thread safety locking on every single JSC API call, which makes them ridiculously expensive for a large number of calls (such as when passing a large array over the RN bridge). It would be great if we could lock and unlock once for an entire sequence of JSC calls… but in the meantime, the less we call JSC the better.

![unknown](https://user-images.githubusercontent.com/183747/67624956-08bd6e00-f838-11e9-8f65-e077693f113d.png)

In my benchmark environment (https://github.com/Nozbe/WatermelonDB/pull/541), the time spent in JSCRuntime::createValue went down from 1.07s to 0.69s by changing JSValueIsXXXX calls to a single JSValueGetType call.

The underlying implementation does the same thing: https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/API/JSValueRef.cpp#L58

## Changelog

[General] [Fixed] - Make JSCRuntime::createValue faster
Pull Request resolved: https://github.com/facebook/react-native/pull/27016

Reviewed By: RSNara

Differential Revision: D18769047

Pulled By: mhorowitz

fbshipit-source-id: 9d1ee28840303f7721e065c1b3c347e354cd7fef
2020-02-20 10:33:16 -08:00