(input, init = undefined)
| 157 | |
| 158 | // https://fetch.spec.whatwg.org/#fetch-method |
| 159 | function fetch (input, init = undefined) { |
| 160 | webidl.argumentLengthCheck(arguments, 1, 'globalThis.fetch') |
| 161 | |
| 162 | // 1. Let p be a new promise. |
| 163 | let p = Promise.withResolvers() |
| 164 | |
| 165 | // 2. Let requestObject be the result of invoking the initial value of |
| 166 | // Request as constructor with input and init as arguments. If this throws |
| 167 | // an exception, reject p with it and return p. |
| 168 | let requestObject |
| 169 | |
| 170 | try { |
| 171 | requestObject = new Request(input, init) |
| 172 | } catch (e) { |
| 173 | p.reject(e) |
| 174 | return p.promise |
| 175 | } |
| 176 | |
| 177 | // 3. Let request be requestObject’s request. |
| 178 | const request = getRequestState(requestObject) |
| 179 | |
| 180 | // 4. If requestObject’s signal’s aborted flag is set, then: |
| 181 | if (requestObject.signal.aborted) { |
| 182 | // 1. Abort the fetch() call with p, request, null, and |
| 183 | // requestObject’s signal’s abort reason. |
| 184 | abortFetch(p, request, null, requestObject.signal.reason, null) |
| 185 | |
| 186 | // 2. Return p. |
| 187 | return p.promise |
| 188 | } |
| 189 | |
| 190 | // 5. Let globalObject be request’s client’s global object. |
| 191 | const globalObject = request.client.globalObject |
| 192 | |
| 193 | // 6. If globalObject is a ServiceWorkerGlobalScope object, then set |
| 194 | // request’s service-workers mode to "none". |
| 195 | if (globalObject?.constructor?.name === 'ServiceWorkerGlobalScope') { |
| 196 | request.serviceWorkers = 'none' |
| 197 | } |
| 198 | |
| 199 | // 7. Let responseObject be null. |
| 200 | let responseObject = null |
| 201 | |
| 202 | // 8. Let relevantRealm be this’s relevant Realm. |
| 203 | |
| 204 | // 9. Let locallyAborted be false. |
| 205 | let locallyAborted = false |
| 206 | |
| 207 | // 10. Let controller be null. |
| 208 | let controller = null |
| 209 | |
| 210 | // 11. Add the following abort steps to requestObject’s signal: |
| 211 | const removeAbortListener = addAbortListener( |
| 212 | requestObject.signal, |
| 213 | () => { |
| 214 | // 1. Set locallyAborted to true. |
| 215 | locallyAborted = true |
| 216 |
no test coverage detected
searching dependent graphs…