mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +08:00
Remove JsToNativeBridge's nativeQueue
Reviewed By: mhorowitz Differential Revision: D4589737 fbshipit-source-id: 3b2730417d99c4f98cfaad386bc50328f2551592
This commit is contained in:
committed by
Facebook Github Bot
parent
fbf6d1aaeb
commit
d7b37c4050
@@ -46,13 +46,6 @@ CxxModule::Callback convertCallback(
|
||||
|
||||
}
|
||||
|
||||
CxxNativeModule::CxxNativeModule(std::weak_ptr<Instance> instance,
|
||||
std::string name,
|
||||
CxxModule::Provider provider)
|
||||
: instance_(instance)
|
||||
, name_(std::move(name))
|
||||
, provider_(provider) {}
|
||||
|
||||
std::string CxxNativeModule::getName() {
|
||||
return name_;
|
||||
}
|
||||
@@ -85,8 +78,8 @@ bool CxxNativeModule::supportsWebWorkers() {
|
||||
|
||||
void CxxNativeModule::invoke(ExecutorToken token, unsigned int reactMethodId, folly::dynamic&& params) {
|
||||
if (reactMethodId >= methods_.size()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("methodId ", reactMethodId, " out of range [0..", methods_.size(), "]"));
|
||||
throw std::invalid_argument(folly::to<std::string>("methodId ", reactMethodId,
|
||||
" out of range [0..", methods_.size(), "]"));
|
||||
}
|
||||
if (!params.isArray()) {
|
||||
throw std::invalid_argument(
|
||||
@@ -99,25 +92,20 @@ void CxxNativeModule::invoke(ExecutorToken token, unsigned int reactMethodId, fo
|
||||
const auto& method = methods_[reactMethodId];
|
||||
|
||||
if (!method.func) {
|
||||
throw std::runtime_error(
|
||||
folly::to<std::string>("Method ", method.name,
|
||||
" is synchronous but invoked asynchronously"));
|
||||
throw std::runtime_error(folly::to<std::string>("Method ", method.name,
|
||||
" is synchronous but invoked asynchronously"));
|
||||
}
|
||||
|
||||
if (params.size() < method.callbacks) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Expected ", method.callbacks, " callbacks, but only ",
|
||||
params.size(), " parameters provided"));
|
||||
throw std::invalid_argument(folly::to<std::string>("Expected ", method.callbacks,
|
||||
" callbacks, but only ", params.size(), " parameters provided"));
|
||||
}
|
||||
|
||||
if (method.callbacks == 1) {
|
||||
first = convertCallback(
|
||||
makeCallback(instance_, token, params[params.size() - 1]));
|
||||
first = convertCallback(makeCallback(instance_, token, params[params.size() - 1]));
|
||||
} else if (method.callbacks == 2) {
|
||||
first = convertCallback(
|
||||
makeCallback(instance_, token, params[params.size() - 2]));
|
||||
second = convertCallback(
|
||||
makeCallback(instance_, token, params[params.size() - 1]));
|
||||
first = convertCallback(makeCallback(instance_, token, params[params.size() - 2]));
|
||||
second = convertCallback(makeCallback(instance_, token, params[params.size() - 1]));
|
||||
}
|
||||
|
||||
params.resize(params.size() - method.callbacks);
|
||||
@@ -141,16 +129,18 @@ void CxxNativeModule::invoke(ExecutorToken token, unsigned int reactMethodId, fo
|
||||
// stack. I'm told that will be possible in the future. TODO
|
||||
// mhorowitz #7128529: convert C++ exceptions to Java
|
||||
|
||||
try {
|
||||
method.func(std::move(params), first, second);
|
||||
} catch (const facebook::xplat::JsArgumentException& ex) {
|
||||
// This ends up passed to the onNativeException callback.
|
||||
throw;
|
||||
} catch (...) {
|
||||
// This means some C++ code is buggy. As above, we fail hard so the C++
|
||||
// developer can debug and fix it.
|
||||
std::terminate();
|
||||
}
|
||||
messageQueueThread_->runOnQueue([method, params=std::move(params), first, second] () {
|
||||
try {
|
||||
method.func(std::move(params), first, second);
|
||||
} catch (const facebook::xplat::JsArgumentException& ex) {
|
||||
// This ends up passed to the onNativeException callback.
|
||||
throw;
|
||||
} catch (...) {
|
||||
// This means some C++ code is buggy. As above, we fail hard so the C++
|
||||
// developer can debug and fix it.
|
||||
std::terminate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MethodCallResult CxxNativeModule::callSerializableNativeHook(
|
||||
|
||||
Reference in New Issue
Block a user