mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
Make startup errors in the websocket executor invalidate the bridge
Reviewed By: mhorowitz Differential Revision: D5226936 fbshipit-source-id: b6d605974674d0e6f86559f2583553e3636d389b
This commit is contained in:
parent
502604074c
commit
c5004d5dd0
@ -172,6 +172,11 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
- (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)URL onComplete:(RCTJavaScriptCompleteBlock)onComplete
|
- (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)URL onComplete:(RCTJavaScriptCompleteBlock)onComplete
|
||||||
{
|
{
|
||||||
|
// Hack: the bridge transitions out of loading state as soon as this method returns, which prevents us
|
||||||
|
// from completely invalidating the bridge and preventing an endless barage of RCTLog.logIfNoNativeHook
|
||||||
|
// calls if the JS execution environment is broken. We therefore block this thread until this message has returned.
|
||||||
|
dispatch_semaphore_t scriptSem = dispatch_semaphore_create(0);
|
||||||
|
|
||||||
NSDictionary<NSString *, id> *message = @{
|
NSDictionary<NSString *, id> *message = @{
|
||||||
@"method": @"executeApplicationScript",
|
@"method": @"executeApplicationScript",
|
||||||
@"url": RCTNullIfNil(URL.absoluteString),
|
@"url": RCTNullIfNil(URL.absoluteString),
|
||||||
@ -184,7 +189,10 @@ RCT_EXPORT_MODULE()
|
|||||||
NSString *error = reply[@"error"];
|
NSString *error = reply[@"error"];
|
||||||
onComplete(error ? RCTErrorWithMessage(error) : nil);
|
onComplete(error ? RCTErrorWithMessage(error) : nil);
|
||||||
}
|
}
|
||||||
|
dispatch_semaphore_signal(scriptSem);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
dispatch_semaphore_wait(scriptSem, DISPATCH_TIME_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)flushedQueue:(RCTJavaScriptCallback)onComplete
|
- (void)flushedQueue:(RCTJavaScriptCallback)onComplete
|
||||||
|
@ -1010,7 +1010,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
|||||||
// ensureOnJavaScriptThread may execute immediately, so use jsMessageThread, to make sure
|
// ensureOnJavaScriptThread may execute immediately, so use jsMessageThread, to make sure
|
||||||
// the block is invoked after callJSFunction
|
// the block is invoked after callJSFunction
|
||||||
if (completion) {
|
if (completion) {
|
||||||
|
if (self->_jsMessageThread) {
|
||||||
self->_jsMessageThread->runOnQueue(completion);
|
self->_jsMessageThread->runOnQueue(completion);
|
||||||
|
} else {
|
||||||
|
RCTLogWarn(@"Can't invoke completion without messageThread");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user