Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webidl changes #3175

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
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
65 changes: 39 additions & 26 deletions lib/web/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class Cache {

async match (request, options = {}) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.match' })

request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.match'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

const p = this.#internalMatchAll(request, options, 1)

Expand All @@ -59,17 +61,20 @@ class Cache {
async matchAll (request = undefined, options = {}) {
webidl.brandCheck(this, Cache)

if (request !== undefined) request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.matchAll'
if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

return this.#internalMatchAll(request, options)
}

async add (request) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.add' })

request = webidl.converters.RequestInfo(request)
const prefix = 'Cache.add'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')

// 1.
const requests = [request]
Expand All @@ -83,7 +88,9 @@ class Cache {

async addAll (requests) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })

const prefix = 'Cache.addAll'
webidl.argumentLengthCheck(arguments, 1, prefix)

// 1.
const responsePromises = []
Expand All @@ -95,7 +102,7 @@ class Cache {
for (let request of requests) {
if (request === undefined) {
throw webidl.errors.conversionFailed({
prefix: 'Cache.addAll',
prefix,
argument: 'Argument 1',
types: ['undefined is not allowed']
})
Expand All @@ -113,7 +120,7 @@ class Cache {
// 3.2
if (!urlIsHttpHttpsScheme(r.url) || r.method !== 'GET') {
throw webidl.errors.exception({
header: 'Cache.addAll',
header: prefix,
message: 'Expected http/s scheme when method is not GET.'
})
}
Expand All @@ -131,7 +138,7 @@ class Cache {
// 5.2
if (!urlIsHttpHttpsScheme(r.url)) {
throw webidl.errors.exception({
header: 'Cache.addAll',
header: prefix,
message: 'Expected http/s scheme.'
})
}
Expand Down Expand Up @@ -251,10 +258,12 @@ class Cache {

async put (request, response) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 2, { header: 'Cache.put' })

request = webidl.converters.RequestInfo(request)
response = webidl.converters.Response(response)
const prefix = 'Cache.put'
webidl.argumentLengthCheck(arguments, 2, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
response = webidl.converters.Response(response, prefix, 'response')

// 1.
let innerRequest = null
Expand All @@ -269,7 +278,7 @@ class Cache {
// 4.
if (!urlIsHttpHttpsScheme(innerRequest.url) || innerRequest.method !== 'GET') {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Expected an http/s scheme when method is not GET'
})
}
Expand All @@ -280,7 +289,7 @@ class Cache {
// 6.
if (innerResponse.status === 206) {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Got 206 status'
})
}
Expand All @@ -295,7 +304,7 @@ class Cache {
// 7.2.1
if (fieldValue === '*') {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Got * vary field value'
})
}
Expand All @@ -305,7 +314,7 @@ class Cache {
// 8.
if (innerResponse.body && (isDisturbed(innerResponse.body.stream) || innerResponse.body.stream.locked)) {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Response body is locked or disturbed'
})
}
Expand Down Expand Up @@ -380,10 +389,12 @@ class Cache {

async delete (request, options = {}) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.delete' })

request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.delete'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

/**
* @type {Request}
Expand Down Expand Up @@ -445,8 +456,10 @@ class Cache {
async keys (request = undefined, options = {}) {
webidl.brandCheck(this, Cache)

if (request !== undefined) request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.keys'

if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

// 1.
let r = null
Expand Down Expand Up @@ -810,17 +823,17 @@ const cacheQueryOptionConverters = [
{
key: 'ignoreSearch',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreMethod',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreVary',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
}
]

Expand Down
20 changes: 13 additions & 7 deletions lib/web/cache/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CacheStorage {

async match (request, options = {}) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.match' })
webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match')

request = webidl.converters.RequestInfo(request)
options = webidl.converters.MultiCacheQueryOptions(options)
Expand Down Expand Up @@ -57,9 +57,11 @@ class CacheStorage {
*/
async has (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.has' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.has'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

// 2.1.1
// 2.2
Expand All @@ -73,9 +75,11 @@ class CacheStorage {
*/
async open (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.open' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.open'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

// 2.1
if (this.#caches.has(cacheName)) {
Expand Down Expand Up @@ -105,9 +109,11 @@ class CacheStorage {
*/
async delete (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.delete' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.delete'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

return this.#caches.delete(cacheName)
}
Expand Down
31 changes: 16 additions & 15 deletions lib/web/cookies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { Headers } = require('../fetch/headers')
* @returns {Record<string, string>}
*/
function getCookies (headers) {
webidl.argumentLengthCheck(arguments, 1, { header: 'getCookies' })
webidl.argumentLengthCheck(arguments, 1, 'getCookies')

webidl.brandCheck(headers, Headers, { strict: false })

Expand All @@ -51,11 +51,12 @@ function getCookies (headers) {
* @returns {void}
*/
function deleteCookie (headers, name, attributes) {
webidl.argumentLengthCheck(arguments, 2, { header: 'deleteCookie' })

webidl.brandCheck(headers, Headers, { strict: false })

name = webidl.converters.DOMString(name)
const prefix = 'deleteCookie'
webidl.argumentLengthCheck(arguments, 2, prefix)

name = webidl.converters.DOMString(name, prefix, 'name')
attributes = webidl.converters.DeleteCookieAttributes(attributes)

// Matches behavior of
Expand All @@ -73,7 +74,7 @@ function deleteCookie (headers, name, attributes) {
* @returns {Cookie[]}
*/
function getSetCookies (headers) {
webidl.argumentLengthCheck(arguments, 1, { header: 'getSetCookies' })
webidl.argumentLengthCheck(arguments, 1, 'getSetCookies')

webidl.brandCheck(headers, Headers, { strict: false })

Expand All @@ -93,7 +94,7 @@ function getSetCookies (headers) {
* @returns {void}
*/
function setCookie (headers, cookie) {
webidl.argumentLengthCheck(arguments, 2, { header: 'setCookie' })
webidl.argumentLengthCheck(arguments, 2, 'setCookie')

webidl.brandCheck(headers, Headers, { strict: false })

Expand All @@ -110,12 +111,12 @@ webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'path',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'domain',
defaultValue: null
defaultValue: () => null
}
])

Expand All @@ -137,32 +138,32 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
return new Date(value)
}),
key: 'expires',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters['long long']),
key: 'maxAge',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'domain',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.DOMString),
key: 'path',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.boolean),
key: 'secure',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.nullableConverter(webidl.converters.boolean),
key: 'httpOnly',
defaultValue: null
defaultValue: () => null
},
{
converter: webidl.converters.USVString,
Expand All @@ -172,7 +173,7 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
{
converter: webidl.sequenceConverter(webidl.converters.DOMString),
key: 'unparsed',
defaultValue: []
defaultValue: () => new Array(0)
}
])

Expand Down
9 changes: 5 additions & 4 deletions lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class EventSource extends EventTarget {
// 1. Let ev be a new EventSource object.
super()

webidl.argumentLengthCheck(arguments, 1, { header: 'EventSource constructor' })
const prefix = 'EventSource constructor'
webidl.argumentLengthCheck(arguments, 1, prefix)

if (!experimentalWarned) {
experimentalWarned = true
Expand All @@ -114,8 +115,8 @@ class EventSource extends EventTarget {
})
}

url = webidl.converters.USVString(url)
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict)
url = webidl.converters.USVString(url, prefix, 'url')
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')

this.#dispatcher = eventSourceInitDict.dispatcher
this.#state = {
Expand Down Expand Up @@ -463,7 +464,7 @@ webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
{
key: 'withCredentials',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'dispatcher', // undici only
Expand Down
Loading
Loading