mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
lib: add FormData global when fetch is enabled
PR-URL: https://github.com/nodejs/node/pull/41956 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
fe66d2b98c
commit
ec0d623bd7
8 files changed
+24
-1
No files matched your search
@@ -319,6 +319,7 @@ module.exports = {
|
||||
Crypto: 'readable',
|
||||
CryptoKey: 'readable',
|
||||
fetch: 'readable',
|
||||
FormData: 'readable',
|
||||
globalThis: 'readable',
|
||||
Response: 'readable',
|
||||
SubtleCrypto: 'readable',
|
||||
|
||||
@@ -363,6 +363,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
|
||||
|
||||
@@ -47,6 +47,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
|
||||
|
||||
@@ -163,6 +163,12 @@ function setupFetch() {
|
||||
configurable: true,
|
||||
value: undici.fetch
|
||||
});
|
||||
ObjectDefineProperty(globalThis, 'FormData', {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
value: undici.FormData
|
||||
});
|
||||
ObjectDefineProperty(globalThis, 'Headers', {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
|
||||
@@ -303,6 +303,7 @@ if (global.structuredClone) {
|
||||
if (global.fetch) {
|
||||
knownGlobals.push(
|
||||
global.fetch,
|
||||
global.FormData,
|
||||
global.Request,
|
||||
global.Response,
|
||||
global.Headers,
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user