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

Function onObjectBegin

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:1071–1116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1069 if (!checkCall(exceptionTracker, cString == nullptr ? -1 : 0)) {
1070 return Valdi::StringBox();
1071 }
1072
1073 auto str = Valdi::StringCache::getGlobal().makeString(cString, len);
1074 JS_FreeCString(_context, cString);
1075
1076 return str;
1077}
1078
1079Valdi::Ref<Valdi::StaticString> QuickJSJavaScriptContext::valueToStaticString(
1080 const Valdi::JSValue& value, Valdi::JSExceptionTracker& exceptionTracker) {
1081 auto guard = _threadAccessChecker.guard();
1082 size_t len = 0;
1083 const auto* cString = JS_ToCStringLen(_context, &len, fromValdiJSValue(value));
1084 if (!checkCall(exceptionTracker, cString == nullptr ? -1 : 0)) {
1085 return nullptr;
1086 }
1087
1088 auto str = Valdi::StaticString::makeUTF8(cString, len);
1089 JS_FreeCString(_context, cString);
1090
1091 return str;
1092}
1093
1094bool QuickJSJavaScriptContext::valueToBool(const Valdi::JSValue& value, Valdi::JSExceptionTracker& exceptionTracker) {
1095 auto guard = _threadAccessChecker.guard();
1096 // JS_ToBool returns -1 for exceptions *and* coerces non-zero numbers and non-empty strings to true
1097 auto result = JS_ToBool(_context, fromValdiJSValue(value));
1098
1099 if (!checkCall(exceptionTracker, result)) {
1100 return false;
1101 }
1102
1103 return static_cast<bool>(result != 0);
1104}
1105
1106double QuickJSJavaScriptContext::valueToDouble(const Valdi::JSValue& value,
1107 Valdi::JSExceptionTracker& exceptionTracker) {
1108 auto guard = _threadAccessChecker.guard();
1109 double number = 0;
1110
1111 if (!checkCall(exceptionTracker, JS_ToFloat64(_context, &number, fromValdiJSValue(value)))) {
1112 return 0;
1113 }
1114
1115 return number;
1116}
1117
1118int32_t QuickJSJavaScriptContext::valueToInt(const Valdi::JSValue& value, Valdi::JSExceptionTracker& exceptionTracker) {
1119 auto guard = _threadAccessChecker.guard();

Callers

nothing calls this directly

Calls 4

getHeapDumpBuilderFunction · 0.85
getGlobalFunction · 0.85
makeStringMethod · 0.80
beginNodeMethod · 0.80

Tested by

no test coverage detected