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 1 commit
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
Prev Previous commit
add context to individual webidl converter calls
  • Loading branch information
KhafraDev committed Apr 28, 2024
commit 681cf77f9c2cdf7a2667e74a98b8dc09578155f8
59 changes: 36 additions & 23 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, '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, '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, '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, '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, '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
18 changes: 12 additions & 6 deletions lib/web/cache/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ class CacheStorage {
*/
async has (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, '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, '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, '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
7 changes: 4 additions & 3 deletions lib/web/cookies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ function getCookies (headers) {
* @returns {void}
*/
function deleteCookie (headers, name, attributes) {
webidl.argumentLengthCheck(arguments, 2, '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 Down
7 changes: 4 additions & 3 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, '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
42 changes: 24 additions & 18 deletions lib/web/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FormData {
append (name, value, filename = undefined) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 2, 'FormData.append')
const prefix = 'FormData.append'
webidl.argumentLengthCheck(arguments, 2, prefix)

if (arguments.length === 3 && !isBlobLike(value)) {
throw new TypeError(
Expand All @@ -38,12 +39,12 @@ class FormData {

// 1. Let value be value if given; otherwise blobValue.

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')
value = isBlobLike(value)
? webidl.converters.Blob(value, { strict: false })
: webidl.converters.USVString(value)
? webidl.converters.Blob(value, prefix, 'value', { strict: false })
: webidl.converters.USVString(value, prefix, 'value')
filename = arguments.length === 3
? webidl.converters.USVString(filename)
? webidl.converters.USVString(filename, prefix, 'filename')
: undefined

// 2. Let entry be the result of creating an entry with
Expand All @@ -57,9 +58,10 @@ class FormData {
delete (name) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 1, 'FormData.delete')
const prefix = 'FormData.delete'
webidl.argumentLengthCheck(arguments, 1, prefix)

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')

// The delete(name) method steps are to remove all entries whose name
// is name from this’s entry list.
Expand All @@ -69,9 +71,10 @@ class FormData {
get (name) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 1, 'FormData.get')
const prefix = 'FormData.get'
webidl.argumentLengthCheck(arguments, 1, prefix)

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')

// 1. If there is no entry whose name is name in this’s entry list,
// then return null.
Expand All @@ -88,9 +91,10 @@ class FormData {
getAll (name) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 1, 'FormData.getAll')
const prefix = 'FormData.getAll'
webidl.argumentLengthCheck(arguments, 1, prefix)

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')

// 1. If there is no entry whose name is name in this’s entry list,
// then return the empty list.
Expand All @@ -104,9 +108,10 @@ class FormData {
has (name) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 1, 'FormData.has')
const prefix = 'FormData.has'
webidl.argumentLengthCheck(arguments, 1, prefix)

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')

// The has(name) method steps are to return true if there is an entry
// whose name is name in this’s entry list; otherwise false.
Expand All @@ -116,7 +121,8 @@ class FormData {
set (name, value, filename = undefined) {
webidl.brandCheck(this, FormData)

webidl.argumentLengthCheck(arguments, 2, 'FormData.set')
const prefix = 'FormData.set'
webidl.argumentLengthCheck(arguments, 2, prefix)

if (arguments.length === 3 && !isBlobLike(value)) {
throw new TypeError(
Expand All @@ -129,12 +135,12 @@ class FormData {

// 1. Let value be value if given; otherwise blobValue.

name = webidl.converters.USVString(name)
name = webidl.converters.USVString(name, prefix, 'name')
value = isBlobLike(value)
? webidl.converters.Blob(value, { strict: false })
: webidl.converters.USVString(value)
? webidl.converters.Blob(value, prefix, 'name', { strict: false })
: webidl.converters.USVString(value, prefix, 'name')
filename = arguments.length === 3
? webidl.converters.USVString(filename)
? webidl.converters.USVString(filename, prefix, 'name')
: undefined

// 2. Let entry be the result of creating an entry with name, value, and
Expand Down
Loading
Loading