mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
6801fc3f9b
commit
dd5474f1e9
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user