Skip to content

Commit adbee9d

Browse files
committed
fix: setup entries before going through form
Signed-off-by: Logan McAnsh <[email protected]>
1 parent c96e157 commit adbee9d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/form-data/src/form-data.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ export class FormData {
66
* @param {HTMLFormElement} [form]
77
*/
88
constructor(form) {
9+
/**
10+
* @private
11+
* @readonly
12+
* @type {Array<[string, FormDataEntryValue]>}
13+
*/
14+
this._entries = [];
15+
16+
Object.defineProperty(this, "_entries", { enumerable: false });
17+
918
if (form !== undefined) {
1019
for (const element of form.elements) {
1120
if (isSelectElement(element)) {
@@ -23,15 +32,6 @@ export class FormData {
2332
}
2433
}
2534
}
26-
27-
/**
28-
* @private
29-
* @readonly
30-
* @type {Array<[string, FormDataEntryValue]>}
31-
*/
32-
this._entries = [];
33-
34-
Object.defineProperty(this, "_entries", { enumerable: false });
3535
}
3636
get [Symbol.toStringTag]() {
3737
return "FormData";
@@ -60,6 +60,9 @@ export class FormData {
6060
),
6161
filename
6262
) {
63+
if (!this._entries) {
64+
throw new Error("FormData.append: missing entries...");
65+
}
6366
this._entries.push([name, toEntryValue(value, filename)]);
6467
}
6568

0 commit comments

Comments
 (0)