Skip to content

Commit 647805a

Browse files
targosdanielleadams
authored andcommitted
lib: add FormData global when fetch is enabled
PR-URL: #41956 Backport-PR-URL: #42727 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 c64b038 commit 647805a

File tree

8 files changed

+29
-0
lines changed

8 files changed

+29
-0
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ module.exports = {
335335
atob: 'readable',
336336
performance: 'readable',
337337
fetch: 'readable',
338+
FormData: 'readable',
338339
Headers: 'readable',
339340
Request: 'readable',
340341
Response: 'readable',

doc/api/globals.md

+11
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ added: REPLACEME
306306
307307
A browser-compatible implementation of the [`fetch()`][] function.
308308

309+
## Class `FormData`
310+
311+
<!-- YAML
312+
added: REPLACEME
313+
-->
314+
315+
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
316+
> CLI flag.
317+
318+
A browser-compatible implementation of {FormData}.
319+
309320
## `global`
310321

311322
<!-- YAML

lib/.eslintrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ rules:
4343
message: "Use `const { Event } = require('internal/event_target');` instead of the global."
4444
- name: EventTarget
4545
message: "Use `const { EventTarget } = require('internal/event_target');` instead of the global."
46+
- name: FormData
47+
message: "Use `const { FormData } = require('internal/deps/undici/undici');` instead of the global."
48+
- name: Headers
49+
message: "Use `const { Headers } = require('internal/deps/undici/undici');` instead of the global."
4650
# Intl is not available in primordials because it can be
4751
# disabled with --without-intl build flag.
4852
- name: Intl

lib/internal/bootstrap/pre_execution.js

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function setupFetch() {
157157

158158
const undici = require('internal/deps/undici/undici');
159159
defineOperation(globalThis, 'fetch', undici.fetch);
160+
exposeInterface(globalThis, 'FormData', undici.FormData);
160161
exposeInterface(globalThis, 'Headers', undici.Headers);
161162
exposeInterface(globalThis, 'Request', undici.Request);
162163
exposeInterface(globalThis, 'Response', undici.Response);

test/common/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ if (global.PerformanceMeasure) {
296296
if (global.fetch) {
297297
knownGlobals.push(
298298
global.fetch,
299+
global.FormData,
299300
global.Request,
300301
global.Response,
301302
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

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ runner.setScriptModifier((obj) => {
2121
// created via `document.createElement`. So we need to ignore them and just
2222
// test `URL`.
2323
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
24+
} else if (typeof FormData === 'undefined' &&
25+
obj.filename.includes('urlsearchparams-constructor.any.js')) {
26+
// TODO(XadillaX): Remove this `else if` after `FormData` is supported.
27+
28+
// Ignore test named `URLSearchParams constructor, FormData.` because we do
29+
// not have `FormData`.
30+
obj.code = obj.code.replace(
31+
/('URLSearchParams constructor, object\.'\);[\w\W]+)test\(function\(\) {[\w\W]*?}, 'URLSearchParams constructor, FormData\.'\);/,
32+
'$1');
2433
}
2534
});
2635
runner.pretendGlobalThisAs('Window');

tools/doc/type-parser.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ const customTypesMap = {
266266
'TextDecoderStream':
267267
'webstreams.md#class-textdecoderstream',
268268

269+
'FormData': 'https://developer.mozilla.org/en-US/docs/Web/API/FormData',
269270
'Headers': 'https://developer.mozilla.org/en-US/docs/Web/API/Headers',
270271
'Response': 'https://developer.mozilla.org/en-US/docs/Web/API/Response',
271272
'Request': 'https://developer.mozilla.org/en-US/docs/Web/API/Request',

0 commit comments

Comments
 (0)