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 double retval;
940 if (!val->NumberValue(context).To(&retval)) {
941 exceptionTracker.onError("Value could not be converted");
942 return 0;
943 }
944 return retval;
945}
946
947int32_t V8JavaScriptContext::valueToInt(const JSValue& value, JSExceptionTracker& exceptionTracker) {
948 v8::HandleScope handleScope(_isolate);
949
950 auto val = fromValdiJSValue(_isolate, value, exceptionTracker);
951 if (!exceptionTracker) {
952 return 0;
953 }
954
955 if (!val->IsInt32()) {
956 exceptionTracker.onError("Value is not an int32 type and cannot be converted");
957 return 0;
958 }
959
960 return val.As<v8::Int32>()->Value();
961}
962
963Ref<RefCountable> V8JavaScriptContext::valueToWrappedObject(const JSValue& value,
964 JSExceptionTracker& exceptionTracker) {
965 v8::HandleScope handleScope(_isolate);
966 auto indirect = fromValdiJSValueToIndirect(value);
967 auto objectInfo = indirect.getWithWrapperID(_isolate);
968 auto val = v8::Local<v8::Object>::Cast(objectInfo.first);
969
970 if (indirect.isEmpty()) {
971 exceptionTracker.onError("Provided js value is already been cleared");
972 return Ref<RefCountable>();
973 } else if (!val->IsObject()) {
974 exceptionTracker.onError("Provided js value is not object");
975 return Ref<RefCountable>();
976 } else if (objectInfo.second != kWrappedObjectID) {
977 exceptionTracker.onError("Provided js value is not a wrapped object");
978 return Ref<RefCountable>();
979 }
980
981 SC_ASSERT(val->InternalFieldCount() == static_cast<int>(InternalFieldSlot::Count));
982 auto external = v8::Local<v8::External>::Cast(val->GetInternalField(static_cast<int>(InternalFieldSlot::DataSlot)));
983 if (!external->IsExternal()) {
984 exceptionTracker.onError("Internal field value is not of type external");
985 }
986
987 return unsafeBridge<RefCountable>(external->Value());
988}
989
990JSTypedArray V8JavaScriptContext::valueToTypedArray(const JSValue& value, JSExceptionTracker& exceptionTracker) {
991 v8::HandleScope handleScope(_isolate);
992
993 v8::Local<v8::Value> val = fromValdiJSValue(_isolate, value, exceptionTracker);
994 if (!val->IsTypedArray()) {
995 exceptionTracker.onError("Value is not TypedArray");
996 return JSTypedArray();

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