Support invoking method that returns result and flushes call queue

Reviewed By: mhorowitz

Differential Revision: D3870879

fbshipit-source-id: bc8f70d9866dfc25468c9072c209cc6842b98575
This commit is contained in:
Pieter De Baets 2016-09-16 06:14:13 -07:00 committed by Facebook Github Bot 9
parent 0162be8fc3
commit 95cce07baf
3 changed files with 8 additions and 7 deletions

View File

@ -71,7 +71,7 @@ class MessageQueue {
[
'invokeCallbackAndReturnFlushedQueue',
'callFunctionReturnFlushedQueue',
'callFunction',
'callFunctionReturnResultAndFlushedQueue',
'flushedQueue',
].forEach((fn) => (this[fn] = this[fn].bind(this)));
@ -109,14 +109,14 @@ class MessageQueue {
return this.flushedQueue();
}
callFunction(module, method, args) {
callFunctionReturnResultAndFlushedQueue(module, method, args) {
let result;
guard(() => {
result = this.__callFunction(module, method, args);
this.__callImmediates();
});
return result;
return [result, this.flushedQueue()];
}
invokeCallbackAndReturnFlushedQueue(cbID, args) {

View File

@ -530,6 +530,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
}
if (loadError) {
RCTLogError(@"Failed to execute source code: %@", [loadError localizedDescription]);
dispatch_async(dispatch_get_main_queue(), ^{
[self stopLoadingWithError:loadError];
});

View File

@ -613,23 +613,23 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
- (void)_callFunctionOnModule:(NSString *)module
method:(NSString *)method
arguments:(NSArray *)args
flushQueue:(BOOL)flushQueue
returnValue:(BOOL)returnValue
unwrapResult:(BOOL)unwrapResult
callback:(RCTJavaScriptCallback)onComplete
{
// TODO: Make this function handle first class instead of dynamically dispatching it. #9317773
NSString *bridgeMethod = flushQueue ? @"callFunctionReturnFlushedQueue" : @"callFunction";
NSString *bridgeMethod = returnValue ? @"callFunctionReturnFlushedQueue" : @"callFunctionReturnResultAndFlushedQueue";
[self _executeJSCall:bridgeMethod arguments:@[module, method, args] unwrapResult:unwrapResult callback:onComplete];
}
- (void)callFunctionOnModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args callback:(RCTJavaScriptCallback)onComplete
{
[self _callFunctionOnModule:module method:method arguments:args flushQueue:YES unwrapResult:YES callback:onComplete];
[self _callFunctionOnModule:module method:method arguments:args returnValue:YES unwrapResult:YES callback:onComplete];
}
- (void)callFunctionOnModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args jsValueCallback:(RCTJavaScriptValueCallback)onComplete
{
[self _callFunctionOnModule:module method:method arguments:args flushQueue:NO unwrapResult:NO callback:onComplete];
[self _callFunctionOnModule:module method:method arguments:args returnValue:NO unwrapResult:NO callback:onComplete];
}
- (void)invokeCallbackID:(NSNumber *)cbID