Skip to content

Commit de0424f

Browse files
authored
remove third party everything support in fetch (#3502)
* remove third party everything support in fetch * fixup * fixup * test * test * test * fixup * fixup * fixup * fixup! remove is*Like, *Like
1 parent 409222c commit de0424f

19 files changed

+38
-361
lines changed

lib/web/fetch/body.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
const util = require('../../core/util')
44
const {
55
ReadableStreamFrom,
6-
isBlobLike,
7-
isReadableStreamLike,
86
readableStreamClose,
97
createDeferredPromise,
108
fullyReadBody,
@@ -44,7 +42,7 @@ function extractBody (object, keepalive = false) {
4442
// 2. If object is a ReadableStream object, then set stream to object.
4543
if (object instanceof ReadableStream) {
4644
stream = object
47-
} else if (isBlobLike(object)) {
45+
} else if (object instanceof Blob) {
4846
// 3. Otherwise, if object is a Blob object, set stream to the
4947
// result of running object’s get stream.
5048
stream = object.stream()
@@ -67,7 +65,7 @@ function extractBody (object, keepalive = false) {
6765
}
6866

6967
// 5. Assert: stream is a ReadableStream object.
70-
assert(isReadableStreamLike(stream))
68+
assert(stream instanceof ReadableStream)
7169

7270
// 6. Let action be null.
7371
let action = null
@@ -112,7 +110,7 @@ function extractBody (object, keepalive = false) {
112110

113111
// Set source to a copy of the bytes held by object.
114112
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
115-
} else if (util.isFormDataLike(object)) {
113+
} else if (object instanceof FormData) {
116114
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
117115
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
118116

@@ -178,7 +176,7 @@ function extractBody (object, keepalive = false) {
178176
// followed by the multipart/form-data boundary string generated
179177
// by the multipart/form-data encoding algorithm.
180178
type = `multipart/form-data; boundary=${boundary}`
181-
} else if (isBlobLike(object)) {
179+
} else if (object instanceof Blob) {
182180
// Blob
183181

184182
// Set source to object.

lib/web/fetch/file.js

-126
This file was deleted.

lib/web/fetch/formdata-parser.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { isUSVString, bufferToLowerCasedHeaderName } = require('../../core/util')
44
const { utf8DecodeBytes } = require('./util')
55
const { HTTP_TOKEN_CODEPOINTS, isomorphicDecode } = require('./data-url')
6-
const { isFileLike } = require('./file')
76
const { makeEntry } = require('./formdata')
87
const assert = require('node:assert')
98
const { File: NodeFile } = require('node:buffer')
@@ -195,7 +194,7 @@ function multipartFormDataParser (input, mimeType) {
195194

196195
// 5.12. Assert: name is a scalar value string and value is either a scalar value string or a File object.
197196
assert(isUSVString(name))
198-
assert((typeof value === 'string' && isUSVString(value)) || isFileLike(value))
197+
assert((typeof value === 'string' && isUSVString(value)) || value instanceof File)
199198

200199
// 5.13. Create an entry with name and value, and append it to entry list.
201200
entryList.push(makeEntry(name, value, filename))

lib/web/fetch/formdata.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict'
22

3-
const { isBlobLike, iteratorMixin } = require('./util')
3+
const { iteratorMixin } = require('./util')
44
const { kState } = require('./symbols')
55
const { kEnumerableProperty } = require('../../core/util')
6-
const { FileLike, isFileLike } = require('./file')
76
const { webidl } = require('./webidl')
87
const { File: NativeFile } = require('node:buffer')
98
const nodeUtil = require('node:util')
@@ -31,7 +30,7 @@ class FormData {
3130
const prefix = 'FormData.append'
3231
webidl.argumentLengthCheck(arguments, 2, prefix)
3332

34-
if (arguments.length === 3 && !isBlobLike(value)) {
33+
if (arguments.length === 3 && !(value instanceof Blob)) {
3534
throw new TypeError(
3635
"Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'"
3736
)
@@ -40,8 +39,8 @@ class FormData {
4039
// 1. Let value be value if given; otherwise blobValue.
4140

4241
name = webidl.converters.USVString(name)
43-
value = isBlobLike(value)
44-
? webidl.converters.Blob(value, prefix, 'value', { strict: false })
42+
value = value instanceof Blob
43+
? webidl.converters.Blob(value, prefix, 'value')
4544
: webidl.converters.USVString(value)
4645
filename = arguments.length === 3
4746
? webidl.converters.USVString(filename)
@@ -124,7 +123,7 @@ class FormData {
124123
const prefix = 'FormData.set'
125124
webidl.argumentLengthCheck(arguments, 2, prefix)
126125

127-
if (arguments.length === 3 && !isBlobLike(value)) {
126+
if (arguments.length === 3 && !(value instanceof Blob)) {
128127
throw new TypeError(
129128
"Failed to execute 'set' on 'FormData': parameter 2 is not of type 'Blob'"
130129
)
@@ -136,8 +135,8 @@ class FormData {
136135
// 1. Let value be value if given; otherwise blobValue.
137136

138137
name = webidl.converters.USVString(name)
139-
value = isBlobLike(value)
140-
? webidl.converters.Blob(value, prefix, 'name', { strict: false })
138+
value = value instanceof Blob
139+
? webidl.converters.Blob(value, prefix, 'name')
141140
: webidl.converters.USVString(value)
142141
filename = arguments.length === 3
143142
? webidl.converters.USVString(filename)
@@ -222,10 +221,8 @@ function makeEntry (name, value, filename) {
222221

223222
// 1. If value is not a File object, then set value to a new File object,
224223
// representing the same bytes, whose name attribute value is "blob"
225-
if (!isFileLike(value)) {
226-
value = value instanceof Blob
227-
? new File([value], 'blob', { type: value.type })
228-
: new FileLike(value, 'blob', { type: value.type })
224+
if (!(value instanceof File)) {
225+
value = new File([value], 'blob', { type: value.type })
229226
}
230227

231228
// 2. If filename is given, then set value to a new File object,
@@ -237,9 +234,7 @@ function makeEntry (name, value, filename) {
237234
lastModified: value.lastModified
238235
}
239236

240-
value = value instanceof NativeFile
241-
? new File([value], filename, options)
242-
: new FileLike(value, filename, options)
237+
value = new File([value], filename, options)
243238
}
244239
}
245240

lib/web/fetch/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const {
3030
determineRequestsReferrer,
3131
coarsenedSharedCurrentTime,
3232
createDeferredPromise,
33-
isBlobLike,
3433
sameOrigin,
3534
isCancelled,
3635
isAborted,
@@ -810,7 +809,7 @@ function schemeFetch (fetchParams) {
810809

811810
// 2. If request’s method is not `GET`, blobURLEntry is null, or blobURLEntry’s
812811
// object is not a Blob object, then return a network error.
813-
if (request.method !== 'GET' || !isBlobLike(blob)) {
812+
if (request.method !== 'GET' || !(blob instanceof Blob)) {
814813
return Promise.resolve(makeNetworkError('invalid method'))
815814
}
816815

lib/web/fetch/request.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,6 @@ class Request {
400400

401401
// 29. If signal is not null, then make this’s signal follow signal.
402402
if (signal != null) {
403-
if (
404-
!signal ||
405-
typeof signal.aborted !== 'boolean' ||
406-
typeof signal.addEventListener !== 'function'
407-
) {
408-
throw new TypeError(
409-
"Failed to construct 'Request': member signal is not of type AbortSignal."
410-
)
411-
}
412-
413403
if (signal.aborted) {
414404
ac.abort(signal.reason)
415405
} else {
@@ -1011,8 +1001,7 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
10111001
(signal) => webidl.converters.AbortSignal(
10121002
signal,
10131003
'RequestInit',
1014-
'signal',
1015-
{ strict: false }
1004+
'signal'
10161005
)
10171006
)
10181007
},

lib/web/fetch/response.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const {
99
isValidReasonPhrase,
1010
isCancelled,
1111
isAborted,
12-
isBlobLike,
1312
serializeJavascriptValueToJSONString,
1413
isErrorLike,
1514
isomorphicEncode,
@@ -541,16 +540,16 @@ webidl.converters.XMLHttpRequestBodyInit = function (V, prefix, name) {
541540
return webidl.converters.USVString(V, prefix, name)
542541
}
543542

544-
if (isBlobLike(V)) {
545-
return webidl.converters.Blob(V, prefix, name, { strict: false })
543+
if (V instanceof Blob) {
544+
return webidl.converters.Blob(V, prefix, name)
546545
}
547546

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

552-
if (util.isFormDataLike(V)) {
553-
return webidl.converters.FormData(V, prefix, name, { strict: false })
551+
if (V instanceof FormData) {
552+
return webidl.converters.FormData(V, prefix, name)
554553
}
555554

556555
if (V instanceof URLSearchParams) {

lib/web/fetch/util.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { redirectStatusSet, referrerPolicySet: referrerPolicyTokens, badPortsSet
66
const { getGlobalOrigin } = require('./global')
77
const { collectASequenceOfCodePoints, collectAnHTTPQuotedString, removeChars, parseMIMEType } = require('./data-url')
88
const { performance } = require('node:perf_hooks')
9-
const { isBlobLike, ReadableStreamFrom, isValidHTTPToken, normalizedMethodRecordsBase } = require('../../core/util')
9+
const { ReadableStreamFrom, isValidHTTPToken, normalizedMethodRecordsBase } = require('../../core/util')
1010
const assert = require('node:assert')
1111
const { isUint8Array } = require('node:util/types')
1212
const { webidl } = require('./webidl')
@@ -1061,13 +1061,6 @@ async function fullyReadBody (body, processBody, processBodyError) {
10611061
}
10621062
}
10631063

1064-
function isReadableStreamLike (stream) {
1065-
return stream instanceof ReadableStream || (
1066-
stream[Symbol.toStringTag] === 'ReadableStream' &&
1067-
typeof stream.tee === 'function'
1068-
)
1069-
}
1070-
10711064
/**
10721065
* @param {ReadableStreamController<Uint8Array>} controller
10731066
*/
@@ -1589,7 +1582,6 @@ module.exports = {
15891582
requestCurrentURL,
15901583
responseURL,
15911584
responseLocationURL,
1592-
isBlobLike,
15931585
isURLPotentiallyTrustworthy,
15941586
isValidReasonPhrase,
15951587
sameOrigin,
@@ -1602,7 +1594,6 @@ module.exports = {
16021594
isErrorLike,
16031595
fullyReadBody,
16041596
bytesMatch,
1605-
isReadableStreamLike,
16061597
readableStreamClose,
16071598
isomorphicEncode,
16081599
urlIsLocal,

0 commit comments

Comments
 (0)