summaryrefslogtreecommitdiff
path: root/ext/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fetch')
-rw-r--r--ext/fetch/20_headers.js10
-rw-r--r--ext/fetch/23_request.js10
-rw-r--r--ext/fetch/23_response.js10
3 files changed, 24 insertions, 6 deletions
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js
index 39127b1ec..a004daa89 100644
--- a/ext/fetch/20_headers.js
+++ b/ext/fetch/20_headers.js
@@ -40,6 +40,7 @@ const _headerList = Symbol("header list");
const _iterableHeaders = Symbol("iterable headers");
const _iterableHeadersCache = Symbol("iterable headers cache");
const _guard = Symbol("guard");
+const _brand = webidl.brand;
/**
* @typedef Header
@@ -286,12 +287,17 @@ class Headers {
/** @param {HeadersInit} [init] */
constructor(init = undefined) {
+ if (init === _brand) {
+ this[_brand] = _brand;
+ return;
+ }
+
const prefix = "Failed to construct 'Headers'";
if (init !== undefined) {
init = webidl.converters["HeadersInit"](init, prefix, "Argument 1");
}
- this[webidl.brand] = webidl.brand;
+ this[_brand] = _brand;
this[_guard] = "none";
if (init !== undefined) {
fillHeaders(this, init);
@@ -486,7 +492,7 @@ webidl.converters["Headers"] = webidl.createInterfaceConverter(
* @returns {Headers}
*/
function headersFromHeaderList(list, guard) {
- const headers = webidl.createBranded(Headers);
+ const headers = new Headers(_brand);
headers[_headerList] = list;
headers[_guard] = guard;
return headers;
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index 5232cc13c..c09bd4880 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -52,6 +52,7 @@ const _mimeType = Symbol("mime type");
const _body = Symbol("body");
const _url = Symbol("url");
const _method = Symbol("method");
+const _brand = webidl.brand;
/**
* @param {(() => string)[]} urlList
@@ -275,6 +276,11 @@ class Request {
* @param {RequestInit} init
*/
constructor(input, init = {}) {
+ if (input === _brand) {
+ this[_brand] = _brand;
+ return;
+ }
+
const prefix = "Failed to construct 'Request'";
webidl.requiredArguments(arguments.length, 1, prefix);
input = webidl.converters["RequestInfo_DOMString"](
@@ -284,7 +290,7 @@ class Request {
);
init = webidl.converters["RequestInit"](init, prefix, "Argument 2");
- this[webidl.brand] = webidl.brand;
+ this[_brand] = _brand;
/** @type {InnerRequest} */
let request;
@@ -554,7 +560,7 @@ function toInnerRequest(request) {
* @returns {Request}
*/
function fromInnerRequest(inner, signal, guard) {
- const request = webidl.createBranded(Request);
+ const request = new Request(_brand);
request[_request] = inner;
request[_signal] = signal;
request[_getHeaders] = () => headersFromHeaderList(inner.headerList, guard);
diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js
index dc4e75434..73a90166d 100644
--- a/ext/fetch/23_response.js
+++ b/ext/fetch/23_response.js
@@ -60,6 +60,7 @@ const _response = Symbol("response");
const _headers = Symbol("headers");
const _mimeType = Symbol("mime type");
const _body = Symbol("body");
+const _brand = webidl.brand;
/**
* @typedef InnerResponse
@@ -305,6 +306,11 @@ class Response {
* @param {ResponseInit} init
*/
constructor(body = null, init = undefined) {
+ if (body === _brand) {
+ this[_brand] = _brand;
+ return;
+ }
+
const prefix = "Failed to construct 'Response'";
body = webidl.converters["BodyInit_DOMString?"](body, prefix, "Argument 1");
init = webidl.converters["ResponseInit_fast"](init, prefix, "Argument 2");
@@ -320,7 +326,7 @@ class Response {
bodyWithType = extractBody(body);
}
initializeAResponse(this, init, bodyWithType);
- this[webidl.brand] = webidl.brand;
+ this[_brand] = _brand;
}
/**
@@ -489,7 +495,7 @@ function toInnerResponse(response) {
* @returns {Response}
*/
function fromInnerResponse(inner, guard) {
- const response = webidl.createBranded(Response);
+ const response = new Response(_brand);
response[_response] = inner;
response[_headers] = headersFromHeaderList(inner.headerList, guard);
return response;