You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: make V8 string to NSString conversions UTF-16 faithful (#392)
* Make V8 string to NSString conversions UTF-16 faithful
V8 strings are UTF-16, but several bridge points round-tripped them through
UTF-8 before building an NSString (and one reverse direction did too). That
path corrupts lone surrogates, which get replaced with U+FFFD, and where it
used C-string APIs (stringWithUTF8String:, [NSString UTF8String] folded into
a std::string) it truncated at an embedded NUL.
Rework tns::ToUtf16String to read the V8 string's native two-byte buffer
directly, which also drops the deprecated std::codecvt_utf8_utf16. Switch the
DictionaryAdapter, Interop and ArgConverter string sites to ToUtf16String +
stringWithCharacters:length:, and pass NSString straight to ToV8String instead
of going through a UTF8String C string.
Add TestRunner cases asserting lone surrogates survive the JS to NSString
bridge: each reads the bridged string's first UTF-16 code unit straight out of
its buffer and checks it is unchanged (high U+D834 and low U+DC00), whereas the
old UTF-8 round trip would have turned either into U+FFFD.
* Routed JS-to-NSString bridge through a UTF-16-faithful ToNSString
Made tns::ToNSString read the V8 string's UTF-16 buffer directly and pointed the six bridge sites at it, instead of building a std::u16string and copying it into NSString at each one. That drops the extra copy and the repeated stringWithCharacters boilerplate, keeps the conversion in one place, and brings Interop back to matching vanilla.
Kept the ToUtf16String rewrite as the general accessor. Added an embedded-NUL test next to the lone-surrogate ones, since the bridge now has to preserve NUL bytes too.
0 commit comments