Skip to content

Commit 717e1d2

Browse files
committed
fix: don't trample fetch types
Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent a6d7ec4 commit 717e1d2

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

elide/runtime/js/polyfills/fetch.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Fetch {
348348

349349
let getRequestPrivate; // Private field accessor
350350

351-
class Request {
351+
class FetchLikeRequest {
352352
#req;
353353
#bodyUsed = false;
354354

@@ -414,7 +414,7 @@ class Fetch {
414414
if (this.#bodyUsed) {
415415
throw new TypeError("Body has already been consumed");
416416
}
417-
return new Request(this);
417+
return new FetchLikeRequest(this);
418418
}
419419

420420
#consumeBody() {
@@ -443,7 +443,7 @@ class Fetch {
443443
return asBlob(body);
444444
}
445445
}
446-
defineToStringTag(Request);
446+
defineToStringTag(FetchLikeRequest);
447447

448448
function makeResponse(init) {
449449
return {
@@ -456,7 +456,7 @@ class Fetch {
456456
};
457457
}
458458

459-
class Response {
459+
class FetchLikeResponse {
460460
#res;
461461
#body;
462462
#bodyUsed = false;
@@ -469,7 +469,7 @@ class Fetch {
469469
}
470470

471471
static error() {
472-
return new Response(null, {type: 'error', status: 0, statusText: ''});
472+
return new FetchLikeResponse(null, {type: 'error', status: 0, statusText: ''});
473473
}
474474

475475
static json(body, init = {}) {
@@ -478,7 +478,7 @@ class Fetch {
478478
if (init.headers != null) {
479479
fillHeaders(headers, init.headers);
480480
}
481-
return new Response(body, {...init, headers});
481+
return new FetchLikeResponse(body, {...init, headers});
482482
}
483483

484484
static redirect(url, status) {
@@ -488,7 +488,7 @@ class Fetch {
488488
if (!isRedirect(status)) {
489489
throw new RangeError(`Invalid status code ${status}`);
490490
}
491-
return new Response(null, {status, statusText: getStatusText(status), headers: {'Location': url}});
491+
return new FetchLikeResponse(null, {status, statusText: getStatusText(status), headers: {'Location': url}});
492492
}
493493

494494
get url() {
@@ -525,7 +525,7 @@ class Fetch {
525525
if (this.#bodyUsed) {
526526
throw new TypeError("Body has already been consumed");
527527
}
528-
let clone = new Response(this.#body);
528+
let clone = new FetchLikeResponse(this.#body);
529529
clone.#res = makeResponse(this.#res);
530530
return clone;
531531
}
@@ -556,7 +556,7 @@ class Fetch {
556556
return asBlob(body);
557557
}
558558
}
559-
defineToStringTag(Response);
559+
defineToStringTag(FetchLikeResponse);
560560

561561
function FetchError(message, code) {
562562
const error = new TypeError(message);
@@ -597,7 +597,7 @@ class Fetch {
597597

598598
async function fetch(input, init={}) {
599599
console.log("[fetch] checkpoint 2.1")
600-
let request = new Request(input, init);
600+
let request = new FetchLikeRequest(input, init);
601601
let requestPrivate = getRequestPrivate(request);
602602

603603
let scheme = requestPrivate.uri.getScheme();
@@ -673,7 +673,7 @@ class Fetch {
673673
mimeType = "text/plain;charset=US-ASCII";
674674
}
675675

676-
let response = new Response(body, {
676+
let response = new FetchLikeResponse(body, {
677677
status: 200,
678678
statusText: 'OK',
679679
url: request.url,
@@ -872,7 +872,7 @@ class Fetch {
872872

873873
console.log("[fetch] checkpoint 6.1")
874874

875-
let response = new Response(body, {
875+
let response = new FetchLikeResponse(body, {
876876
status,
877877
headers,
878878
url: request.url,
@@ -957,12 +957,11 @@ class Fetch {
957957
default: return "";
958958
};
959959
}
960-
Object.entries({"fetch": fetch, "Headers": Headers, "Request": Request, "Response": Response}).forEach((entry) => {
960+
Object.entries({"fetch": fetch}).forEach((entry) => {
961961
const [name, fn] = entry;
962962
Object.defineProperty(globalThis, name, {value: fn, configurable: true, writable: true, enumerable: false});
963963
});
964964
}
965965
};
966966

967-
globalThis['Fetch'] = Fetch;
968967
export { Fetch };

0 commit comments

Comments
 (0)