Permalink
Browse files

Refactored executeApplicationScript in RCTCxxBridge

Reviewed By: dcaspi

Differential Revision: D5850957

fbshipit-source-id: d2cacfd99fd7ffca70b0dcf0bf252ea160268c05
  • Loading branch information...
fromcelticpark authored and facebook-github-bot committed Sep 18, 2017
1 parent 7953707 commit 6e281798e844c2d824a375b0ef4447368087c5b6
Showing with 12 additions and 24 deletions.
  1. +12 −24 React/CxxBridge/RCTCxxBridge.mm
@@ -1155,25 +1155,7 @@ - (void)enqueueApplicationScript:(NSData *)script
{
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge enqueueApplicationScript]", nil);
[self _tryAndHandleError:^{
NSString *sourceUrlStr = deriveSourceURL(url);
if (isRAMBundle(script)) {
[self->_performanceLogger markStartForTag:RCTPLRAMBundleLoad];
auto ramBundle = std::make_unique<JSIndexedRAMBundle>(sourceUrlStr.UTF8String);
std::unique_ptr<const JSBigString> scriptStr = ramBundle->getStartupCode();
[self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad];
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
if (self->_reactInstance) {
self->_reactInstance->loadUnbundle(std::move(ramBundle), std::move(scriptStr),
sourceUrlStr.UTF8String, false);
}
} else if (self->_reactInstance) {
self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),
sourceUrlStr.UTF8String, false);
} else {
throw std::logic_error("Attempt to call loadApplicationScript: on uninitialized bridge");
}
}];
[self executeApplicationScript:script url:url async:YES];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
@@ -1185,6 +1167,13 @@ - (void)enqueueApplicationScript:(NSData *)script
}
- (void)executeApplicationScriptSync:(NSData *)script url:(NSURL *)url
{
[self executeApplicationScript:script url:url async:NO];
}
- (void)executeApplicationScript:(NSData *)script
url:(NSURL *)url
async:(BOOL)async
{
[self _tryAndHandleError:^{
NSString *sourceUrlStr = deriveSourceURL(url);
@@ -1196,19 +1185,18 @@ - (void)executeApplicationScriptSync:(NSData *)script url:(NSURL *)url
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
if (self->_reactInstance) {
self->_reactInstance->loadUnbundle(std::move(ramBundle), std::move(scriptStr),
sourceUrlStr.UTF8String, true);
sourceUrlStr.UTF8String, !async);
}
} else if (self->_reactInstance) {
self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),
sourceUrlStr.UTF8String, true);
sourceUrlStr.UTF8String, !async);
} else {
throw std::logic_error("Attempt to call loadApplicationScriptSync: on uninitialized bridge");
std::string methodName = async ? "loadApplicationScript" : "loadApplicationScriptSync";
throw std::logic_error("Attempt to call " + methodName + ": on uninitialized bridge");
}
}];
}
- (JSValue *)callFunctionOnModule:(NSString *)module
method:(NSString *)method
arguments:(NSArray *)arguments

0 comments on commit 6e28179

Please sign in to comment.