Skip to content

Commit e363ccc

Browse files
KhafraDevmetcoder95
authored andcommitted
fix: minor fetch finalize fixes
1 parent a00a53b commit e363ccc

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/fetch/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,38 @@ async function fetch (...args) {
205205
return p.promise
206206
}
207207

208+
// https://fetch.spec.whatwg.org/#finalize-and-report-timing
208209
function finalizeAndReportTiming (response, initiatorType = 'other') {
209-
// 1. If response’s URL list is null or empty, then return.
210+
// 1. If response is an aborted network error, then return.
211+
if (response.type === 'error' && response.aborted) {
212+
return
213+
}
214+
215+
// 2. If response’s URL list is null or empty, then return.
210216
if (!response.urlList?.length) {
211217
return
212218
}
213219

214-
// 2. Let originalURL be response’s URL list[0].
220+
// 3. Let originalURL be response’s URL list[0].
215221
const originalURL = response.urlList[0]
216222

217-
// 3. Let timingInfo be response’s timing info.
223+
// 4. Let timingInfo be response’s timing info.
218224
let timingInfo = response.timingInfo
219225

220-
// 4. Let cacheState be response’s cache state.
226+
// 5. Let cacheState be response’s cache state.
221227
let cacheState = response.cacheState
222228

223-
// 5. If timingInfo is null, then return.
229+
// 6. If originalURL’s scheme is not an HTTP(S) scheme, then return.
230+
if (!/^https?:/.test(originalURL.protocol)) {
231+
return
232+
}
233+
234+
// 7. If timingInfo is null, then return.
224235
if (timingInfo === null) {
225236
return
226237
}
227238

228-
// 6. If response’s timing allow passed flag is not set, then:
239+
// 8. If response’s timing allow passed flag is not set, then:
229240
if (!timingInfo.timingAllowPassed) {
230241
// 1. Set timingInfo to a the result of creating an opaque timing info for timingInfo.
231242
timingInfo = createOpaqueTimingInfo({
@@ -236,23 +247,23 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
236247
cacheState = ''
237248
}
238249

239-
// 7. Set timingInfo’s end time to the coarsened shared current time
250+
// 9. Set timingInfo’s end time to the coarsened shared current time
240251
// given global’s relevant settings object’s cross-origin isolated
241252
// capability.
242253
// TODO: given global’s relevant settings object’s cross-origin isolated
243254
// capability?
244255
response.timingInfo.endTime = coarsenedSharedCurrentTime()
245256

246-
// 8. Set response’s timing info to timingInfo.
257+
// 10. Set response’s timing info to timingInfo.
247258
response.timingInfo = timingInfo
248259

249-
// 9. Mark resource timing for timingInfo, originalURL, initiatorType,
260+
// 11. Mark resource timing for timingInfo, originalURL, initiatorType,
250261
// global, and cacheState.
251262
markResourceTiming(
252263
timingInfo,
253264
originalURL,
254265
initiatorType,
255-
global,
266+
globalThis,
256267
cacheState
257268
)
258269
}

0 commit comments

Comments
 (0)