summaryrefslogtreecommitdiff
path: root/ext/fetch/23_response.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-11 23:43:52 +0200
committerGitHub <noreply@github.com>2021-10-11 23:43:52 +0200
commit5bad8e17734ef8cc1f19df292d553cc1327638f3 (patch)
tree618fb5588aca5924686b431d4cc9932d16584fa6 /ext/fetch/23_response.js
parent5508a0f45e233708f3a0a5fc9e9a48ab3c0fb33c (diff)
perf(webidl): inline ResponseInit converter (#12285)
Diffstat (limited to 'ext/fetch/23_response.js')
-rw-r--r--ext/fetch/23_response.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js
index 29a37ceca..5ff6e56c3 100644
--- a/ext/fetch/23_response.js
+++ b/ext/fetch/23_response.js
@@ -12,6 +12,7 @@
"use strict";
((window) => {
+ const { isProxy } = Deno.core;
const webidl = window.__bootstrap.webidl;
const consoleInternal = window.__bootstrap.console;
const { HTTP_TAB_OR_SPACE, regexMatcher } = window.__bootstrap.infra;
@@ -249,7 +250,7 @@
prefix,
context: "Argument 1",
});
- init = webidl.converters["ResponseInit"](init, {
+ init = webidl.converters["ResponseInit_fast"](init, {
prefix,
context: "Argument 2",
});
@@ -260,7 +261,10 @@
);
}
- if (!RegExpPrototypeTest(REASON_PHRASE_RE, init.statusText)) {
+ if (
+ init.statusText &&
+ !RegExpPrototypeTest(REASON_PHRASE_RE, init.statusText)
+ ) {
throw new TypeError("Status text is not valid.");
}
@@ -270,7 +274,7 @@
this[_response] = response;
/** @type {Headers} */
this[_headers] = headersFromHeaderList(response.headerList, "response");
- if (init.headers !== undefined) {
+ if (init.headers) {
fillHeaders(this[_headers], init.headers);
}
if (body !== null) {
@@ -407,6 +411,27 @@
converter: webidl.converters["HeadersInit"],
}],
);
+ webidl.converters["ResponseInit_fast"] = function (init, opts) {
+ if (init === undefined || init === null) {
+ return { status: 200, statusText: "", headers: undefined };
+ }
+ // Fast path, if not a proxy
+ if (typeof init === "object" && !isProxy(init)) {
+ // Not a proxy fast path
+ const status = init.status !== undefined
+ ? webidl.converters["unsigned short"](init.status)
+ : 200;
+ const statusText = init.statusText !== undefined
+ ? webidl.converters["ByteString"](init.statusText)
+ : "";
+ const headers = init.headers !== undefined
+ ? webidl.converters["HeadersInit"](init.headers)
+ : undefined;
+ return { status, statusText, headers };
+ }
+ // Slow default path
+ return webidl.converters["ResponseInit"](init, opts);
+ };
/**
* @param {Response} response