@@ -4,10 +4,16 @@ const { iteratorMixin } = require('./util')
44const { kEnumerableProperty } = require ( '../../core/util' )
55const { webidl } = require ( '../webidl' )
66const nodeUtil = require ( 'node:util' )
7+ const { runtimeFeatures } = require ( '../../util/runtime-features.js' )
8+
9+ const random = runtimeFeatures . has ( 'crypto' )
10+ ? require ( 'node:crypto' ) . randomInt
11+ : ( max ) => Math . floor ( Math . random ( ) * max )
712
813// https://xhr.spec.whatwg.org/#formdata
914class FormData {
1015 #state = [ ]
16+ #boundary = null
1117
1218 constructor ( form = undefined ) {
1319 webidl . util . markAsUncloneable ( this )
@@ -192,11 +198,24 @@ class FormData {
192198 static setFormDataState ( formData , newState ) {
193199 formData . #state = newState
194200 }
201+
202+ /**
203+ * @param {FormData } formData
204+ * @returns {string | null }
205+ */
206+ static getFormDataBoundary ( formData ) {
207+ const boundary = formData . #boundary
208+ if ( boundary != null ) return boundary
209+
210+ // eslint-disable-next-line no-return-assign
211+ return formData . #boundary = `----formdata-undici-0${ `${ random ( 1e11 ) } ` . padStart ( 11 , '0' ) } `
212+ }
195213}
196214
197- const { getFormDataState, setFormDataState } = FormData
215+ const { getFormDataState, setFormDataState, getFormDataBoundary } = FormData
198216Reflect . deleteProperty ( FormData , 'getFormDataState' )
199217Reflect . deleteProperty ( FormData , 'setFormDataState' )
218+ Reflect . deleteProperty ( FormData , 'getFormDataBoundary' )
200219
201220iteratorMixin ( 'FormData' , FormData , getFormDataState , 'name' , 'value' )
202221
@@ -256,4 +275,4 @@ function makeEntry (name, value, filename) {
256275
257276webidl . is . FormData = webidl . util . MakeTypeAssertion ( FormData )
258277
259- module . exports = { FormData, makeEntry, setFormDataState }
278+ module . exports = { FormData, makeEntry, setFormDataState, getFormDataBoundary }
0 commit comments