Added RCTInspectorDevServerHelper call in FBReactJSExecutor. Added UTF8StringForSourceURL

Reviewed By: javache

Differential Revision: D5246399

fbshipit-source-id: 179ff0b69886c4ff71911fc7b1d3491ff4d5967d
This commit is contained in:
Viacheslav Radchenko 2017-06-14 14:06:26 -07:00 коммит произвёл Facebook Github Bot
Родитель c9a39b3bd3
Коммит 879edf0d05
3 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -1062,19 +1062,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
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>(url.path.UTF8String);
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),
[[url absoluteString] UTF8String], false);
sourceUrlStr.UTF8String, false);
}
} else if (self->_reactInstance) {
self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),
[[url absoluteString] UTF8String], false);
sourceUrlStr.UTF8String, false);
} else {
throw std::logic_error("Attempt to call loadApplicationScript: on uninitialized bridge");
}
@ -1092,19 +1093,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
- (void)executeApplicationScriptSync:(NSData *)script url:(NSURL *)url
{
[self _tryAndHandleError:^{
NSString *sourceUrlStr = deriveSourceURL(url);
if (isRAMBundle(script)) {
[self->_performanceLogger markStartForTag:RCTPLRAMBundleLoad];
auto ramBundle = std::make_unique<JSIndexedRAMBundle>(url.path.UTF8String);
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),
[[url absoluteString] UTF8String], true);
sourceUrlStr.UTF8String, true);
}
} else if (self->_reactInstance) {
self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),
[[url absoluteString] UTF8String], true);
sourceUrlStr.UTF8String, true);
} else {
throw std::logic_error("Attempt to call loadApplicationScriptSync: on uninitialized bridge");
}

Просмотреть файл

@ -48,5 +48,6 @@ struct ValueEncoder<NSArray *> {
};
NSError *tryAndReturnError(const std::function<void()>& func);
NSString *deriveSourceURL(NSURL *url);
} }

Просмотреть файл

@ -133,4 +133,16 @@ NSError *tryAndReturnError(const std::function<void()>& func) {
}
}
NSString *deriveSourceURL(NSURL *url) {
NSString *sourceUrl;
if (url.isFileURL) {
// Url will contain only path to resource (i.g. file:// will be removed)
sourceUrl = url.path;
} else {
// Url will include protocol (e.g. http://)
sourceUrl = url.absoluteString;
}
return sourceUrl ?: @"";
}
} }