-
Notifications
You must be signed in to change notification settings - Fork 561
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
Support globalThis.FormData #3844
Conversation
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@@ -109,7 +109,7 @@ function extractBody (object, keepalive = false) { | |||
|
|||
// Set source to a copy of the bytes held by object. | |||
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength)) | |||
} else if (webidl.is.FormData(object)) { | |||
} else if (webidl.is.FormData(object) || (globalThis.FormData && object instanceof FormData)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (webidl.is.FormData(object) || (globalThis.FormData && object instanceof FormData)) { | |
} else if (webidl.is.FormData(object)) { |
@@ -258,6 +258,13 @@ function makeEntry (name, value, filename) { | |||
return { name, value } | |||
} | |||
|
|||
webidl.is.FormData = webidl.util.MakeTypeAssertion(FormData) | |||
const _isFormData = webidl.util.MakeTypeAssertion(FormData) | |||
webidl.is.FormData = function (V) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this?
// lib/web/fetch/webidl.js
webidl.util.MakeTypeAssertionMultiple = function (List) {
return (O) => List.some((I) => FunctionPrototypeSymbolHasInstance(I, O))
}
Usage:
webidl.is.FormData = webidl.util.MakeTypeAssertionMultiple([FormData, gloablThis.FormData].filter(Boolean))
I don't understand the need for this change, it's a known limitation that different versions of undici create different versions of classes. It's also a pain to deal with. Won't work: new Request(new globalThis.Request('http://a'))
await fetch(new globalThis.Request(...)) Works because of webidl:
|
Ok, let's close this. We would need to document this a bit better, as I suspect a flurry of issues. |
Since #3502, we only support our own classes, and that is the right move. However, we need to relax this condition to allow for
globalThis.FormData
, as that is a different copy of undici.In essence, this change make the following fork