Skip to content

Commit a87242f

Browse files
authored
feat(fetch): remove unnecessary checks (#1520)
1 parent af61bf5 commit a87242f

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lib/fetch/index.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,27 @@ class Fetch extends EE {
9595
}
9696

9797
// https://fetch.spec.whatwg.org/#fetch-method
98-
async function fetch (...args) {
99-
if (args.length < 1) {
98+
async function fetch (input, init = undefined) {
99+
if (arguments.length < 1) {
100100
throw new TypeError(
101-
`Failed to execute 'fetch' on 'Window': 1 argument required, but only ${args.length} present.`
102-
)
103-
}
104-
if (
105-
args.length >= 1 &&
106-
typeof args[1] !== 'object' &&
107-
args[1] !== undefined
108-
) {
109-
throw new TypeError(
110-
"Failed to execute 'fetch' on 'Window': cannot convert to dictionary."
101+
`Failed to execute 'fetch' on 'Window': 1 argument required, but only ${arguments.length} present.`
111102
)
112103
}
113104

114-
const resource = args[0]
115-
const init = args.length >= 1 ? args[1] ?? {} : {}
116-
117105
// 1. Let p be a new promise.
118106
const p = createDeferredPromise()
119107

120108
// 2. Let requestObject be the result of invoking the initial value of
121109
// Request as constructor with input and init as arguments. If this throws
122110
// an exception, reject p with it and return p.
123-
const requestObject = new Request(resource, init)
111+
let requestObject
112+
113+
try {
114+
requestObject = new Request(input, init)
115+
} catch (e) {
116+
p.reject(e)
117+
return p.promise
118+
}
124119

125120
// 3. Let request be requestObject’s request.
126121
const request = requestObject[kState]

0 commit comments

Comments
 (0)