mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 23:28:12 +00:00
Fix a folly::dynamic deprecated pattern
Reviewed By: javache Differential Revision: D4075622 fbshipit-source-id: 4a6b6c4068d762dce2b1535bfd9630e185f5489f
This commit is contained in:
parent
d8e77f0c76
commit
dc02907039
@ -12,6 +12,7 @@
|
||||
#include <folly/json.h>
|
||||
#include <folly/ScopeGuard.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <unordered_set>
|
||||
#include <dlfcn.h>
|
||||
|
||||
@ -98,10 +99,12 @@ void CxxMethodWrapper::invoke(jobject jCatalystInstance, ExecutorToken::jhybrido
|
||||
id1 = arguments->array[arguments->array.size() - 2].getInt();
|
||||
int id2 = arguments->array[arguments->array.size() - 1].getInt();
|
||||
second = [catalystInstance, executorToken, id2](std::vector<folly::dynamic> args) mutable {
|
||||
folly::dynamic argsArray(std::make_move_iterator(args.begin()),
|
||||
std::make_move_iterator(args.end()));
|
||||
ThreadScope guard;
|
||||
sCatalystInstanceInvokeCallback(
|
||||
catalystInstance.get(), executorToken.get(), id2,
|
||||
ReadableNativeArray::newObjectCxxArgs(std::move(args)).get());
|
||||
ReadableNativeArray::newObjectCxxArgs(std::move(argsArray)).get());
|
||||
catalystInstance.reset();
|
||||
executorToken.reset();
|
||||
};
|
||||
@ -110,10 +113,12 @@ void CxxMethodWrapper::invoke(jobject jCatalystInstance, ExecutorToken::jhybrido
|
||||
}
|
||||
|
||||
first = [catalystInstance, executorToken, id1](std::vector<folly::dynamic> args) mutable {
|
||||
folly::dynamic argsArray(std::make_move_iterator(args.begin()),
|
||||
std::make_move_iterator(args.end()));
|
||||
ThreadScope guard;
|
||||
sCatalystInstanceInvokeCallback(
|
||||
catalystInstance.get(), executorToken.get(), id1,
|
||||
ReadableNativeArray::newObjectCxxArgs(std::move(args)).get());
|
||||
ReadableNativeArray::newObjectCxxArgs(std::move(argsArray)).get());
|
||||
// This is necessary because by the time the lambda's dtor runs,
|
||||
// the guard has been destroyed, and it may not be possible to
|
||||
// get a JNIEnv* to clean up the captured global_ref.
|
||||
|
@ -20,7 +20,7 @@ const auto EXECUTOR_BASECLASS = "com/facebook/react/bridge/JavaJSExecutor";
|
||||
static std::string executeJSCallWithProxy(
|
||||
jobject executor,
|
||||
const std::string& methodName,
|
||||
const std::vector<folly::dynamic>& arguments) {
|
||||
const folly::dynamic& arguments) {
|
||||
static auto executeJSCall =
|
||||
jni::findClassStatic(EXECUTOR_BASECLASS)->getMethod<jstring(jstring, jstring)>("executeJSCall");
|
||||
|
||||
@ -88,20 +88,14 @@ void ProxyExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle>) {
|
||||
}
|
||||
|
||||
void ProxyExecutor::callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) {
|
||||
std::vector<folly::dynamic> call{
|
||||
moduleId,
|
||||
methodId,
|
||||
std::move(arguments),
|
||||
};
|
||||
auto call = folly::dynamic::array(moduleId, methodId, std::move(arguments));
|
||||
|
||||
std::string result = executeJSCallWithProxy(m_executor.get(), "callFunctionReturnFlushedQueue", std::move(call));
|
||||
m_delegate->callNativeModules(*this, folly::parseJson(result), true);
|
||||
}
|
||||
|
||||
void ProxyExecutor::invokeCallback(const double callbackId, const folly::dynamic& arguments) {
|
||||
std::vector<folly::dynamic> call{
|
||||
(double) callbackId,
|
||||
std::move(arguments)
|
||||
};
|
||||
auto call = folly::dynamic::array(callbackId, std::move(arguments));
|
||||
std::string result = executeJSCallWithProxy(m_executor.get(), "invokeCallbackAndReturnFlushedQueue", std::move(call));
|
||||
m_delegate->callNativeModules(*this, folly::parseJson(result), true);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "CxxNativeModule.h"
|
||||
#include "Instance.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include <folly/json.h>
|
||||
|
||||
#include <cxxreact/JsArgumentHelpers.h>
|
||||
@ -26,6 +28,24 @@ std::function<void(folly::dynamic)> makeCallback(
|
||||
};
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* CxxModule::Callback accepts a vector<dynamic>, makeCallback returns
|
||||
* a callback that accepts a dynamic, adapt the second into the first.
|
||||
* TODO: Callback types should be made equal (preferably
|
||||
* function<void(dynamic)>) to avoid the extra copy and indirect call.
|
||||
*/
|
||||
CxxModule::Callback convertCallback(
|
||||
std::function<void(folly::dynamic)> callback) {
|
||||
return [callback = std::move(callback)](std::vector<folly::dynamic> args) {
|
||||
callback(folly::dynamic(std::make_move_iterator(args.begin()),
|
||||
std::make_move_iterator(args.end())));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CxxNativeModule::CxxNativeModule(std::weak_ptr<Instance> instance,
|
||||
std::unique_ptr<CxxModule> module)
|
||||
: instance_(instance)
|
||||
@ -86,10 +106,13 @@ void CxxNativeModule::invoke(ExecutorToken token, unsigned int reactMethodId, fo
|
||||
}
|
||||
|
||||
if (method.callbacks == 1) {
|
||||
first = makeCallback(instance_, token, params[params.size() - 1]);
|
||||
first = convertCallback(
|
||||
makeCallback(instance_, token, params[params.size() - 1]));
|
||||
} else if (method.callbacks == 2) {
|
||||
first = makeCallback(instance_, token, params[params.size() - 2]);
|
||||
second = 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);
|
||||
@ -158,4 +181,3 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook(
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user