Skip to content

Commit

Permalink
lib: add FormData global when fetch is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Feb 18, 2022
1 parent 82f6b0c commit 247b887
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -319,6 +319,7 @@ module.exports = {
Crypto: 'readable',
CryptoKey: 'readable',
fetch: 'readable',
FormData: 'readable',
globalThis: 'readable',
Response: 'readable',
SubtleCrypto: 'readable',
Expand Down
11 changes: 11 additions & 0 deletions doc/api/globals.md
Expand Up @@ -389,6 +389,17 @@ added: v17.5.0
A browser-compatible implementation of the [`fetch()`][] function.

## Class `FormData`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental. Enable this API with the [`--experimental-fetch`][]
> CLI flag.
A browser-compatible implementation of {FormData}.

## `global`

<!-- YAML
Expand Down
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Expand Up @@ -49,6 +49,8 @@ rules:
message: Use `const { Event } = require('internal/event_target');` instead of the global.
- name: EventTarget
message: Use `const { EventTarget } = require('internal/event_target');` instead of the global.
- name: FormData
message: Use `const { FormData } = require('internal/deps/undici/undici');` instead of the global.
- name: Headers
message: Use `const { Headers } = require('internal/deps/undici/undici');` instead of the global.
# Intl is not available in primordials because it can be
Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/pre_execution.js
Expand Up @@ -160,6 +160,7 @@ function setupFetch() {

const undici = require('internal/deps/undici/undici');
defineOperation(globalThis, 'fetch', undici.fetch);
exposeInterface(globalThis, 'FormData', undici.FormData);
exposeInterface(globalThis, 'Headers', undici.Headers);
exposeInterface(globalThis, 'Request', undici.Request);
exposeInterface(globalThis, 'Response', undici.Response);
Expand Down
1 change: 1 addition & 0 deletions test/common/index.js
Expand Up @@ -303,6 +303,7 @@ if (global.structuredClone) {
if (global.fetch) {
knownGlobals.push(
global.fetch,
global.FormData,
global.Request,
global.Response,
global.Headers,
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-fetch.mjs
Expand Up @@ -7,6 +7,7 @@ import events from 'events';
import http from 'http';

assert.strictEqual(typeof globalThis.fetch, 'function');
assert.strictEqual(typeof globalThis.FormData, 'function');
assert.strictEqual(typeof globalThis.Headers, 'function');
assert.strictEqual(typeof globalThis.Request, 'function');
assert.strictEqual(typeof globalThis.Response, 'function');
Expand Down
2 changes: 1 addition & 1 deletion test/wpt/test-url.js
Expand Up @@ -11,7 +11,7 @@ runner.setScriptModifier((obj) => {
// created via `document.createElement`. So we need to ignore them and just
// test `URL`.
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
} else if (typeof FormData === 'undefined' && // eslint-disable-line
} else if (typeof FormData === 'undefined' &&
obj.filename.includes('urlsearchparams-constructor.any.js')) {
// TODO(XadillaX): Remove this `else if` after `FormData` is supported.

Expand Down
1 change: 1 addition & 0 deletions tools/doc/type-parser.mjs
Expand Up @@ -271,6 +271,7 @@ const customTypesMap = {
'TextDecoderStream':
'webstreams.md#class-textdecoderstream',

'FormData': 'https://developer.mozilla.org/en-US/docs/Web/API/FormData',
'Headers': 'https://developer.mozilla.org/en-US/docs/Web/API/Headers',
'Response': 'https://developer.mozilla.org/en-US/docs/Web/API/Response',
'Request': 'https://developer.mozilla.org/en-US/docs/Web/API/Request',
Expand Down

0 comments on commit 247b887

Please sign in to comment.