diff --git a/lib/core/util.js b/lib/core/util.js index 3939f0d25e5..bfee97946cd 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -409,6 +409,21 @@ function throwIfAborted (signal) { } } +const hasToWellFormed = !!String.prototype.toWellFormed + +/** + * @param {string} val + */ +function toUSVString (val) { + if (hasToWellFormed) { + return `${val}`.toWellFormed() + } else if (nodeUtil.toUSVString) { + return nodeUtil.toUSVString(val) + } + + return `${val}` +} + const kEnumerableProperty = Object.create(null) kEnumerableProperty.enumerable = true @@ -418,7 +433,7 @@ module.exports = { isDisturbed, isErrored, isReadable, - toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), + toUSVString, isReadableAborted, isBlobLike, parseOrigin,