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

Method valueToStaticString

valdi/src/valdi/v8/V8JavaScriptContext.cpp:786–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

784}
785
786Ref<StaticString> V8JavaScriptContext::valueToStaticString(const JSValue& value, JSExceptionTracker& exceptionTracker) {
787 v8::HandleScope handleScope(_isolate);
788 v8::Local<v8::Value> val = fromValdiJSValue(_isolate, value, exceptionTracker);
789 if (!exceptionTracker) {
790 return nullptr;
791 }
792 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context);
793 v8::Local<v8::String> string;
794 if (!val->ToString(context).ToLocal(&string)) {
795 exceptionTracker.onError("Failed to convert value to static string");
796 return nullptr;
797 }
798
799 const int length = string->Utf8Length(_isolate);
800 Ref<StaticString> str = StaticString::makeUTF8(length);
801 string->WriteUtf8(_isolate, str->utf8Data(), length);
802
803 return str;
804}
805
806bool V8JavaScriptContext::valueToBool(const JSValue& value, JSExceptionTracker& exceptionTracker) {
807 v8::HandleScope handleScope(_isolate);

Callers 4

runtimeOutputLogMethod · 0.45
valueToStringMethod · 0.45

Calls 5

ToLocalMethod · 0.80
utf8DataMethod · 0.80
fromValdiJSValueFunction · 0.70
onErrorMethod · 0.65
NewFunction · 0.50

Tested by

no test coverage detected