diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2023-11-07 06:18:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 22:18:28 +0100 |
commit | 90189dd9974be01596ec776e63a4eceef1a036e0 (patch) | |
tree | 5ef3171dfc4181e1682d86ccd4daa5c874bc261a /ext/webidl/00_webidl.js | |
parent | 7eb34c7a36ac065d169e3645fc8a3da3e71431d7 (diff) |
fix(ext): use `String#toWellFormed` in ext/webidl and ext/node (#21054)
Fixes #18802
This PR adds `util.toUSVString` to node:util:
```js
import util from "node:util";
util.toUSVString("string\ud801"); // => "string\ufffd"
```
Diffstat (limited to 'ext/webidl/00_webidl.js')
-rw-r--r-- | ext/webidl/00_webidl.js | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index c3b00286f..956def267 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -70,8 +70,8 @@ const { // TODO(lucacasonato): add SharedArrayBuffer to primordials // SharedArrayBufferPrototype String, - StringFromCodePoint, StringPrototypeCharCodeAt, + StringPrototypeToWellFormed, Symbol, SymbolIterator, SymbolToStringTag, @@ -425,29 +425,7 @@ converters.ByteString = (V, prefix, context, opts) => { converters.USVString = (V, prefix, context, opts) => { const S = converters.DOMString(V, prefix, context, opts); - const n = S.length; - let U = ""; - for (let i = 0; i < n; ++i) { - const c = StringPrototypeCharCodeAt(S, i); - if (c < 0xd800 || c > 0xdfff) { - U += StringFromCodePoint(c); - } else if (0xdc00 <= c && c <= 0xdfff) { - U += StringFromCodePoint(0xfffd); - } else if (i === n - 1) { - U += StringFromCodePoint(0xfffd); - } else { - const d = StringPrototypeCharCodeAt(S, i + 1); - if (0xdc00 <= d && d <= 0xdfff) { - const a = c & 0x3ff; - const b = d & 0x3ff; - U += StringFromCodePoint((2 << 15) + (2 << 9) * a + b); - ++i; - } else { - U += StringFromCodePoint(0xfffd); - } - } - } - return U; + return StringPrototypeToWellFormed(S); }; converters.object = (V, prefix, context, _opts) => { |