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

Method valueToString

valdi/src/valdi/v8/V8JavaScriptContext.cpp:764–784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764StringBox V8JavaScriptContext::valueToString(const JSValue& value, JSExceptionTracker& exceptionTracker) {
765 v8::HandleScope handleScope(_isolate);
766 v8::Local<v8::Value> val = fromValdiJSValue(_isolate, value, exceptionTracker);
767 if (!exceptionTracker) {
768 return StringBox();
769 }
770 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context);
771 v8::Local<v8::String> string;
772 if (!val->ToString(context).ToLocal(&string)) {
773 exceptionTracker.onError("Failed to convert value to string");
774 return StringBox();
775 }
776
777 // TODO: we probably should use WriteUtf8 method instead
778 v8::String::Utf8Value stringValue(_isolate, string);
779
780 auto stringData = *stringValue;
781 auto stringLength = stringValue.length();
782
783 return StringCache::getGlobal().makeString(stringData, stringLength);
784}
785
786Ref<StaticString> V8JavaScriptContext::valueToStaticString(const JSValue& value, JSExceptionTracker& exceptionTracker) {
787 v8::HandleScope handleScope(_isolate);

Callers

nothing calls this directly

Calls 8

getGlobalFunction · 0.85
ToLocalMethod · 0.80
makeStringMethod · 0.80
fromValdiJSValueFunction · 0.70
onErrorMethod · 0.65
StringBoxClass · 0.50
NewFunction · 0.50
lengthMethod · 0.45

Tested by

no test coverage detected