summaryrefslogtreecommitdiff
path: root/ext/fetch/21_formdata.js
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2022-10-05 18:31:36 +0200
committerGitHub <noreply@github.com>2022-10-05 12:31:36 -0400
commitb487027b4576332a0f0f818e7e8feda5dcc04d15 (patch)
tree554ac2cd27ceaba6f24ca55ac4042a5d498e026f /ext/fetch/21_formdata.js
parent0b016a7fb8639ce49603c8c339539174b191a4b1 (diff)
refactor(ext/fetch): simplify parseContentDisposition (#16162)
Replaced `forEach`, `map`, `filter`, `map` with a single `for` loop
Diffstat (limited to 'ext/fetch/21_formdata.js')
-rw-r--r--ext/fetch/21_formdata.js28
1 files changed, 11 insertions, 17 deletions
diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js
index 72f83a860..5532cc5a3 100644
--- a/ext/fetch/21_formdata.js
+++ b/ext/fetch/21_formdata.js
@@ -16,12 +16,9 @@
const { Blob, BlobPrototype, File, FilePrototype } =
globalThis.__bootstrap.file;
const {
- ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
- ArrayPrototypeFilter,
- ArrayPrototypeForEach,
Map,
MapPrototypeGet,
MapPrototypeSet,
@@ -335,20 +332,17 @@
/** @type {Map<string, string>} */
const params = new Map();
// Forced to do so for some Map constructor param mismatch
- ArrayPrototypeForEach(
- ArrayPrototypeMap(
- ArrayPrototypeFilter(
- ArrayPrototypeMap(
- ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1),
- (s) => StringPrototypeSplit(StringPrototypeTrim(s), "="),
- ),
- (arr) => arr.length > 1,
- ),
- ([k, v]) => [k, StringPrototypeReplace(v, /^"([^"]*)"$/, "$1")],
- ),
- ([k, v]) => MapPrototypeSet(params, k, v),
- );
-
+ const values = ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1);
+ for (let i = 0; i < values.length; i++) {
+ const entries = StringPrototypeSplit(StringPrototypeTrim(values[i]), "=");
+ if (entries.length > 1) {
+ MapPrototypeSet(
+ params,
+ entries[0],
+ StringPrototypeReplace(entries[1], /^"([^"]*)"$/, "$1"),
+ );
+ }
+ }
return params;
}