Skip to content

Commit e500d61

Browse files
authored
[Fetch] Avoid assigned to XMLHttpRequest.status field (#24841)
I have no idea how or when this assigned is triggered but apparently there are cases where it can be. I tried doing fetches from `file://` but there were all blocked. Fixes: #20189
1 parent cbbc783 commit e500d61

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Fetch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,10 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
415415
writeI53ToI64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.dataOffset }}}, e.loaded - ptrLen);
416416
writeI53ToI64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.totalBytes }}}, e.total);
417417
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.readyState, 'xhr.readyState', 'i16') }}}
418+
var status = xhr.status;
418419
// If loading files from a source that does not give HTTP status code, assume success if we get data bytes
419-
if (xhr.readyState >= 3 && xhr.status === 0 && e.loaded > 0) xhr.status = 200;
420-
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.status, 'xhr.status', 'i16') }}}
420+
if (xhr.readyState >= 3 && xhr.status === 0 && e.loaded > 0) status = 200;
421+
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.status, 'status', 'i16') }}}
421422
if (xhr.statusText) stringToUTF8(xhr.statusText, fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
422423
onprogress?.(fetch, xhr, e);
423424
_free(ptr);

0 commit comments

Comments
 (0)