Extract part of executeApplicationScript into a C function

Reviewed By: javache

Differential Revision: D3542897

fbshipit-source-id: aa74c0c7c4477158fc9c8aff69432aed592f472f
This commit is contained in:
Adam Ernst 2016-07-11 13:14:23 -07:00 committed by Facebook Github Bot 8
parent 5e89baa7a0
commit af7104b49e

View File

@ -694,30 +694,26 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
if (!self.isValid) {
return;
}
[self->_performanceLogger markStartForTag:RCTPLScriptExecution];
JSValueRef jsError = NULL;
RCTJSCWrapper *jscWrapper = self->_jscWrapper;
JSStringRef execJSString = jscWrapper->JSStringCreateWithUTF8CString((const char *)script.bytes);
JSStringRef bundleURL = jscWrapper->JSStringCreateWithUTF8CString(sourceURL.absoluteString.UTF8String);
JSGlobalContextRef ctx = self->_context.context.JSGlobalContextRef;
JSValueRef result = jscWrapper->JSEvaluateScript(ctx, execJSString, NULL, bundleURL, 0, &jsError);
jscWrapper->JSStringRelease(bundleURL);
jscWrapper->JSStringRelease(execJSString);
NSError *error = executeApplicationScript(self->_jscWrapper, script, sourceURL, self->_context.context.JSGlobalContextRef);
[self->_performanceLogger markStopForTag:RCTPLScriptExecution];
if (onComplete) {
NSError *error;
if (!result) {
error = RCTNSErrorFromJSError(jscWrapper, ctx, jsError);
}
onComplete(error);
}
}), 0, @"js_call", (@{ @"url": sourceURL.absoluteString }))];
}
static NSError *executeApplicationScript(RCTJSCWrapper *jscWrapper, NSData *script, NSURL *sourceURL, JSGlobalContextRef ctx)
{
JSValueRef jsError = NULL;
JSStringRef execJSString = jscWrapper->JSStringCreateWithUTF8CString((const char *)script.bytes);
JSStringRef bundleURL = jscWrapper->JSStringCreateWithUTF8CString(sourceURL.absoluteString.UTF8String);
JSValueRef result = jscWrapper->JSEvaluateScript(ctx, execJSString, NULL, bundleURL, 0, &jsError);
jscWrapper->JSStringRelease(bundleURL);
jscWrapper->JSStringRelease(execJSString);
return result ? nil : RCTNSErrorFromJSError(jscWrapper, ctx, jsError);
}
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
{
if ([NSThread currentThread] != _javaScriptThread) {