Skip to content

Commit ec0d623

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 fe66d2b commit ec0d623

File tree

8 files changed

+24
-1
lines changed

8 files changed

+24
-1
lines changed

‎.eslintrc.js‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 11 additions & 0 deletions
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‎

Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 6 additions & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import events from 'events'
77
importhttpfrom'http';
88

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

‎test/wpt/test-url.js‎

Lines changed: 1 addition & 1 deletion
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-
}elseif(typeofFormData==='undefined'&&// eslint-disable-line
14+
}elseif(typeofFormData==='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‎

Lines changed: 1 addition & 0 deletions
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)