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

View File

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

View File

@ -613,23 +613,23 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
- (void)_callFunctionOnModule:(NSString *)module - (void)_callFunctionOnModule:(NSString *)module
method:(NSString *)method method:(NSString *)method
arguments:(NSArray *)args arguments:(NSArray *)args
flushQueue:(BOOL)flushQueue returnValue:(BOOL)returnValue
unwrapResult:(BOOL)unwrapResult unwrapResult:(BOOL)unwrapResult
callback:(RCTJavaScriptCallback)onComplete callback:(RCTJavaScriptCallback)onComplete
{ {
// TODO: Make this function handle first class instead of dynamically dispatching it. #9317773 // 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]; [self _executeJSCall:bridgeMethod arguments:@[module, method, args] unwrapResult:unwrapResult callback:onComplete];
} }
- (void)callFunctionOnModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args callback:(RCTJavaScriptCallback)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 - (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 - (void)invokeCallbackID:(NSNumber *)cbID