Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 22 additions & 32 deletions lib/web/webidl/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { types, inspect, toUSVString } = require('node:util')
const { types, inspect } = require('node:util')
const { markAsUncloneable } = require('node:worker_threads')

const UNDEFINED = 1
Expand Down Expand Up @@ -495,21 +495,16 @@ webidl.nullableConverter = function (converter) {
}
}

webidl.is.USVString = (() => {
if (typeof String.prototype.isWellFormed === 'function') {
/**
* @param {*} value
* @returns {boolean}
*/
return (value) => typeof value === 'string' && value.isWellFormed()
} else {
/**
* @param {*} value
* @returns {boolean}
*/
return (value) => typeof value === 'string' && value === toUSVString(value)
}
})()
/**
* @param {*} value
* @returns {boolean}
*/
webidl.is.USVString = function (value) {
return (
typeof value === 'string' &&
value.isWellFormed()
)
}

webidl.is.ReadableStream = webidl.util.MakeTypeAssertion(ReadableStream)
webidl.is.Blob = webidl.util.MakeTypeAssertion(Blob)
Expand Down Expand Up @@ -572,23 +567,18 @@ webidl.converters.ByteString = function (V, prefix, argument) {
return x
}

// https://webidl.spec.whatwg.org/#es-USVString
// TODO: rewrite this so we can control the errors thrown
webidl.converters.USVString = (() => {
if (typeof String.prototype.toWellFormed === 'function') {
/**
* @param {string} value
* @returns {string}
*/
return (value) => `${value}`.toWellFormed()
} else {
/**
* @param {string} value
* @returns {string}
*/
return toUSVString
/**
* @param {unknown} value
* @returns {string}
* @see https://webidl.spec.whatwg.org/#es-USVString
*/
webidl.converters.USVString = function (value) {
// TODO: rewrite this so we can control the errors thrown
if (typeof value === 'string') {
return value.toWellFormed()
}
})()
return `${value}`.toWellFormed()
}

// https://webidl.spec.whatwg.org/#es-boolean
webidl.converters.boolean = function (V) {
Expand Down
Loading