aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/webcore/JSDOMFormData.cpp
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-08-31 17:33:08 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-31 17:33:08 -0700
commitfef70f2473daefe242c80b9f3f34ef67396efaef (patch)
tree2f6dce4958d0a954115b6279deef418d9c8c340e /src/bun.js/bindings/webcore/JSDOMFormData.cpp
parentbd7262f037589a69be8b5fb2f705666309c32b86 (diff)
downloadbun-fef70f2473daefe242c80b9f3f34ef67396efaef.tar.gz
bun-fef70f2473daefe242c80b9f3f34ef67396efaef.tar.zst
bun-fef70f2473daefe242c80b9f3f34ef67396efaef.zip
get name if not provided in `FormData.append` (#4434)
* get file name from blob if not provided * add test * another test * format
Diffstat (limited to 'src/bun.js/bindings/webcore/JSDOMFormData.cpp')
-rw-r--r--src/bun.js/bindings/webcore/JSDOMFormData.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/bun.js/bindings/webcore/JSDOMFormData.cpp b/src/bun.js/bindings/webcore/JSDOMFormData.cpp
index 09a0a6c08..fdb71341c 100644
--- a/src/bun.js/bindings/webcore/JSDOMFormData.cpp
+++ b/src/bun.js/bindings/webcore/JSDOMFormData.cpp
@@ -286,6 +286,8 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_append1Body(JSC
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.append(WTFMove(name), WTFMove(value)); })));
}
+extern "C" BunString Blob__getFileNameString(void* impl);
+
static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_append2Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSDOMFormData>::ClassParameter castedThis)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
@@ -298,10 +300,6 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_append2Body(JSC
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1);
- EnsureStillAliveScope argument2 = callFrame->argument(2);
- auto filename = argument2.value().isUndefined() ? String() : convert<IDLUSVString>(*lexicalGlobalObject, argument2.value());
- RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
-
RefPtr<Blob> blobValue = nullptr;
if (argument1.value().inherits<JSBlob>()) {
blobValue = Blob::create(argument1.value());
@@ -312,6 +310,10 @@ static inline JSC::EncodedJSValue jsDOMFormDataPrototypeFunction_append2Body(JSC
}
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ EnsureStillAliveScope argument2 = callFrame->argument(2);
+ auto filename = argument2.value().isUndefined() ? Bun::toWTFString(Blob__getFileNameString(blobValue->impl())) : convert<IDLUSVString>(*lexicalGlobalObject, argument2.value());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.append(WTFMove(name), WTFMove(blobValue), WTFMove(filename)); })));
}