MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getValueType

Method getValueType

valdi/src/valdi/hermes/HermesJavaScriptContext.cpp:1028–1072  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1026}
1027
1028ValueType HermesJavaScriptContext::getValueType(const JSValue& value) {
1029 auto* hermesValue = toPinnedHermesValue(value);
1030 if (hermesValue->isUndefined()) {
1031 return ValueType::Undefined;
1032 } else if (hermesValue->isNull()) {
1033 return ValueType::Null;
1034 } else if (hermesValue->isNumber()) {
1035 return ValueType::Double;
1036 } else if (hermesValue->isBool()) {
1037 return ValueType::Bool;
1038 } else if (hermesValue->isString()) {
1039 return ValueType::StaticString;
1040 } else if (hermesValue->isObject()) {
1041 hermes::vm::GCScope gcScope(*_runtime);
1042
1043 if (hermes::vm::vmisa<hermes::vm::Callable>(*hermesValue)) {
1044 return ValueType::Function;
1045 }
1046 if (hermes::vm::vmisa<hermes::vm::JSArray>(*hermesValue)) {
1047 return ValueType::Array;
1048 }
1049 if (hermes::vm::vmisa<hermes::vm::JSArrayBuffer>(*hermesValue) ||
1050 hermes::vm::vmisa<hermes::vm::JSTypedArrayBase>(*hermesValue)) {
1051 return ValueType::TypedArray;
1052 }
1053 if (hermes::vm::vmisa<hermes::vm::JSError>(*hermesValue)) {
1054 return ValueType::Error;
1055 }
1056
1057 auto jsObjectHandle = hermes::vm::Handle<hermes::vm::JSObject>::vmcast(hermesValue);
1058
1059 if (hasNativeState(*_runtime, jsObjectHandle)) {
1060 return ValueType::ValdiObject;
1061 }
1062
1063 if (!getLongConstructor().empty() &&
1064 isInstanceOf(*_runtime, jsObjectHandle, toPinnedHermesValue(getLongConstructor().get()))) {
1065 return Valdi::ValueType::Long;
1066 }
1067
1068 return ValueType::Map;
1069 }
1070
1071 return ValueType::Undefined;
1072}
1073
1074bool HermesJavaScriptContext::isValueUndefined(const JSValue& value) {
1075 return toHermesValue(value).isUndefined();

Callers

nothing calls this directly

Calls 10

hasNativeStateFunction · 0.85
isInstanceOfFunction · 0.85
isBoolMethod · 0.80
getMethod · 0.65
isUndefinedMethod · 0.45
isNullMethod · 0.45
isNumberMethod · 0.45
isStringMethod · 0.45
isObjectMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected