Skip to content

Commit

Permalink
refactor(ext/web): Don't rely on NaN comparisons in `TextEncoderStrea…
Browse files Browse the repository at this point in the history
…m` (#13151)

In the `transform` function to `TextEncoderStream`'s internal
`TransformStream`, if `chunk` is the empty string and
`this.#pendingHighSurrogate` is null, then `lastCodeUnit` will be NaN.
As it turns out, this does not cause a bug because the comparison to
check for lone surrogates turns out to be false for NaN, but to rely on
it makes the code brittle.
  • Loading branch information
Andreu Botella authored and bartlomieju committed Jan 5, 2022
1 parent 0721ee5 commit 49ccfdd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/web/08_text_encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@
transform: (chunk, controller) => {
try {
chunk = webidl.converters.DOMString(chunk);
if (chunk === "") {
return PromiseResolve();
}
if (this.#pendingHighSurrogate !== null) {
chunk = this.#pendingHighSurrogate + chunk;
}
Expand Down

0 comments on commit 49ccfdd

Please sign in to comment.