mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 07:08:27 +00:00
Don't use the same throw for calling into JSC, and calling into native modules
Differential Revision: D3779181 fbshipit-source-id: 7fb17c9c90abd9302137dad3a326c6ce30e7ca86
This commit is contained in:
parent
46e47aaecd
commit
1d571c5ed5
@ -344,15 +344,14 @@ void JSCExecutor::bindBridge() throw(JSException) {
|
||||
m_flushedQueueJS = batchedBridge.getProperty("flushedQueue").asObject();
|
||||
}
|
||||
|
||||
void JSCExecutor::flush() {
|
||||
auto result = m_flushedQueueJS->callAsFunction({});
|
||||
void JSCExecutor::callNativeModules(Value&& value) {
|
||||
try {
|
||||
auto calls = Value(m_context, result).toJSONString();
|
||||
auto calls = value.toJSONString();
|
||||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
} catch (...) {
|
||||
std::string message = "Error in flush()";
|
||||
try {
|
||||
message += ":" + Value(m_context, result).toString().str();
|
||||
message += ":" + value.toString().str();
|
||||
} catch (...) {
|
||||
// ignored
|
||||
}
|
||||
@ -360,31 +359,44 @@ void JSCExecutor::flush() {
|
||||
}
|
||||
}
|
||||
|
||||
void JSCExecutor::flush() {
|
||||
callNativeModules(m_flushedQueueJS->callAsFunction({}));
|
||||
}
|
||||
|
||||
void JSCExecutor::callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) {
|
||||
try {
|
||||
auto result = m_callFunctionReturnFlushedQueueJS->callAsFunction({
|
||||
Value(m_context, String::createExpectingAscii(moduleId)),
|
||||
Value(m_context, String::createExpectingAscii(methodId)),
|
||||
Value::fromDynamic(m_context, std::move(arguments))
|
||||
});
|
||||
auto calls = Value(m_context, result).toJSONString();
|
||||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error("Error calling function: " + moduleId + ":" + methodId));
|
||||
}
|
||||
// This weird pattern is because Value is not default constructible.
|
||||
// The lambda is inlined, so there's no overhead.
|
||||
|
||||
auto result = [&] {
|
||||
try {
|
||||
return m_callFunctionReturnFlushedQueueJS->callAsFunction({
|
||||
Value(m_context, String::createExpectingAscii(moduleId)),
|
||||
Value(m_context, String::createExpectingAscii(methodId)),
|
||||
Value::fromDynamic(m_context, std::move(arguments))
|
||||
});
|
||||
} catch (...) {
|
||||
std::throw_with_nested(
|
||||
std::runtime_error("Error calling function: " + moduleId + ":" + methodId));
|
||||
}
|
||||
}();
|
||||
|
||||
callNativeModules(std::move(result));
|
||||
}
|
||||
|
||||
void JSCExecutor::invokeCallback(const double callbackId, const folly::dynamic& arguments) {
|
||||
try {
|
||||
auto result = m_invokeCallbackAndReturnFlushedQueueJS->callAsFunction({
|
||||
JSValueMakeNumber(m_context, callbackId),
|
||||
Value::fromDynamic(m_context, std::move(arguments))
|
||||
});
|
||||
auto calls = Value(m_context, result).toJSONString();
|
||||
m_delegate->callNativeModules(*this, std::move(calls), true);
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error(folly::to<std::string>("Error invoking callback.", callbackId)));
|
||||
}
|
||||
auto result = [&] {
|
||||
try {
|
||||
return m_invokeCallbackAndReturnFlushedQueueJS->callAsFunction({
|
||||
JSValueMakeNumber(m_context, callbackId),
|
||||
Value::fromDynamic(m_context, std::move(arguments))
|
||||
});
|
||||
} catch (...) {
|
||||
std::throw_with_nested(
|
||||
std::runtime_error(folly::to<std::string>("Error invoking callback.", callbackId)));
|
||||
}
|
||||
}();
|
||||
|
||||
callNativeModules(std::move(result));
|
||||
}
|
||||
|
||||
void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue) {
|
||||
|
@ -117,6 +117,7 @@ private:
|
||||
void initOnJSVMThread() throw(JSException);
|
||||
void terminateOnJSVMThread();
|
||||
void bindBridge() throw(JSException);
|
||||
void callNativeModules(Value&&);
|
||||
void flush();
|
||||
void flushQueueImmediate(std::string queueJSON);
|
||||
void loadModule(uint32_t moduleId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user