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

Function jsValueToValue

valdi/src/valdi/runtime/JavaScript/JavaScriptUtils.cpp:722–768  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

720 auto valdiObject = jsWrappedObjectToValdiObject(jsContext, jsValue, exceptionTracker);
721 if (!exceptionTracker) {
722 return Value::undefined();
723 }
724
725 return Value(valdiObject);
726}
727
728Value jsErrorToValue(IJavaScriptContext& jsContext, const JSValue& jsValue, JSExceptionTracker& /*exceptionTracker*/) {
729 return Value(convertJSErrorToValdiError(jsContext, JSValueRef::makeRetained(jsContext, jsValue), nullptr));
730}
731
732Value jsValueToValue(IJavaScriptContext& jsContext,
733 const JSValue& jsValue,
734 const ReferenceInfoBuilder& referenceInfoBuilder,
735 JSExceptionTracker& exceptionTracker) {
736 Valdi::JavaScriptRef<JSValue> ref;
737
738 if (!checkRefNotCircular(jsValue, exceptionTracker.getCircularRefChecker(), ref)) {
739 static auto kCircular = STRING_LITERAL("<circular>");
740 return Valdi::Value(kCircular);
741 }
742
743 switch (jsContext.getValueType(jsValue)) {
744 case Valdi::ValueType::Null:
745 return Valdi::Value();
746 case Valdi::ValueType::Undefined:
747 return Valdi::Value::undefined();
748 case Valdi::ValueType::InternedString:
749 case Valdi::ValueType::StaticString:
750 // We always use the interned string API when going from an untyped JSValue to a Value
751 return Value(jsContext.valueToString(jsValue, exceptionTracker));
752 case Valdi::ValueType::Int:
753 return Value(jsContext.valueToInt(jsValue, exceptionTracker));
754 case Valdi::ValueType::Double:
755 return Value(jsContext.valueToDouble(jsValue, exceptionTracker));
756 case Valdi::ValueType::Long:
757 return Value(jsContext.valueToLong(jsValue, exceptionTracker).toInt64());
758 case Valdi::ValueType::Bool:
759 return Value(jsContext.valueToBool(jsValue, exceptionTracker));
760 case Valdi::ValueType::Map:
761 return jsObjectToValue(jsContext, jsValue, referenceInfoBuilder, exceptionTracker);
762 case Valdi::ValueType::Array:
763 return jsArrayToValue(jsContext, jsValue, referenceInfoBuilder, exceptionTracker);
764 case Valdi::ValueType::TypedArray:
765 return jsTypedArrayToValue(jsContext, jsValue, referenceInfoBuilder, exceptionTracker);
766 case Valdi::ValueType::Function:
767 return Value(jsFunctionToFunction(
768 jsContext, jsValue, referenceInfoBuilder, exceptionTracker, defaultJSValueFunctionFactory()));
769 case Valdi::ValueType::TypedObject:
770 std::abort();
771 case Valdi::ValueType::ProxyTypedObject:

Callers 15

TEST_PFunction · 0.85
withContextRetMethod · 0.85
dumpMemoryStatisticsMethod · 0.85
pushToMarshallerMethod · 0.85
doCallMethod · 0.85
getParameterAsValueMethod · 0.85
visitPropertyNameMethod · 0.85
jsArrayToValueFunction · 0.85
isJsModuleLoadedMethod · 0.85
onModulesUnloadedMethod · 0.85

Calls 15

checkRefNotCircularFunction · 0.85
jsObjectToValueFunction · 0.85
jsArrayToValueFunction · 0.85
jsTypedArrayToValueFunction · 0.85
jsFunctionToFunctionFunction · 0.85
jsWrappedObjectToValueFunction · 0.85
jsErrorToValueFunction · 0.85
toInt64Method · 0.80
valueToStringMethod · 0.65
ValueClass · 0.50
getValueTypeMethod · 0.45

Tested by 3

TEST_PFunction · 0.68
withContextRetMethod · 0.68