Skip to content

Commit ddff8d5

Browse files
authored
[Fetch] fetchXHR callbacks are always specified. NFC (#24845)
No need to check for undefined here.
1 parent 0e9686a commit ddff8d5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/Fetch.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
244244
#if FETCH_DEBUG
245245
dbg('fetch: XHR failed, no URL specified!');
246246
#endif
247-
onerror(fetch, 0, 'no url specified!');
247+
onerror(fetch, 'no url specified!');
248248
return;
249249
}
250250
var url_ = UTF8ToString(url);
@@ -363,12 +363,12 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
363363
#if FETCH_DEBUG
364364
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" succeeded with status ${xhr.status}`);
365365
#endif
366-
onsuccess?.(fetch, xhr, e);
366+
onsuccess(fetch, xhr, e);
367367
} else {
368368
#if FETCH_DEBUG
369369
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" failed with status ${xhr.status}`);
370370
#endif
371-
onerror?.(fetch, xhr, e);
371+
onerror(fetch, e);
372372
}
373373
};
374374
xhr.onerror = (e) => {
@@ -380,7 +380,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
380380
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" finished with error, readyState ${xhr.readyState} and status ${xhr.status}`);
381381
#endif
382382
saveResponseAndStatus();
383-
onerror?.(fetch, xhr, e);
383+
onerror(fetch, e);
384384
};
385385
xhr.ontimeout = (e) => {
386386
// check if xhr was aborted by user and don't try to call back
@@ -390,7 +390,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
390390
#if FETCH_DEBUG
391391
dbg(`fetch: xhr of URL "${xhr.url_}" / responseURL "${xhr.responseURL}" timed out, readyState ${xhr.readyState} and status ${xhr.status}`);
392392
#endif
393-
onerror?.(fetch, xhr, e);
393+
onerror(fetch, e);
394394
};
395395
xhr.onprogress = (e) => {
396396
// check if xhr was aborted by user and don't try to call back
@@ -420,7 +420,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
420420
if (xhr.readyState >= 3 && xhr.status === 0 && e.loaded > 0) status = 200;
421421
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.status, 'status', 'i16') }}}
422422
if (xhr.statusText) stringToUTF8(xhr.statusText, fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
423-
onprogress?.(fetch, xhr, e);
423+
onprogress(fetch, e);
424424
_free(ptr);
425425
};
426426
xhr.onreadystatechange = (e) => {
@@ -439,7 +439,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
439439
var ruPtr = stringToNewUTF8(xhr.responseURL);
440440
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.responseUrl, 'ruPtr', '*') }}}
441441
}
442-
onreadystatechange?.(fetch, xhr, e);
442+
onreadystatechange(fetch, e);
443443
};
444444
#if FETCH_DEBUG
445445
dbg(`fetch: xhr.send(data=${data})`);
@@ -450,7 +450,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
450450
#if FETCH_DEBUG
451451
dbg(`fetch: xhr failed with exception: ${e}`);
452452
#endif
453-
onerror?.(fetch, xhr, e);
453+
onerror(fetch, e);
454454
}
455455
}
456456

@@ -486,14 +486,14 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
486486
});
487487
};
488488

489-
var reportProgress = (fetch, xhr, e) => {
489+
var reportProgress = (fetch, e) => {
490490
doCallback(() => {
491491
if (onprogress) {{{ makeDynCall('vp', 'onprogress') }}}(fetch);
492492
else progresscb?.(fetch);
493493
});
494494
};
495495

496-
var reportError = (fetch, xhr, e) => {
496+
var reportError = (fetch, e) => {
497497
#if FETCH_DEBUG
498498
dbg(`fetch: operation failed: ${e}`);
499499
#endif
@@ -504,7 +504,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
504504
});
505505
};
506506

507-
var reportReadyStateChange = (fetch, xhr, e) => {
507+
var reportReadyStateChange = (fetch, e) => {
508508
#if FETCH_DEBUG
509509
dbg(`fetch: ready state change. e: ${e}`);
510510
#endif

0 commit comments

Comments
 (0)