Skip to content

Commit

Permalink
rn | cxx | Move the definitions of TurboModule virtual methods to dec…
Browse files Browse the repository at this point in the history
…laration, to allow for use in context with RTTI.

Summary:
Not having this disallows including turbo module and extending in places where RTTI is enabled.
There is no additional includes or implementation changes - it merely allows for things to nicely link with other libraries.

Changelog: [General][Fixed] - Allow including TurboModule.h in mixed rtti/no-rtti environment, even if TurboModule.h/cpp is compiled without RTTI.

Reviewed By: appden

Differential Revision: D34637168

fbshipit-source-id: 2e5d9e546bdc5652f06436fec3b12f1aa9daab05
  • Loading branch information
nlutsenko authored and facebook-github-bot committed Mar 5, 2022
1 parent 87ad1e8 commit 1f87729
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall

LOCAL_SHARED_LIBRARIES = libfb libfbjni libreact_nativemodule_core
LOCAL_SHARED_LIBRARIES = libfb libfbjni libreact_nativemodule_core libjsi

LOCAL_STATIC_LIBRARIES = libcallinvokerholder libreactperfloggerjni

Expand Down
23 changes: 0 additions & 23 deletions ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,5 @@ TurboModule::TurboModule(
std::shared_ptr<CallInvoker> jsInvoker)
: name_(name), jsInvoker_(jsInvoker) {}

TurboModule::~TurboModule() {}

jsi::Value TurboModule::get(
jsi::Runtime &runtime,
const jsi::PropNameID &propName) {
std::string propNameUtf8 = propName.utf8(runtime);
auto p = methodMap_.find(propNameUtf8);
if (p == methodMap_.end()) {
// Method was not found, let JS decide what to do.
return jsi::Value::undefined();
}
MethodMetadata meta = p->second;
return jsi::Function::createFromHostFunction(
runtime,
propName,
static_cast<unsigned int>(meta.argCount),
[this, meta](
facebook::jsi::Runtime &rt,
const facebook::jsi::Value &thisVal,
const facebook::jsi::Value *args,
size_t count) { return meta.invoker(rt, *this, args, count); });
}

} // namespace react
} // namespace facebook
20 changes: 18 additions & 2 deletions ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,27 @@ enum TurboModuleMethodValueKind {
class JSI_EXPORT TurboModule : public facebook::jsi::HostObject {
public:
TurboModule(const std::string &name, std::shared_ptr<CallInvoker> jsInvoker);
virtual ~TurboModule();

virtual facebook::jsi::Value get(
facebook::jsi::Runtime &runtime,
const facebook::jsi::PropNameID &propName) override;
const facebook::jsi::PropNameID &propName) override {
std::string propNameUtf8 = propName.utf8(runtime);
auto p = methodMap_.find(propNameUtf8);
if (p == methodMap_.end()) {
// Method was not found, let JS decide what to do.
return jsi::Value::undefined();
}
MethodMetadata meta = p->second;
return jsi::Function::createFromHostFunction(
runtime,
propName,
static_cast<unsigned int>(meta.argCount),
[this, meta](
facebook::jsi::Runtime &rt,
const facebook::jsi::Value &thisVal,
const facebook::jsi::Value *args,
size_t count) { return meta.invoker(rt, *this, args, count); });
}

const std::string name_;
std::shared_ptr<CallInvoker> jsInvoker_;
Expand Down

0 comments on commit 1f87729

Please sign in to comment.