refactor: use primordials in extensions/fetch (#11266)

This commit is contained in:
Satya Rohith 2021-07-06 15:02:59 +05:30 committed by GitHub
parent e8258e0210
commit ab6b0cefd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 307 additions and 134 deletions

View file

@ -26,6 +26,20 @@
} = window.__bootstrap.headers;
const { HttpClient } = window.__bootstrap.fetch;
const abortSignal = window.__bootstrap.abortSignal;
const {
ArrayPrototypeMap,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
MapPrototypeHas,
MapPrototypeGet,
MapPrototypeSet,
ObjectKeys,
RegExpPrototypeTest,
Symbol,
SymbolFor,
SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
const _request = Symbol("request");
const _headers = Symbol("headers");
@ -81,7 +95,9 @@
* @returns {InnerRequest}
*/
function cloneInnerRequest(request) {
const headerList = [...request.headerList.map((x) => [x[0], x[1]])];
const headerList = [
...ArrayPrototypeMap(request.headerList, (x) => [x[0], x[1]]),
];
let body = null;
if (request.body !== null) {
body = request.body.clone();
@ -129,7 +145,7 @@
}
// Regular path
if (!HTTP_TOKEN_CODE_POINT_RE.test(m)) {
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, m)) {
throw new TypeError("Method is not valid.");
}
const upperCase = byteUpperCase(m);
@ -166,14 +182,17 @@
mimeType = temporaryMimeType;
if (mimesniff.essence(mimeType) !== essence) {
charset = null;
const newCharset = mimeType.parameters.get("charset");
const newCharset = MapPrototypeGet(mimeType.parameters, "charset");
if (newCharset !== undefined) {
charset = newCharset;
}
essence = mimesniff.essence(mimeType);
} else {
if (mimeType.parameters.has("charset") === null && charset !== null) {
mimeType.parameters.set("charset", charset);
if (
MapPrototypeHas(mimeType.parameters, "charset") === null &&
charset !== null
) {
MapPrototypeSet(mimeType.parameters, "charset", charset);
}
}
}
@ -267,15 +286,17 @@
this[_headers] = headersFromHeaderList(request.headerList, "request");
// 32.
if (Object.keys(init).length > 0) {
let headers = headerListFromHeaders(this[_headers]).slice(
if (ObjectKeys(init).length > 0) {
let headers = ArrayPrototypeSlice(
headerListFromHeaders(this[_headers]),
0,
headerListFromHeaders(this[_headers]).length,
);
if (init.headers !== undefined) {
headers = init.headers;
}
headerListFromHeaders(this[_headers]).splice(
ArrayPrototypeSplice(
headerListFromHeaders(this[_headers]),
0,
headerListFromHeaders(this[_headers]).length,
);
@ -367,11 +388,11 @@
);
}
get [Symbol.toStringTag]() {
get [SymbolToStringTag]() {
return "Request";
}
[Symbol.for("Deno.customInspect")](inspect) {
[SymbolFor("Deno.customInspect")](inspect) {
const inner = {
bodyUsed: this.bodyUsed,
headers: this.headers,