Skip to content

Commit

Permalink
Add util function to determine TurboModuleValueKind (#42271)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Jan 17, 2024
1 parent 6801fc3 commit dd5474f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit dd5474f

Please sign in to comment.