src: migrate WriteOneByte to WriteOneByteV2

PR-URL: https://github.com/nodejs/node/pull/59634
Fixes: https://github.com/nodejs/node/issues/59555
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Chengzhong Wu authored and GitHub committed 2025-08-29 22:41:00 +00:00
1 parent cbabdbf3f2
commit 5af035503a
5 files changed
+137 -36

No files matched your search

+7 -5
View File
@@ -254,11 +254,13 @@ size_t StringBytes::Write(Isolate* isolate,
nbytes = std::min(buflen, static_cast<size_t>(input_view.length()));
memcpy(buf, input_view.data8(), nbytes);
} else {
uint8_t* const dst = reinterpret_cast<uint8_t*>(buf);
const int flags = String::HINT_MANY_WRITES_EXPECTED |
String::NO_NULL_TERMINATION |
String::REPLACE_INVALID_UTF8;
nbytes = str->WriteOneByte(isolate, dst, 0, buflen, flags);
nbytes = std::min(buflen, static_cast<size_t>(input_view.length()));
// Do not use v8::String::WriteOneByteV2 as it asserts the string to be
// a one byte string. For compatibility, convert the uint16_t to uint8_t
// even though this may loose accuracy.
for (size_t i = 0; i < nbytes; i++) {
buf[i] = static_cast<uint8_t>(input_view.data16()[i]);
}
}
break;