Skip to content

Commit 4fbe064

Browse files
targosbengl
authored andcommitted
lib: add FormData global when fetch is enabled
PR-URL: #41956 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent ce23738 commit 4fbe064

File tree

8 files changed

+24
-1
lines changed

8 files changed

+24
-1
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ module.exports = {
319319
Crypto: 'readable',
320320
CryptoKey: 'readable',
321321
fetch: 'readable',
322+
FormData: 'readable',
322323
globalThis: 'readable',
323324
Response: 'readable',
324325
SubtleCrypto: 'readable',

doc/api/globals.md

+11
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ added: v17.5.0
363363
364364
A browser-compatible implementation of the [`fetch()`][] function.
365365

366+
## Class `FormData`
367+
368+
<!-- YAML
369+
added: REPLACEME
370+
-->
371+
372+
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
373+
> CLI flag.
374+
375+
A browser-compatible implementation of {FormData}.
376+
366377
## `global`
367378

368379
<!-- YAML

lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ rules:
4747
message: Use `const { Event } = require('internal/event_target');` instead of the global.
4848
- name: EventTarget
4949
message: Use `const { EventTarget } = require('internal/event_target');` instead of the global.
50+
- name: FormData
51+
message: Use `const { FormData } = require('internal/deps/undici/undici');` instead of the global.
5052
- name: Headers
5153
message: Use `const { Headers } = require('internal/deps/undici/undici');` instead of the global.
5254
# Intl is not available in primordials because it can be

lib/internal/bootstrap/pre_execution.js

+6
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ function setupFetch() {
163163
configurable: true,
164164
value: undici.fetch
165165
});
166+
ObjectDefineProperty(globalThis, 'FormData', {
167+
writable: true,
168+
enumerable: false,
169+
configurable: true,
170+
value: undici.FormData
171+
});
166172
ObjectDefineProperty(globalThis, 'Headers', {
167173
writable: true,
168174
enumerable: false,

test/common/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ if (global.structuredClone) {
303303
if (global.fetch) {
304304
knownGlobals.push(
305305
global.fetch,
306+
global.FormData,
306307
global.Request,
307308
global.Response,
308309
global.Headers,

test/parallel/test-fetch.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import events from 'events';
77
import http from 'http';
88

99
assert.strictEqual(typeof globalThis.fetch, 'function');
10+
assert.strictEqual(typeof globalThis.FormData, 'function');
1011
assert.strictEqual(typeof globalThis.Headers, 'function');
1112
assert.strictEqual(typeof globalThis.Request, 'function');
1213
assert.strictEqual(typeof globalThis.Response, 'function');

test/wpt/test-url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runner.setScriptModifier((obj) => {
1111
// created via `document.createElement`. So we need to ignore them and just
1212
// test `URL`.
1313
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
14-
} else if (typeof FormData === 'undefined' && // eslint-disable-line
14+
} else if (typeof FormData === 'undefined' &&
1515
obj.filename.includes('urlsearchparams-constructor.any.js')) {
1616
// TODO(XadillaX): Remove this `else if` after `FormData` is supported.
1717

tools/doc/type-parser.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ const customTypesMap = {
271271
'TextDecoderStream':
272272
'webstreams.md#class-textdecoderstream',
273273

274+
'FormData': 'https://developer.mozilla.org/en-US/docs/Web/API/FormData',
274275
'Headers': 'https://developer.mozilla.org/en-US/docs/Web/API/Headers',
275276
'Response': 'https://developer.mozilla.org/en-US/docs/Web/API/Response',
276277
'Request': 'https://developer.mozilla.org/en-US/docs/Web/API/Request',

0 commit comments

Comments
 (0)