Skip to content

Commit 1f87729

Browse files
nlutsenkofacebook-github-bot
authored andcommitted
rn | cxx | Move the definitions of TurboModule virtual methods to declaration, 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
1 parent 87ad1e8 commit 1f87729

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/Android.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
5050

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

53-
LOCAL_SHARED_LIBRARIES = libfb libfbjni libreact_nativemodule_core
53+
LOCAL_SHARED_LIBRARIES = libfb libfbjni libreact_nativemodule_core libjsi
5454

5555
LOCAL_STATIC_LIBRARIES = libcallinvokerholder libreactperfloggerjni
5656

ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp

-23
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,5 @@ TurboModule::TurboModule(
1717
std::shared_ptr<CallInvoker> jsInvoker)
1818
: name_(name), jsInvoker_(jsInvoker) {}
1919

20-
TurboModule::~TurboModule() {}
21-
22-
jsi::Value TurboModule::get(
23-
jsi::Runtime &runtime,
24-
const jsi::PropNameID &propName) {
25-
std::string propNameUtf8 = propName.utf8(runtime);
26-
auto p = methodMap_.find(propNameUtf8);
27-
if (p == methodMap_.end()) {
28-
// Method was not found, let JS decide what to do.
29-
return jsi::Value::undefined();
30-
}
31-
MethodMetadata meta = p->second;
32-
return jsi::Function::createFromHostFunction(
33-
runtime,
34-
propName,
35-
static_cast<unsigned int>(meta.argCount),
36-
[this, meta](
37-
facebook::jsi::Runtime &rt,
38-
const facebook::jsi::Value &thisVal,
39-
const facebook::jsi::Value *args,
40-
size_t count) { return meta.invoker(rt, *this, args, count); });
41-
}
42-
4320
} // namespace react
4421
} // namespace facebook

ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,27 @@ enum TurboModuleMethodValueKind {
3838
class JSI_EXPORT TurboModule : public facebook::jsi::HostObject {
3939
public:
4040
TurboModule(const std::string &name, std::shared_ptr<CallInvoker> jsInvoker);
41-
virtual ~TurboModule();
4241

4342
virtual facebook::jsi::Value get(
4443
facebook::jsi::Runtime &runtime,
45-
const facebook::jsi::PropNameID &propName) override;
44+
const facebook::jsi::PropNameID &propName) override {
45+
std::string propNameUtf8 = propName.utf8(runtime);
46+
auto p = methodMap_.find(propNameUtf8);
47+
if (p == methodMap_.end()) {
48+
// Method was not found, let JS decide what to do.
49+
return jsi::Value::undefined();
50+
}
51+
MethodMetadata meta = p->second;
52+
return jsi::Function::createFromHostFunction(
53+
runtime,
54+
propName,
55+
static_cast<unsigned int>(meta.argCount),
56+
[this, meta](
57+
facebook::jsi::Runtime &rt,
58+
const facebook::jsi::Value &thisVal,
59+
const facebook::jsi::Value *args,
60+
size_t count) { return meta.invoker(rt, *this, args, count); });
61+
}
4662

4763
const std::string name_;
4864
std::shared_ptr<CallInvoker> jsInvoker_;

0 commit comments

Comments
 (0)