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

Method newStringUTF8

valdi/src/valdi/jscore/JavaScriptCoreContext.cpp:374–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372Valdi::JSValueRef JavaScriptCoreContext::onNewBool(bool boolean) {
373 return returnJSValueRef(JSValueMakeBoolean(getJSGlobalContext(), boolean), kJSTypeBoolean);
374}
375
376Valdi::JSValueRef JavaScriptCoreContext::onNewNumber(int32_t number) {
377 return onNewNumber(static_cast<double>(number));
378}
379
380Valdi::JSValueRef JavaScriptCoreContext::onNewNumber(double number) {
381 auto context = getJSGlobalContext();
382 return returnJSValueRef(JSValueMakeNumber(context, number), kJSTypeNumber);
383}
384
385Valdi::JSValueRef JavaScriptCoreContext::newStringUTF8(const std::string_view& str,
386 Valdi::JSExceptionTracker& exceptionTracker) {
387 // JSStringCreateWithUTF8CString (used by newPropertyName) internally calls strlen(),
388 // truncating strings with embedded null bytes. Use JSStringCreateWithCharacters instead,
389 // which takes an explicit length. JSCore uses UTF-16 internally, so both paths do the
390 // same conversion — this one just handles null bytes correctly.
391 auto utf16 = Valdi::utf8ToUtf16(str.data(), str.size());

Callers

nothing calls this directly

Calls 6

utf8ToUtf16Function · 0.85
toValdiJSPropertyNameFunction · 0.70
fromValdiJSPropertyNameFunction · 0.70
getMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected