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

remove double validation in webidl #3516

Merged
merged 3 commits into from
Aug 27, 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
6 changes: 1 addition & 5 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,18 +916,14 @@ Object.defineProperties(Request.prototype, {
}
})

webidl.converters.Request = webidl.interfaceConverter(
Request
)

// https://fetch.spec.whatwg.org/#requestinfo
webidl.converters.RequestInfo = function (V, prefix, argument) {
if (typeof V === 'string') {
return webidl.converters.USVString(V)
}

if (V instanceof Request) {
return webidl.converters.Request(V, prefix, argument)
return V
}

return webidl.converters.USVString(V)
Expand Down
22 changes: 5 additions & 17 deletions lib/web/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,38 +522,26 @@ function fromInnerResponse (innerResponse, guard) {
return response
}

webidl.converters.ReadableStream = webidl.interfaceConverter(
ReadableStream
)

webidl.converters.FormData = webidl.interfaceConverter(
FormData
)

webidl.converters.URLSearchParams = webidl.interfaceConverter(
URLSearchParams
)

// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
webidl.converters.XMLHttpRequestBodyInit = function (V, prefix, name) {
if (typeof V === 'string') {
return webidl.converters.USVString(V, prefix, name)
}

if (V instanceof Blob) {
return webidl.converters.Blob(V, prefix, name)
return V
}

if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) {
return webidl.converters.BufferSource(V, prefix, name)
return V
}

if (V instanceof FormData) {
return webidl.converters.FormData(V, prefix, name)
return V
}

if (V instanceof URLSearchParams) {
return webidl.converters.URLSearchParams(V, prefix, name)
return V
}

return webidl.converters.DOMString(V, prefix, name)
Expand All @@ -562,7 +550,7 @@ webidl.converters.XMLHttpRequestBodyInit = function (V, prefix, name) {
// https://fetch.spec.whatwg.org/#bodyinit
webidl.converters.BodyInit = function (V, prefix, argument) {
if (V instanceof ReadableStream) {
return webidl.converters.ReadableStream(V, prefix, argument)
return V
}

// Note: the spec doesn't include async iterables,
Expand Down
21 changes: 0 additions & 21 deletions lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,27 +654,6 @@ webidl.converters.DataView = function (V, prefix, name, opts) {
return V
}

// https://webidl.spec.whatwg.org/#BufferSource
webidl.converters.BufferSource = function (V, prefix, name, opts) {
if (types.isAnyArrayBuffer(V)) {
return webidl.converters.ArrayBuffer(V, prefix, name, { ...opts, allowShared: false })
}

if (types.isTypedArray(V)) {
return webidl.converters.TypedArray(V, V.constructor, prefix, name, { ...opts, allowShared: false })
}

if (types.isDataView(V)) {
return webidl.converters.DataView(V, prefix, name, { ...opts, allowShared: false })
}

throw webidl.errors.conversionFailed({
prefix,
argument: `${name} ("${webidl.util.Stringify(V)}")`,
types: ['BufferSource']
})
}

webidl.converters['sequence<ByteString>'] = webidl.sequenceConverter(
webidl.converters.ByteString
)
Expand Down
4 changes: 2 additions & 2 deletions lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,11 @@ webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'] = functio
webidl.converters.WebSocketSendData = function (V) {
if (webidl.util.Type(V) === 'Object') {
if (V instanceof Blob) {
return webidl.converters.Blob(V)
return V
}

if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) {
return webidl.converters.BufferSource(V)
return V
}
}

Expand Down
13 changes: 0 additions & 13 deletions test/webidl/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ test('DataView', () => {
assert.equal(webidl.converters.DataView(view, 'converter', 'converter'), view)
})

test('BufferSource', () => {
assert.doesNotThrow(() => {
const buffer = new ArrayBuffer(16)
const view = new DataView(buffer, 0)

webidl.converters.BufferSource(view, 'converter', 'converter')
})

assert.throws(() => {
webidl.converters.BufferSource(3, 'converter', 'converter')
}, TypeError)
})

test('ByteString', () => {
assert.doesNotThrow(() => {
webidl.converters.ByteString('', 'converter', 'converter')
Expand Down
Loading