fix: ignore exception thrown when `AppRegistry` is missing (#763)

This commit is contained in:
Tommy Nguyen 2022-02-14 11:35:19 +01:00 коммит произвёл GitHub
Родитель 03d4e1e4a5
Коммит a19724dfcf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 30 добавлений и 23 удалений

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

@ -17,33 +17,40 @@ std::vector<std::string> ReactTestApp::GetAppKeys(Runtime &runtime)
return result;
}
// const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry");
auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId);
auto getCallableModule = fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule");
auto appRegistry =
getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry").asObject(runtime);
try {
// const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry");
auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId);
auto getCallableModule =
fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule");
auto appRegistry = getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry")
.asObject(runtime);
// const appKeys = appRegistry.getAppKeys();
auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys");
auto appKeys = getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime);
// const appKeys = appRegistry.getAppKeys();
auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys");
auto appKeys =
getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime);
auto length = appKeys.length(runtime);
result.reserve(length);
auto length = appKeys.length(runtime);
result.reserve(length);
auto logBox = String::createFromAscii(runtime, "LogBox", 6);
for (size_t i = 0; i < length; ++i) {
auto value = appKeys.getValueAtIndex(runtime, i);
if (!value.isString()) {
continue;
auto logBox = String::createFromAscii(runtime, "LogBox", 6);
for (size_t i = 0; i < length; ++i) {
auto value = appKeys.getValueAtIndex(runtime, i);
if (!value.isString()) {
continue;
}
auto appKey = value.toString(runtime);
if (String::strictEquals(runtime, appKey, logBox)) {
// Ignore internal app keys
continue;
}
result.push_back(appKey.utf8(runtime));
}
auto appKey = value.toString(runtime);
if (String::strictEquals(runtime, appKey, logBox)) {
// Ignore internal app keys
continue;
}
result.push_back(appKey.utf8(runtime));
} catch (...) {
// Ignore - if we get here, Metro will eventually throw an invariant violation:
// Module AppRegistry is not a registered callable module (calling runApplication).
}
return result;