src: refactor WriteUCS2 and remove flags argument #58163
+23
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change refactors
StringBytes::WriteUCS2()
in multiple ways.The
flags
argument being passed toWriteUCS2()
is not useful: the only really relevant flag isNO_NULL_TERMINATION
since V8 ignoresREPLACE_INVALID_UTF8
,HINT_MANY_WRITES_EXPECTED
, andPRESERVE_ONE_BYTE_NULL
for UTF-16 strings. However,WriteUCS2()
might not null-terminate the result correctly regardless of whetherNO_NULL_TERMINATION
is set because it makes multiple calls toString::Write()
internally. For these reasons, this patch removes theflags
argument entirely and always assumesNO_NULL_TERMINATION
.Next, this patch replaces the calls to the deprecated function
String::Write()
with calls to the new functionString::WriteV2()
, which always succeeds and always writes a predictable number of characters, removing the need to deal with a return value here.Lastly, this patch simplifies the implementation of
WriteUCS2()
and computes the exact number of charactersnchars
from the beginning, removing the need to later check again if the number of characters is zero.