From c2c6161a6adf6f2afaef2aab31daeeb84e6eaf2f Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 27 Aug 2024 15:23:56 -0400 Subject: [PATCH] remove double validation in webidl (#3516) * webidl don't double validate * remove unused converters * remove BufferSource --- lib/web/fetch/request.js | 6 +----- lib/web/fetch/response.js | 22 +++++----------------- lib/web/fetch/webidl.js | 21 --------------------- lib/web/websocket/websocket.js | 4 ++-- test/webidl/converters.js | 13 ------------- 5 files changed, 8 insertions(+), 58 deletions(-) diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js index b82127f0c6b..5caf385c685 100644 --- a/lib/web/fetch/request.js +++ b/lib/web/fetch/request.js @@ -916,10 +916,6 @@ 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') { @@ -927,7 +923,7 @@ webidl.converters.RequestInfo = function (V, prefix, argument) { } if (V instanceof Request) { - return webidl.converters.Request(V, prefix, argument) + return V } return webidl.converters.USVString(V) diff --git a/lib/web/fetch/response.js b/lib/web/fetch/response.js index 252addc2286..9cf5d8018f2 100644 --- a/lib/web/fetch/response.js +++ b/lib/web/fetch/response.js @@ -522,18 +522,6 @@ 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') { @@ -541,19 +529,19 @@ webidl.converters.XMLHttpRequestBodyInit = function (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) @@ -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, diff --git a/lib/web/fetch/webidl.js b/lib/web/fetch/webidl.js index ef0e6dc27f1..9db13d07df7 100644 --- a/lib/web/fetch/webidl.js +++ b/lib/web/fetch/webidl.js @@ -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'] = webidl.sequenceConverter( webidl.converters.ByteString ) diff --git a/lib/web/websocket/websocket.js b/lib/web/websocket/websocket.js index 96d6c4e453d..5d876987e16 100644 --- a/lib/web/websocket/websocket.js +++ b/lib/web/websocket/websocket.js @@ -794,11 +794,11 @@ webidl.converters['DOMString or sequence 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 } } diff --git a/test/webidl/converters.js b/test/webidl/converters.js index c5f4ce88d71..e88a54a48b6 100644 --- a/test/webidl/converters.js +++ b/test/webidl/converters.js @@ -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')