Commit Graph

36 Commits

Author SHA1 Message Date
Jakub Grzmiel d005c8c08a Fix format warnings for clang 5.0
Reviewed By: mzlee

Differential Revision: D5900751

fbshipit-source-id: 4e9aea068aab3d2d882b8fb103a8828e861da97c
2017-09-25 10:30:53 -07:00
Pieter De Baets c5004d5dd0 Make startup errors in the websocket executor invalidate the bridge
Reviewed By: mhorowitz

Differential Revision: D5226936

fbshipit-source-id: b6d605974674d0e6f86559f2583553e3636d389b
2017-06-22 08:37:13 -07:00
Pieter De Baets 2e4284215c Handle fatal errors thrown by the Chrome debugger
Reviewed By: mmmulani

Differential Revision: D5219190

fbshipit-source-id: 16cff0e08de9c53d7a3e10897ddec3e6924c3bf5
2017-06-12 03:38:51 -07:00
Pieter De Baets 0ea1ea5fb7 Remove unused websocket-executor-name and websocket-executor-port options
Reviewed By: davidaurelio

Differential Revision: D4745529

fbshipit-source-id: 2c69aca33c999ccf2af8dbf8d9af2c1d123b59cd
2017-03-22 05:38:04 -07:00
Ben Roth 6a14f0b449 Add RCTDevSettings module
Summary:
This decouples non-UI logic from RCTDevMenu into a new module RCTDevSettings.

**Motivation**: This allows developers to change dev settings without depending on the built-in dev menu, e.g. if they want to introduce their own UI, or have other devtools logic that doesn't depend on an action sheet.

It also introduces the RCTDevSettingsDataSource protocol for storing dev tools preferences. This could allow a developer to implement alternative behaviors, e.g. loading the settings from some other config, changing settings based on the user, deciding not to persist some settings, or something else.

The included data source implementation, RCTDevSettingsUserDefaultsDataSource, uses NSUserDefaults and is backwards compatible with the older implementation, so **no workflows or dependent code will break, and old saved settings will persist.**

The RCTDevMenu interface has not changed and is therefore also backwards-compatible, though
some methods are now deprecated.

In order to ensure that RCTDevSettings
Closes https://github.com/facebook/react-native/pull/11613

Reviewed By: mmmulani

Differential Revision: D4571773

Pulled By: javache

fbshipit-source-id: 25555d0a6eaa81f694343e079ed02439e5845fbc
2017-02-24 07:00:16 -08:00
Eming Kwok 40b84fa5f8 fix memory leak in Chrome debugging
Summary:
`RCTWebSocketExecutor` saves every WebSocket callback when sending message to chrome, but does not clear them in a debug session until the JS bridge is reloaded, and there may be thousands of blocks saved in the callback table. This PR removes them after they are called.
Closes https://github.com/facebook/react-native/pull/11341

Differential Revision: D4295710

Pulled By: javache

fbshipit-source-id: 29a02d1aba320115bbb97aee8981e34b89303c91
2016-12-07 17:13:42 -08:00
Pieter De Baets e1577df1fd Move all header imports to "<React/..>"
Summary:
To make React Native play nicely with our internal build infrastructure we need to properly namespace all of our header includes.

Where previously you could do `#import "RCTBridge.h"`, you must now write this as `#import <React/RCTBridge.h>`. If your xcode project still has a custom header include path, both variants will likely continue to work, but for new projects, we're defaulting the header include path to `$(BUILT_PRODUCTS_DIR)/usr/local/include`, where the React and CSSLayout targets will copy a subset of headers too. To make Xcode copy headers phase work properly, you may need to add React as an explicit dependency to your app's scheme and disable "parallelize build".

Reviewed By: mmmulani

Differential Revision: D4213120

fbshipit-source-id: 84a32a4b250c27699e6795f43584f13d594a9a82
2016-11-23 07:58:39 -08:00
Pieter De Baets f255bda51f Fix loop when websocket executor is used without packager present
Reviewed By: mhorowitz

Differential Revision: D4159911

fbshipit-source-id: db913704641daf055060f5fe4561479daf76cd5a
2016-11-21 07:13:28 -08:00
Omeid 54f48de48a ios:websocket:exectuor : Grab port from Bundle URL
Summary:
Grabbing the port from Bundle URL allows concurrent Remote JS Debugging using the same machine with running multiple instances of packager on different ports.

This improves the developer experience when developing and debugging cross-platform components.
Closes https://github.com/facebook/react-native/pull/10007

Differential Revision: D4008630

Pulled By: javache

fbshipit-source-id: fcf8495e564fd9ac7baf26a87ed3904898132aa0
2016-10-12 08:43:37 -07:00
Douglas Lowder d368ebfab2 Apple TV support 1: existing Objective C code should compile for tvOS
Summary:
First commit for Apple TV support: changes to existing Objective-C code so that it will compile correctly for tvOS.
Closes https://github.com/facebook/react-native/pull/9649

Differential Revision: D3916021

Pulled By: javache

fbshipit-source-id: 34acc9daf3efff835ffe38c43ba5d4098a02c830
2016-09-27 06:28:33 -07:00
Skotch Vail bcf4bb6edd Automated changes to remove implicit capture of self in blocks: Libraries/FBReactKit/BUCK
Reviewed By: javache

Differential Revision: D3442470

fbshipit-source-id: 584a2bb3df5f7122166778b8fd44fae45560491e
2016-07-07 12:44:14 -07:00
Nathan Azaria 9443bc5c3f Changed the host for RCTWebSocketExecutor to the one retrieved from the bridge.
Reviewed By: javache

Differential Revision: D3425043

fbshipit-source-id: 342d3dfede6a29197dedb68278ee088dcf009e16
2016-06-13 13:28:28 -07:00
Nick Lockwood 72b363d7fc Replaced isMainThread checks with a proper test for main queue
Summary:
As per https://twitter.com/olebegemann/status/738656134731599872, our use of "main thread" to mean "main queue" seems to be unsafe.

This diff replaces the `NSThread.isMainQueue` checks with dispatch_get_specific(), which is the recommended approach.

I've also replaced all use of "MainThread" terminology with "MainQueue", and taken the opportunity to deprecate the "sync" param of `RCTExecuteOnMainThread()`, which, while we do still use it in a few places, is incredibly unsafe and shouldn't be encouraged.

Reviewed By: javache

Differential Revision: D3384910

fbshipit-source-id: ea7c216013372267b82eb25a38db5eb4cd46a089
2016-06-06 07:58:36 -07:00
Elliot Lynde 7e515f8d4a Wait longer for debugger proxy
Reviewed By: yuzhi

Differential Revision: D3198412

fb-gh-sync-id: fe11f74b2a019accc24b08162746ce4793a49b90
fbshipit-source-id: fe11f74b2a019accc24b08162746ce4793a49b90
2016-04-19 17:13:25 -07:00
digeff 4c8a9f0d00 Added support for JavaScript third-party debuggers
Summary:* Add ability to configure the app that should open when starting debugging

axemclion discussed this feature with tadeuzagallo and martinbigio on: https://github.com/facebook/react-native/issues/5051
Closes https://github.com/facebook/react-native/pull/5683

Reviewed By: martinbigio

Differential Revision: D2971497

Pulled By: mkonicek

fb-gh-sync-id: 91c3ce68feed989658124bb96cb61d03dd032599
fbshipit-source-id: 91c3ce68feed989658124bb96cb61d03dd032599
2016-04-07 13:15:58 -07:00
Pieter De Baets b00c77af80 Increase RN devtools retry timeout
Summary:The 200ms timeout was causing resource issues and causing a lot of overhead when you're not running the devtools, since it will basically create a new socket every 200ms.

Also clean up the way we do logging so it's completely compiled out in prod, and standardize all the names we use for threading to lowercase react.

Reviewed By: frantic

Differential Revision: D3115975

fb-gh-sync-id: e6e51c0621d8e9fc4eadb864acd678b8b5d322a1
fbshipit-source-id: e6e51c0621d8e9fc4eadb864acd678b8b5d322a1
2016-04-01 07:02:25 -07:00
Alex Kotliarskyi 64d56f34b7 Improve Chrome debugger
Summary:
`debugger.html` contained a ton of hacky code that was needed to ensure we have a clean JS runtime every time a client RN app connects. That was needed because we used the page's global environment as runtime. Some time ago WebWorker support was added and now we run RN code inside an isolated WebWorker instance, and we can safely get rid of all these hacks.

This has a bunch of nice side-effects: debug reload works faster, `console.log`s are preserved, `debuggerWorker.js` selection doesn't change.

Made sure the debugging (breakpoints, etc.) still works as before.

Small demo
![](http://g.recordit.co/FPdVHLHPUW.gif)
Closes https://github.com/facebook/react-native/pull/5715

Reviewed By: svcscm

Differential Revision: D2906602

Pulled By: frantic

fb-gh-sync-id: 1a6ab9a5655d7c32ddd23619564e59c377b53a35
2016-02-05 15:17:33 -08:00
Martín Bigio 4f37fe6f68 Improve error wording when packager dies and simulator was on debug mode
Reviewed By: jingc

Differential Revision: D2835719

fb-gh-sync-id: 694aac79cd9a76cfac32f7808c3f1bbb85d6bfb0
2016-01-19 16:37:34 -08:00
Martín Bigio 469bb7fbfd Improve error wording when fail to launch debugger
Reviewed By: javache

Differential Revision: D2829484

fb-gh-sync-id: a3402ece1f5cd19e8408fa3ab89adf7a26c66de9
2016-01-14 10:02:34 -08:00
Pieter De Baets 0cfe76399c Improve red boxes coming from RCTWebSocketExecutor
Reviewed By: tadeuzagallo

Differential Revision: D2775452

fb-gh-sync-id: b709e0e725ab76468700466b804237eed9158bfd
2015-12-23 13:32:28 -08:00
Sebastian Markbage 8d397b4cbc Decouple Module System from Native Calls
Summary:
The JavaScript ecosystem doesn't have the notion of a built-in native module loader. Even Node is decoupled from its module loader. The module loader system is just JS that runs on top of the global `process` object which has all the built-in goodies.

Additionally there is no such thing as a global require. That is something unique to our providesModule system. In other module systems such as node, every require is contextual. Even registered npm names are localized by version.

The only global namespace that is accessible to the host environment is the global object. Normally module systems attaches itself onto the hooks provided by the host environment on the global object.

Currently, we have two forms of dispatch that reaches directly into the module system. executeJSCall which reaches directly into require. Everything now calls through the BatchedBridge module (except one RCTLog edge case that I will fix). I propose that the executors calls directly onto `BatchedBridge` through an instance on the global so that everything is guaranteed to go through it. It becomes the main communication hub.

I also propose that we drop the dynamic requires inside of MessageQueue/BatchBridge and instead have the modules register themselves with the bridge.

executeJSCall was originally modeled after the XHP equivalent. The XHP equivalent was designed that way because the act of doing the call was the thing that defined a dependency on the module from the page. However, that is not how React Native works.

The JS side is driving the dependencies by virtue of requiring new modules and frameworks and the existence of dependencies is driven by the JS side, so this design doesn't make as much sense.

The main driver for this is to be able to introduce a new module system like Prepack's module system. However, it also unlocks the possibility to do dead module elimination even in our current module system. It is currently not possible because we don't know which module might be called from native.

Since the module system now becomes decoupled we could publish all our providesModule modules as npm/CommonJS modules using a rewrite script. That's what React Core does.

That way people could use any CommonJS bundler such as Webpack, Closure Compiler, Rollup or some new innovation to create a JS bundle.

This diff expands the executeJSCalls to the BatchedBridge's three individual pieces to make them first class instead of being dynamic. This removes one layer of abstraction. Hopefully we can also remove more of the things that register themselves with the BatchedBridge (various EventEmitters) and instead have everything go through the public protocol. ReactMethod/RCT_EXPORT_METHOD.

public

Reviewed By: vjeux

Differential Revision: D2717535

fb-gh-sync-id: 70114f05483124f5ac5c4570422bb91a60a727f6
2015-12-08 16:03:37 -08:00
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
Summary: public

The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.

This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.

The rules are now as follows:

* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but  `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.

These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.

I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:

Out of the 65 modules included in UIExplorer:

* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand

Reviewed By: jspahrsummers

Differential Revision: D2677695

fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 04:49:45 -08:00
Nick Lockwood fa0b45c58b Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
2015-11-14 10:28:28 -08:00
Natthu Bharambe cce9ba864f Command line flags to start RN apps in web executor mode.
Reviewed By: frantic

Differential Revision: D2613142

fb-gh-sync-id: fadcea3d23825420c0412f2e4d8d51c70b0f08ed
2015-11-06 14:53:28 -08:00
Frédéric Sagnes 4a3857ef1d Use JSStringCreateWithUTF8CString and skip NSString decoding when loading the bundle
Summary: public

Benchmarking our startup path has shown we spend a lot of time decoding strings (iPhone 4S / iPhone 5):

* reading a 2MB JS bundle: 35ms / 15ms
* decoding is to an `NSString`: 186ms / 78ms
* transforming that to a `JSString`: 29ms / 10ms

Instead of going through an `NSString` transformation, we generate a null-terminated bundle (0.1ms / 0.05ms to copy the data) and use `JSStringCreateWithUTF8CString` (121ms / 53ms) to generate the string. That makes decoding 70% faster.

Reviewed By: javache

Differential Revision: D2541140

fb-gh-sync-id: 09a016b8edfd46a9b62682c76705564d2024e75e
2015-10-16 08:11:25 -07:00
Nick Lockwood 88e0bbc469 Ran Convert > To Modern Objective C Syntax 2015-08-25 01:08:49 -08:00
Alex Kotliarskyi 8d07df4a22 [ReactNative] Unbreak debugger 2015-08-21 11:20:17 -07:00
Harrison Harnisch 46c6cde947 UI CPU and memory utilization graphs in Chrome debugging mode
Summary:
Chrome debugging UI is currently only showing connection state and logs in the console, leaving room for plenty of interesting information.

I've pushed the UI (using the same convention set by FPS -- UI/JS) CPU and memory utilization data over the debug Websocket and tapped into the existing stream of JS calls that get ran in V8.

The number of JS calls in a time interval is counted for all sub calls in a batch
https://github.com/hharnisc/react-native/blob/master/packager/debugger.html#L150

The last 5 batches of JS calls are displayed in a list format.

<img width="951" alt="screen shot 2015-07-19 at 7 34 00 pm" src="https://cloud.githubusercontent.com/assets/1388079/8769257/edc42f70-2e4d-11e5-8813-e86ef530a446.png">

Charts are created with [Chart.JS](https://github.com/nnnick/Chart.js) (MIT licensed).
Closes https://github.com/facebook/react-native/pull/2050
Github Author: Harrison Harnisch <hharnisc@gmail.com>
2015-08-21 02:11:45 -07:00
Nick Lockwood 8d1e02b8bd Convert alloc/init to new to please linter 2015-08-17 08:46:00 -07:00
Nick Lockwood f165bbaf4e Use +[RCTConvert NSURL:] everywhere instead of +[NSURL URLWithString:]
Summary:
RCTConvert's URL: method gracefully handles unescaped urls, local file urls, urls containing unicode, etc. URLWithString doesn't.
2015-08-04 16:26:16 -08:00
Tadeu Zagallo 127f7095dc [ReactNative] Add RCTBridgeDelegate
Summary:
Add a new bridge delegate protocol to allow a more flexible bridge configuration.

For now it just support the pre-existent configurations + providing the JavaScript
source to the bridge, that should allow pre-loading sources.
2015-07-28 15:57:02 -08:00
Tadeu Zagallo d30ada61f0 [ReactNative] Remove unused executor context id
Summary:
Remove `RCTGetExecutorID` and `RCTSetExecutorID`, it wasn't used anymore since
the bridge was refactored into `RCTBridge` and `RCTBatchedBridge`.
2015-07-14 16:40:21 -08:00
Nick Lockwood 650fc9de4c Increased warning levels to -Wall -Wextra, and fixed Xcode 7 beta issues
Summary:
@public

I've increased the warning levels in the OSS frameworks, which caught a bunch of minor issues. I also fixed some new errors in Xcode 7 relating to designated initializers and TLS security.

Test Plan:
* Test the sample apps and make sure they still work.
* Run tests.
2015-06-15 07:52:50 -08:00
Tadeu Zagallo efd386eba2 [ReactNative] Fix timers for debugger executors
Summary:
@public

`-[RCTJavaScriptExecutor executeBlockOnJavaScriptQueue:]` would always `dispatch_async`
for the WebView and WebSocket executors, what caused for any frame aligned dispatch.

Test Plan:
Test the `Timers, TimerMixin` example on UIExplorer, `requestAnimationFrame` was
taking ~33.3ms when debugging, now takes ~16.6ms as expected.
2015-06-12 16:59:19 -08:00
Tadeu Zagallo 847dff8d75 [ReactNative] Make JavaScript executors bridge modules
Summary:
@public

This is the first of a few diffs that change the way the executors are handled
by the bridge.

For they are just promoted to modules, so they are automatically loaded by the bridge.

Test Plan:
Tested on UIExplorer, Catalyst and MAdMan.
Tested all the 3 executors, everything looks fine.
2015-06-09 15:40:55 -08:00
Harrison Harnisch babdc21614 WebSocket polyfill
Summary:
- Added as a library in /Libraries/WebSocket
- Drag and drop to add to project (similar to adding Geolocation polyfill)
- Exposed as `window.WebSocket` which conforms with https://developer.mozilla.org/en-US/docs/Web/API/WebSocket specs
Closes https://github.com/facebook/react-native/pull/890
Github Author: Harrison Harnisch <hharnisc@gmail.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-05-14 09:37:02 -08:00