Skip to content

Commit

Permalink
Don't create the JSCRuntime until createJSExecutor() is called.
Browse files Browse the repository at this point in the history
Summary:
This avoids an intermittent reentrancy bug in JSC on iOS 11
(https://bugs.webkit.org/show_bug.cgi?id=186827).  It also makes the
code more consistent with android.

Reviewed By: amnn

Differential Revision: D13313265

fbshipit-source-id: f42476b2f660e127ecfc9c72584554817eea1010
  • Loading branch information
mhorowitz authored and facebook-github-bot committed Dec 4, 2018
1 parent bdb084e commit 99c3709
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

typedef void (^RCTPendingCall)();

using namespace facebook::jsc;
using namespace facebook::jsi;
using namespace facebook::react;

Expand Down Expand Up @@ -92,6 +91,24 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
std::shared_ptr<JSExecutorFactory> factory_;
};

class JSCExecutorFactory : public JSExecutorFactory {
public:
std::unique_ptr<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override {
return folly::make_unique<JSIExecutor>(
facebook::jsc::makeJSCRuntime(),
delegate,
[](const std::string &message, unsigned int logLevel) {
_RCTLogJavaScriptInternal(
static_cast<RCTLogLevel>(logLevel),
[NSString stringWithUTF8String:message.c_str()]);
},
JSIExecutor::defaultTimeoutInvoker,
nullptr);
}
};

}

static bool isRAMBundle(NSData *script) {
Expand Down Expand Up @@ -320,13 +337,7 @@ - (void)start
executorFactory = [cxxDelegate jsExecutorFactoryForBridge:self];
}
if (!executorFactory) {
executorFactory = std::make_shared<JSIExecutorFactory>(
makeJSCRuntime(),
[](const std::string &message, unsigned int logLevel) {
_RCTLogJavaScriptInternal(
static_cast<RCTLogLevel>(logLevel),
[NSString stringWithUTF8String:message.c_str()]);
}, nullptr);
executorFactory = std::make_shared<JSCExecutorFactory>();
}
} else {
id<RCTJavaScriptExecutor> objcExecutor = [self moduleForClass:self.executorClass];
Expand Down

0 comments on commit 99c3709

Please sign in to comment.