summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-05-26 23:44:42 +0200
committerGitHub <noreply@github.com>2021-05-26 23:44:42 +0200
commitd5d59bb794503416ced2c3ad6a2bb043f97ce3e5 (patch)
treee18b9655fedca63f068333fb1fa37297e3b0b3b7
parente5beb800c94099852964d482a32a13f5c29ec147 (diff)
fix(fetch): make prototype properties writable (#10769)
-rw-r--r--cli/tests/unit/fetch_test.ts10
-rw-r--r--extensions/fetch/22_body.js19
-rw-r--r--extensions/fetch/23_request.js22
-rw-r--r--extensions/fetch/23_response.js34
-rw-r--r--tools/wpt/expectation.json23
5 files changed, 85 insertions, 23 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index e73953a5c..c2224083d 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -1139,3 +1139,13 @@ unitTest(
assertEquals(actual, expected);
},
);
+
+unitTest({}, function fetchWritableRespProps(): void {
+ const original = new Response("https://deno.land", {
+ status: 404,
+ headers: { "x-deno": "foo" },
+ });
+ const new_ = new Response("https://deno.land", original);
+ assertEquals(original.status, new_.status);
+ assertEquals(new_.headers.get("x-deno"), "foo");
+});
diff --git a/extensions/fetch/22_body.js b/extensions/fetch/22_body.js
index 938e3023e..8c93e0fcf 100644
--- a/extensions/fetch/22_body.js
+++ b/extensions/fetch/22_body.js
@@ -147,6 +147,8 @@
return this[bodySymbol].stream;
}
},
+ configurable: true,
+ enumerable: true,
},
bodyUsed: {
/**
@@ -159,6 +161,8 @@
}
return false;
},
+ configurable: true,
+ enumerable: true,
},
arrayBuffer: {
/** @returns {Promise<ArrayBuffer>} */
@@ -167,6 +171,9 @@
const body = await consumeBody(this);
return packageData(body, "ArrayBuffer");
},
+ writable: true,
+ configurable: true,
+ enumerable: true,
},
blob: {
/** @returns {Promise<Blob>} */
@@ -175,6 +182,9 @@
const body = await consumeBody(this);
return packageData(body, "Blob", this[mimeTypeSymbol]);
},
+ writable: true,
+ configurable: true,
+ enumerable: true,
},
formData: {
/** @returns {Promise<FormData>} */
@@ -183,6 +193,9 @@
const body = await consumeBody(this);
return packageData(body, "FormData", this[mimeTypeSymbol]);
},
+ writable: true,
+ configurable: true,
+ enumerable: true,
},
json: {
/** @returns {Promise<any>} */
@@ -191,6 +204,9 @@
const body = await consumeBody(this);
return packageData(body, "JSON");
},
+ writable: true,
+ configurable: true,
+ enumerable: true,
},
text: {
/** @returns {Promise<string>} */
@@ -199,6 +215,9 @@
const body = await consumeBody(this);
return packageData(body, "text");
},
+ writable: true,
+ configurable: true,
+ enumerable: true,
},
};
return Object.defineProperties(prototype.prototype, mixin);
diff --git a/extensions/fetch/23_request.js b/extensions/fetch/23_request.js
index 480b83182..d8369b404 100644
--- a/extensions/fetch/23_request.js
+++ b/extensions/fetch/23_request.js
@@ -403,6 +403,28 @@
mixinBody(Request, _body, _mimeType);
+ Object.defineProperty(Request.prototype, "method", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Request.prototype, "url", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Request.prototype, "headers", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Request.prototype, "redirect", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Request.prototype, "clone", {
+ enumerable: true,
+ writable: true,
+ configurable: true,
+ });
+
webidl.converters["Request"] = webidl.createInterfaceConverter(
"Request",
Request,
diff --git a/extensions/fetch/23_response.js b/extensions/fetch/23_response.js
index 6d9874c6a..7bbf3c66e 100644
--- a/extensions/fetch/23_response.js
+++ b/extensions/fetch/23_response.js
@@ -365,6 +365,40 @@
mixinBody(Response, _body, _mimeType);
+ Object.defineProperty(Response.prototype, "type", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "url", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "redirected", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "status", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "ok", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "statusText", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "headers", {
+ enumerable: true,
+ configurable: true,
+ });
+ Object.defineProperty(Response.prototype, "clone", {
+ enumerable: true,
+ writable: true,
+ configurable: true,
+ });
+
webidl.converters["Response"] = webidl.createInterfaceConverter(
"Response",
Response,
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index e7aca77a8..f504357f7 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -929,46 +929,23 @@
"Headers interface: operation has(ByteString)",
"Headers interface: operation set(ByteString, ByteString)",
"Headers interface: iterable<ByteString, ByteString>",
- "Request interface: attribute method",
- "Request interface: attribute url",
- "Request interface: attribute headers",
"Request interface: attribute destination",
"Request interface: attribute referrer",
"Request interface: attribute referrerPolicy",
"Request interface: attribute mode",
"Request interface: attribute credentials",
"Request interface: attribute cache",
- "Request interface: attribute redirect",
"Request interface: attribute integrity",
"Request interface: attribute keepalive",
"Request interface: attribute isReloadNavigation",
"Request interface: attribute isHistoryNavigation",
"Request interface: attribute signal",
- "Request interface: operation clone()",
"Request interface: attribute body",
"Request interface: attribute bodyUsed",
- "Request interface: operation arrayBuffer()",
- "Request interface: operation blob()",
- "Request interface: operation formData()",
- "Request interface: operation json()",
- "Request interface: operation text()",
"Response interface: operation error()",
"Response interface: operation redirect(USVString, optional unsigned short)",
- "Response interface: attribute type",
- "Response interface: attribute url",
- "Response interface: attribute redirected",
- "Response interface: attribute status",
- "Response interface: attribute ok",
- "Response interface: attribute statusText",
- "Response interface: attribute headers",
- "Response interface: operation clone()",
"Response interface: attribute body",
"Response interface: attribute bodyUsed",
- "Response interface: operation arrayBuffer()",
- "Response interface: operation blob()",
- "Response interface: operation formData()",
- "Response interface: operation json()",
- "Response interface: operation text()",
"Window interface: operation fetch(RequestInfo, optional RequestInit)"
]
},