Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add FormData global when fetch is enabled #41956

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ module.exports = {
Crypto: 'readable',
CryptoKey: 'readable',
fetch: 'readable',
FormData: 'readable',
targos marked this conversation as resolved.
Show resolved Hide resolved
globalThis: 'readable',
Response: 'readable',
SubtleCrypto: 'readable',
Expand Down
11 changes: 11 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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