mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Warn whenever CxxNativeModules are used
Summary: After this diff, when ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse is enabled, the legacy NativeModule infra will log soft exceptions whenever legacy NativeModules are accessed/used. Changelog: [Internal] Reviewed By: p-sun Differential Revision: D30272695 fbshipit-source-id: 7111402c1d8b883a600dcb4559e9ff1d56447070
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b7fd68e611
commit
f536f82e12
@@ -54,6 +54,12 @@ CxxModule::Callback convertCallback(
|
||||
|
||||
} // namespace
|
||||
|
||||
WarnOnUsageLogger CxxNativeModule::warnOnUsageLogger_ = nullptr;
|
||||
|
||||
void CxxNativeModule::setWarnOnUsageLogger(WarnOnUsageLogger logger) {
|
||||
warnOnUsageLogger_ = logger;
|
||||
}
|
||||
|
||||
std::string CxxNativeModule::getName() {
|
||||
return name_;
|
||||
}
|
||||
@@ -87,6 +93,12 @@ folly::dynamic CxxNativeModule::getConstants() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (warnOnUsageLogger_) {
|
||||
warnOnUsageLogger_(
|
||||
"Calling getConstants() on Cxx NativeModule (name = \"" + getName() +
|
||||
"\").");
|
||||
}
|
||||
|
||||
folly::dynamic constants = folly::dynamic::object();
|
||||
for (auto &pair : module_->getConstants()) {
|
||||
constants.insert(std::move(pair.first), std::move(pair.second));
|
||||
@@ -121,6 +133,12 @@ void CxxNativeModule::invoke(
|
||||
"Method ", method.name, " is synchronous but invoked asynchronously"));
|
||||
}
|
||||
|
||||
if (warnOnUsageLogger_) {
|
||||
warnOnUsageLogger_(
|
||||
"Calling " + method.name + "() on Cxx NativeModule (name = \"" +
|
||||
getName() + "\").");
|
||||
}
|
||||
|
||||
if (params.size() < method.callbacks) {
|
||||
throw std::invalid_argument(folly::to<std::string>(
|
||||
"Expected ",
|
||||
@@ -204,6 +222,12 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook(
|
||||
"Method ", method.name, " is asynchronous but invoked synchronously"));
|
||||
}
|
||||
|
||||
if (warnOnUsageLogger_) {
|
||||
warnOnUsageLogger_(
|
||||
"Calling " + method.name + "() on Cxx NativeModule (name = \"" +
|
||||
getName() + "\").");
|
||||
}
|
||||
|
||||
return method.syncFunc(std::move(args));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user