Skip to content

Commit 549e7ed

Browse files
authoredApr 1, 2023
util: replace util.toUSVString with String.prototype.toWellFormed (#2036)
1 parent 7ae1779 commit 549e7ed

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎lib/core/util.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,21 @@ function throwIfAborted (signal) {
409409
}
410410
}
411411

412+
const hasToWellFormed = !!String.prototype.toWellFormed
413+
414+
/**
415+
* @param {string} val
416+
*/
417+
function toUSVString (val) {
418+
if (hasToWellFormed) {
419+
return `${val}`.toWellFormed()
420+
} else if (nodeUtil.toUSVString) {
421+
return nodeUtil.toUSVString(val)
422+
}
423+
424+
return `${val}`
425+
}
426+
412427
const kEnumerableProperty = Object.create(null)
413428
kEnumerableProperty.enumerable = true
414429

@@ -418,7 +433,7 @@ module.exports = {
418433
isDisturbed,
419434
isErrored,
420435
isReadable,
421-
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`),
436+
toUSVString,
422437
isReadableAborted,
423438
isBlobLike,
424439
parseOrigin,

0 commit comments

Comments
 (0)
Please sign in to comment.