Decoupling initialisation and synchronous execution.
Reviewed By: javache Differential Revision: D4117471 fbshipit-source-id: b00de532c99f041ebba8b9d74972a36827a1a3f4
This commit is contained in:
parent
e7dc71ba84
commit
227f1b0ea8
|
@ -87,15 +87,21 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey;
|
||||||
/**
|
/**
|
||||||
* @experimental
|
* @experimental
|
||||||
* Pass a RCTJSContextProvider object to use an NSThread/JSContext pair that have already been created.
|
* Pass a RCTJSContextProvider object to use an NSThread/JSContext pair that have already been created.
|
||||||
* The returned executor has already executed the supplied application script synchronously.
|
* The underlying JSContext will be returned in the JSContext pointer if it is non-NULL.
|
||||||
* The underlying JSContext will be returned in the JSContext pointer if it is non-NULL and there was no error.
|
|
||||||
* If an error occurs, this method will return nil and specify the error in the error pointer if it is non-NULL.
|
|
||||||
*/
|
*/
|
||||||
+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider
|
+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider
|
||||||
applicationScript:(NSData *)applicationScript
|
JSContext:(JSContext **)JSContext;
|
||||||
sourceURL:(NSURL *)sourceURL
|
|
||||||
JSContext:(JSContext **)JSContext
|
/**
|
||||||
error:(NSError **)error;
|
* @experimental
|
||||||
|
* synchronouslyExecuteApplicationScript:sourceURL:JSContext:error:
|
||||||
|
*
|
||||||
|
* Run the provided JS Script/Bundle, blocking the caller until it finishes.
|
||||||
|
* If there is an error during execution, it is returned, otherwise `NULL` is
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
- (NSError *)synchronouslyExecuteApplicationScript:(NSData *)script
|
||||||
|
sourceURL:(NSURL *)sourceURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the given module/method directly. The completion block will be called with the
|
* Invokes the given module/method directly. The completion block will be called with the
|
||||||
|
|
|
@ -252,20 +252,13 @@ static NSThread *newJavaScriptThread(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider
|
+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider
|
||||||
applicationScript:(NSData *)applicationScript
|
|
||||||
sourceURL:(NSURL *)sourceURL
|
|
||||||
JSContext:(JSContext **)JSContext
|
JSContext:(JSContext **)JSContext
|
||||||
error:(NSError **)error
|
|
||||||
{
|
{
|
||||||
const RCTJSContextData data = JSContextProvider.data;
|
const RCTJSContextData data = JSContextProvider.data;
|
||||||
if (JSContext) {
|
if (JSContext) {
|
||||||
*JSContext = data.context;
|
*JSContext = data.context;
|
||||||
}
|
}
|
||||||
RCTJSCExecutor *executor = [[RCTJSCExecutor alloc] initWithJSContextData:data];
|
return [[RCTJSCExecutor alloc] initWithJSContextData:data];
|
||||||
if (applicationScript && ![executor _synchronouslyExecuteApplicationScript:applicationScript sourceURL:sourceURL JSContext:data.context error:error]) {
|
|
||||||
return nil; // error has been set by _synchronouslyExecuteApplicationScript:
|
|
||||||
}
|
|
||||||
return executor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithJSContextData:(const RCTJSContextData &)data
|
- (instancetype)initWithJSContextData:(const RCTJSContextData &)data
|
||||||
|
@ -280,33 +273,29 @@ static NSThread *newJavaScriptThread(void)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)_synchronouslyExecuteApplicationScript:(NSData *)script
|
- (NSError *)synchronouslyExecuteApplicationScript:(NSData *)script
|
||||||
sourceURL:(NSURL *)sourceURL
|
sourceURL:(NSURL *)sourceURL
|
||||||
JSContext:(JSContext *)context
|
|
||||||
error:(NSError **)error
|
|
||||||
{
|
{
|
||||||
TaggedScript taggedScript = loadTaggedScript(script, sourceURL, _performanceLogger, _randomAccessBundle, error);
|
NSError *loadError;
|
||||||
|
TaggedScript taggedScript = loadTaggedScript(script, sourceURL, _performanceLogger, _randomAccessBundle, &loadError);
|
||||||
|
|
||||||
if (!taggedScript.script) {
|
if (loadError) {
|
||||||
return NO;
|
return loadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taggedScript.tag == RCTScriptRAMBundle) {
|
if (taggedScript.tag == RCTScriptRAMBundle) {
|
||||||
registerNativeRequire(context, self);
|
registerNativeRequire(_context.context, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
NSError *returnedError = executeApplicationScript(taggedScript, sourceURL,
|
NSError *execError = executeApplicationScript(taggedScript, sourceURL,
|
||||||
_jscWrapper,
|
_jscWrapper,
|
||||||
_performanceLogger,
|
_performanceLogger,
|
||||||
_context.context.JSGlobalContextRef);
|
_context.context.JSGlobalContextRef);
|
||||||
if (returnedError) {
|
if (execError) {
|
||||||
if (error) {
|
return execError;
|
||||||
*error = returnedError;
|
|
||||||
}
|
|
||||||
return NO;
|
|
||||||
} else {
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RCTJavaScriptContext *)context
|
- (RCTJavaScriptContext *)context
|
||||||
|
|
Loading…
Reference in New Issue