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

Method getValueType

valdi/src/valdi/v8/V8JavaScriptContext.cpp:940–993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

938}
939
940ValueType V8JavaScriptContext::getValueType(const JSValue& value) {
941 v8::HandleScope handleScope(_isolate);
942
943 auto indirect = fromValdiJSValueToIndirect(value);
944 auto objectInfo = indirect.getWithWrapperID(_isolate);
945
946 auto val = objectInfo.first;
947 auto classID = objectInfo.second;
948
949 if (val.IsEmpty()) {
950 return ValueType::Undefined;
951 }
952
953 if (val->IsUndefined()) {
954 return ValueType::Undefined;
955 }
956 if (val->IsNull()) {
957 return ValueType::Null;
958 }
959 if (val->IsString() || val->IsStringObject()) {
960 return ValueType::StaticString;
961 }
962 if (val->IsNumber() || val->IsNumberObject()) {
963 return ValueType::Double;
964 }
965 if (val->IsBoolean() || val->IsBoolean()) {
966 return ValueType::Bool;
967 }
968 if (val->IsArray()) {
969 return ValueType::Array;
970 }
971 if (val->IsObject() && classID == kWrappedObjectID) {
972 return ValueType::ValdiObject;
973 }
974 if (val->IsFunction()) {
975 return ValueType::Function;
976 }
977 if (val->IsTypedArray() || val->IsArrayBuffer() || val->IsArrayBufferView()) {
978 return ValueType::TypedArray;
979 }
980 if (val->IsNativeError()) { // TODO(rjaber): Check that native error is semantically the as other VMs
981 return ValueType::Error;
982 }
983 if (val->IsSymbol() || val->IsSymbolObject() || val->IsAsyncFunction()) {
984 // Symbols are opaque types that we don't support exporting
985 return ValueType::Undefined;
986 }
987 // IMPL(rjaber): Implement a wrapper valdi object
988 // if () {
989 // return ValueType::Long;
990 // }
991
992 return ValueType::Map;
993}
994
995bool V8JavaScriptContext::isValueUndefined(const JSValue& value) {
996 v8::HandleScope handleScope(_isolate);

Callers 2

throwInvalidTypeFunction · 0.45
jsValueToValueFunction · 0.45

Calls 6

getWithWrapperIDMethod · 0.80
IsUndefinedMethod · 0.80
IsNullMethod · 0.80
IsStringMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected