Android instrumentation tests for C++ module sync methods.
Differential Revision: D3574896 fbshipit-source-id: 8cd4c55b7a472c77cc86fd5cbfe43bc4541ba6ba
This commit is contained in:
parent
ca8531105e
commit
5d0131d31b
|
@ -44,12 +44,11 @@ public class CxxModuleWrapper implements NativeModule
|
|||
public native HybridData initHybrid();
|
||||
|
||||
@Override
|
||||
public native void invoke(CatalystInstance catalystInstance, ExecutorToken executorToken, ReadableNativeArray args);
|
||||
public native void invoke(CatalystInstance catalystInstance, ExecutorToken executorToken,
|
||||
ReadableNativeArray args);
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return BaseJavaModule.METHOD_TYPE_REMOTE;
|
||||
}
|
||||
public native String getType();
|
||||
}
|
||||
|
||||
public CxxModuleWrapper(String library, String factory) {
|
||||
|
|
|
@ -44,12 +44,21 @@ public:
|
|||
static void registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", CxxMethodWrapper::initHybrid),
|
||||
makeNativeMethod("getType", CxxMethodWrapper::getType),
|
||||
makeNativeMethod("invoke",
|
||||
"(Lcom/facebook/react/bridge/CatalystInstance;Lcom/facebook/react/bridge/ExecutorToken;Lcom/facebook/react/bridge/ReadableNativeArray;)V",
|
||||
CxxMethodWrapper::invoke),
|
||||
});
|
||||
}
|
||||
|
||||
std::string getType() {
|
||||
if (method_->func) {
|
||||
return "remote";
|
||||
} else {
|
||||
return "syncHook";
|
||||
}
|
||||
}
|
||||
|
||||
void invoke(jobject catalystinstance, ExecutorToken::jhybridobject executorToken, NativeArray* args);
|
||||
|
||||
const CxxModule::Method* method_;
|
||||
|
@ -59,6 +68,12 @@ void CxxMethodWrapper::invoke(jobject jCatalystInstance, ExecutorToken::jhybrido
|
|||
CxxModule::Callback first;
|
||||
CxxModule::Callback second;
|
||||
|
||||
if (!method_->func) {
|
||||
throw std::runtime_error(
|
||||
folly::to<std::string>("Method ", method_->name,
|
||||
" is synchronous but invoked asynchronously"));
|
||||
}
|
||||
|
||||
if (method_->callbacks >= 1) {
|
||||
auto catalystInstance = make_global(adopt_local(jCatalystInstance));
|
||||
global_ref<ExecutorToken::jhybridobject> executorToken = make_global(jExecutorToken);
|
||||
|
|
|
@ -57,6 +57,10 @@ void Sample::call_later(int msec, std::function<void()> f) {
|
|||
t.detach();
|
||||
}
|
||||
|
||||
double Sample::twice(double n) {
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
SampleCxxModule::SampleCxxModule(std::unique_ptr<Sample> sample)
|
||||
: sample_(std::move(sample)) {}
|
||||
|
||||
|
@ -100,6 +104,13 @@ auto SampleCxxModule::getMethods() -> std::vector<Method> {
|
|||
Method("except", [this] {
|
||||
sample_->except();
|
||||
}),
|
||||
Method("twice", [this](dynamic args) -> dynamic {
|
||||
return sample_->twice(jsArgAsDouble(args, 0));
|
||||
}, SyncTag),
|
||||
Method("syncHello", [this]() -> dynamic {
|
||||
sample_->hello();
|
||||
return nullptr;
|
||||
}, SyncTag),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
std::map<std::string, std::string> load();
|
||||
void call_later(int msec, std::function<void()> f);
|
||||
void except();
|
||||
double twice(double n);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> state_;
|
||||
|
|
Loading…
Reference in New Issue