summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/node/polyfills/util.ts10
-rw-r--r--ext/webidl/00_webidl.js26
2 files changed, 12 insertions, 24 deletions
diff --git a/ext/node/polyfills/util.ts b/ext/node/polyfills/util.ts
index 1b611b1fd..2e25746ef 100644
--- a/ext/node/polyfills/util.ts
+++ b/ext/node/polyfills/util.ts
@@ -37,7 +37,9 @@ const {
SafeSet,
SetPrototypeAdd,
SetPrototypeHas,
+ StringPrototypeIsWellFormed,
StringPrototypePadStart,
+ StringPrototypeToWellFormed,
} = primordials;
export {
@@ -187,6 +189,13 @@ export const TextDecoder = _TextDecoder;
export type TextEncoder = import("./_utils.ts")._TextEncoder;
export const TextEncoder = _TextEncoder;
+export function toUSVString(str: string): string {
+ if (StringPrototypeIsWellFormed(str)) {
+ return str;
+ }
+ return StringPrototypeToWellFormed(str);
+}
+
function pad(n: number) {
return StringPrototypePadStart(NumberPrototypeToString(n), 2, "0");
}
@@ -309,6 +318,7 @@ export default {
stripVTControlCharacters,
TextDecoder,
TextEncoder,
+ toUSVString,
log,
debuglog,
isDeepStrictEqual,
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) => {