Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3264a1

Browse files
committedFeb 16, 2022
lib: add FormData global when fetch is enabled
1 parent 551ca68 commit f3264a1

File tree

8 files changed

+19
-1
lines changed

8 files changed

+19
-1
lines changed
 

‎.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ module.exports = {
337337
performance: 'readable',
338338
structuredClone: 'readable',
339339
fetch: 'readable',
340+
FormData: 'readable',
340341
Headers: 'readable',
341342
Request: 'readable',
342343
Response: 'readable',

‎doc/api/globals.md

+11
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,17 @@ added: v17.5.0
389389
390390
A browser-compatible implementation of the [`fetch()`][] function.
391391

392+
## Class `FormData`
393+
394+
<!-- YAML
395+
added: REPLACEME
396+
-->
397+
398+
> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
399+
> CLI flag.
400+
401+
A browser-compatible implementation of {FormData}.
402+
392403
## `global`
393404

394405
<!-- YAML

‎lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rules:
4949
message: Use `const { Event } = require('internal/event_target');` instead of the global.
5050
- name: EventTarget
5151
message: Use `const { EventTarget } = require('internal/event_target');` instead of the global.
52+
- name: FormData
53+
message: Use `const { FormData } = require('internal/deps/undici/undici');` instead of the global.
5254
- name: Headers
5355
message: Use `const { Headers } = require('internal/deps/undici/undici');` instead of the global.
5456
# Intl is not available in primordials because it can be

‎lib/internal/bootstrap/pre_execution.js

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

160160
const undici = require('internal/deps/undici/undici');
161161
defineOperation(globalThis, 'fetch', undici.fetch);
162+
exposeInterface(globalThis, 'FormData', undici.FormData);
162163
exposeInterface(globalThis, 'Headers', undici.Headers);
163164
exposeInterface(globalThis, 'Request', undici.Request);
164165
exposeInterface(globalThis, 'Response', undici.Response);

‎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)
Please sign in to comment.