зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1812696 - Implement FormData constructor submitter parameter r=webidl,smaug
Also improve error messages for current submitter validations Spec PR: https://github.com/whatwg/xhr/pull/366 WPT PR: https://github.com/web-platform-tests/wpt/pull/37895 Differential Revision: https://phabricator.services.mozilla.com/D167576
This commit is contained in:
Родитель
63cfae170f
Коммит
159a19ad5c
|
@ -10,6 +10,8 @@
|
|||
#include "mozilla/dom/Directory.h"
|
||||
#include "mozilla/dom/HTMLFormElement.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsQueryObject.h"
|
||||
|
||||
#include "MultipartBlobImpl.h"
|
||||
|
||||
|
@ -298,12 +300,37 @@ JSObject* FormData::WrapObject(JSContext* aCx,
|
|||
return FormData_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#dom-formdata
|
||||
/* static */
|
||||
already_AddRefed<FormData> FormData::Constructor(
|
||||
const GlobalObject& aGlobal,
|
||||
const Optional<NonNull<HTMLFormElement> >& aFormElement, ErrorResult& aRv) {
|
||||
RefPtr<FormData> formData = new FormData(aGlobal.GetAsSupports());
|
||||
const Optional<NonNull<HTMLFormElement> >& aFormElement,
|
||||
nsGenericHTMLElement* aSubmitter, ErrorResult& aRv) {
|
||||
RefPtr<FormData> formData;
|
||||
// 1. If form is given, then:
|
||||
if (aFormElement.WasPassed()) {
|
||||
// 1.1. If submitter is non-null, then:
|
||||
if (aSubmitter) {
|
||||
nsCOMPtr<nsIFormControl> fc = do_QueryObject(aSubmitter);
|
||||
|
||||
// 1.1.1. If submitter is not a submit button, then throw a TypeError.
|
||||
if (!fc || !fc->IsSubmitControl()) {
|
||||
aRv.ThrowTypeError("The submitter is not a submit button.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 1.1.2. If submitter's form owner is not this form element, then throw a
|
||||
// "NotFoundError" DOMException.
|
||||
if (fc->GetForm() != &aFormElement.Value()) {
|
||||
aRv.ThrowNotFoundError("The submitter is not owned by this form.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// 1.2. Let list be the result of constructing the entry list for form and
|
||||
// submitter.
|
||||
formData =
|
||||
new FormData(aGlobal.GetAsSupports(), UTF_8_ENCODING, aSubmitter);
|
||||
aRv = aFormElement.Value().ConstructEntryList(formData);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
|
@ -312,6 +339,8 @@ already_AddRefed<FormData> FormData::Constructor(
|
|||
// Step 9. Return a shallow clone of entry list.
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
|
||||
formData = formData->Clone();
|
||||
} else {
|
||||
formData = new FormData(aGlobal.GetAsSupports());
|
||||
}
|
||||
|
||||
return formData.forget();
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/HTMLFormSubmission.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/FormDataBinding.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
|
@ -69,7 +70,7 @@ class FormData final : public nsISupports,
|
|||
static already_AddRefed<FormData> Constructor(
|
||||
const GlobalObject& aGlobal,
|
||||
const Optional<NonNull<HTMLFormElement> >& aFormElement,
|
||||
ErrorResult& aRv);
|
||||
nsGenericHTMLElement* aSubmitter, ErrorResult& aRv);
|
||||
|
||||
void Append(const nsAString& aName, const nsAString& aValue,
|
||||
ErrorResult& aRv);
|
||||
|
|
|
@ -296,7 +296,7 @@ void HTMLFormElement::RequestSubmit(nsGenericHTMLElement* aSubmitter,
|
|||
// 1.2. If submitter's form owner is not this form element, then throw a
|
||||
// "NotFoundError" DOMException.
|
||||
if (fc->GetForm() != this) {
|
||||
aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
|
||||
aRv.ThrowNotFoundError("The submitter is not owned by this form.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ typedef (Blob or Directory or USVString) FormDataEntryValue;
|
|||
[Exposed=(Window,Worker)]
|
||||
interface FormData {
|
||||
[Throws]
|
||||
constructor(optional HTMLFormElement form);
|
||||
constructor(optional HTMLFormElement form, optional HTMLElement? submitter = null);
|
||||
|
||||
[Throws]
|
||||
undefined append(USVString name, Blob value, optional USVString filename);
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
[constructor-submitter.html]
|
||||
[FormData construction should throw a TypeError if a non-null submitter is not a submit button]
|
||||
expected: FAIL
|
||||
|
||||
[FormData construction should throw a 'NotFoundError' DOMException if a non-null submitter is not owned by the form]
|
||||
expected: FAIL
|
||||
|
||||
[The constructed FormData object should contain an in-tree-order entry for a named submit button submitter]
|
||||
expected: FAIL
|
||||
|
||||
[The constructed FormData object should contain in-tree-order entries for an activated Image Button submitter]
|
||||
expected: FAIL
|
||||
|
||||
[The constructed FormData object should contain in-tree-order entries for an unactivated Image Button submitter]
|
||||
expected: FAIL
|
Загрузка…
Ссылка в новой задаче