Bug 1551758 - Form submission reentrancy protection for 'submit' and 'invalid' event; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D53696

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Dai 2019-11-20 19:39:38 +00:00
Родитель 3c293b08a8
Коммит fd9869d4f3
4 изменённых файлов: 28 добавлений и 4 удалений

Просмотреть файл

@ -119,7 +119,8 @@ HTMLFormElement::HTMLFormElement(
mNotifiedObservers(false),
mNotifiedObserversResult(false),
mEverTriedInvalidSubmit(false),
mIsConstructingEntryList(false) {
mIsConstructingEntryList(false),
mIsFiringSubmissionEvents(false) {
// We start out valid.
AddStatesSilently(NS_EVENT_STATE_VALID);
}
@ -236,6 +237,15 @@ void HTMLFormElement::MaybeSubmit(Element* aSubmitter) {
return;
}
// 6.1. If form's firing submission events is true, then return.
if (mIsFiringSubmissionEvents) {
return;
}
// 6.2. Set form's firing submission events to true.
AutoRestore<bool> resetFiringSubmissionEventsFlag(mIsFiringSubmissionEvents);
mIsFiringSubmissionEvents = true;
// 6.3. If the submitter element's no-validate state is false, then
// interactively validate the constraints of form and examine the result.
// If the result is negative (i.e., the constraint validation concluded

Просмотреть файл

@ -616,6 +616,8 @@ class HTMLFormElement final : public nsGenericHTMLElement,
bool mEverTriedInvalidSubmit;
/** Whether we are constructing entry list */
bool mIsConstructingEntryList;
/** Whether we are firing submission event */
bool mIsFiringSubmissionEvents;
private:
NotNull<const Encoding*> GetSubmitEncoding();

Просмотреть файл

@ -1,7 +1,4 @@
[form-submission-algorithm.html]
[If form's firing submission events is true, then return; 'invalid' event]
expected: FAIL
[firing an event named submit; form.requestSubmit(submitter)]
expected: FAIL

Просмотреть файл

@ -18,6 +18,21 @@ test(() => {
assert_equals(counter, 2);
}, 'If constructing entry list flag of form is true, then return');
test(() => {
let form = populateForm('<input><input type=submit>');
let submitter1 = form.querySelector('input[type=submit]');
let valid = form.elements[0];
let counter = 0;
valid.oninvalid = () => {
++counter;
};
form.onsubmit = () => {
valid.required = true;
submitter1.dispatchEvent(new MouseEvent("click"));
};
submitter1.dispatchEvent(new MouseEvent("click"));
assert_equals(counter, 0);
}, "If firing submission events flag of form is true, then return");
test(() => {
let form = populateForm('<input required><input type=submit><button type=submit></button>');