Add util function to determine TurboModuleValueKind (#42271)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42271

Changelog: [Internal]

Adds a util function to determine the `TurboModuleMethodValueKind` based on the `jsi:Value` type

Reviewed By: javache

Differential Revision: D52761045

fbshipit-source-id: de937cda67198aad962e63f41ccd42be6c00c0b8
This commit is contained in:
Christoph Purrer
2024-01-17 08:53:58 -08:00
committed by Facebook GitHub Bot
parent 6801fc3f9b
commit dd5474f1e9
2 changed files with 32 additions and 0 deletions
@@ -6,9 +6,34 @@
*/
#include "TurboModule.h"
#include <react/debug/react_native_assert.h>
namespace facebook::react {
TurboModuleMethodValueKind getTurboModuleMethodValueKind(
jsi::Runtime& rt,
const jsi::Value* value) {
if (!value || value->isUndefined() || value->isNull()) {
return VoidKind;
} else if (value->isBool()) {
return BooleanKind;
} else if (value->isNumber()) {
return NumberKind;
} else if (value->isString()) {
return StringKind;
} else if (value->isObject()) {
auto object = value->asObject(rt);
if (object.isArray(rt)) {
return ArrayKind;
} else if (object.isFunction(rt)) {
return FunctionKind;
}
return ObjectKind;
}
react_native_assert(false && "Unsupported jsi::Value kind");
return VoidKind;
}
TurboModule::TurboModule(
std::string name,
std::shared_ptr<CallInvoker> jsInvoker)
@@ -31,6 +31,13 @@ enum TurboModuleMethodValueKind {
PromiseKind,
};
/**
* Determines TurboModuleMethodValueKind based on the jsi::Value type.
*/
TurboModuleMethodValueKind getTurboModuleMethodValueKind(
jsi::Runtime& rt,
const jsi::Value* value);
class TurboCxxModule;
class TurboModuleBinding;