Bug 1652699 - Fix a null pointer crash while doing dialog form submission r=smaug

It's possible that the dialog is closed while we are processing
the request, and we'd deferencing a null pointer for such case.

Differential Revision: https://phabricator.services.mozilla.com/D83531
This commit is contained in:
Sean Feng 2020-07-14 21:19:10 +00:00
Родитель 8695ba2c43
Коммит 9cb69ecf75
2 изменённых файлов: 22 добавлений и 2 удалений

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

@ -830,7 +830,7 @@ nsresult HTMLFormSubmission::GetFromForm(HTMLFormElement* aForm,
// If there isn't one, or if it does not have an open attribute, do
// nothing.
if (!dialog || !dialog->Open()) {
return NS_OK;
return NS_ERROR_FAILURE;
}
nsAutoString result;

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

@ -9,7 +9,7 @@
<body>
<dialog id="favDialog">
<form method="dialog">
<form id="dialogForm" method="dialog">
<button id="confirmBtn" value="default">Confirm</button>
<input id="confirmImgBtn" src="./resources/submit.jpg" width="41"
height="41" type="image" alt="Hello">
@ -78,5 +78,25 @@ promise_test(async () => {
assert_false(dialog.open, "dialog should be closed now");
}, "formmethod attribute should use dialog form submission");
promise_test(async () => {
const dialog = document.querySelector('dialog');
dialog.returnValue = "";
dialog.showModal();
const button = document.querySelector('button');
button.value = "sushi";
const dialogForm = document.getElementById('dialogForm');
dialogForm.onsubmit = function() {
dialog.close();
}
button.click();
assert_false(dialog.open, "dialog should be closed now");
// If the submission request got processed, the returnValue should change
// to "sushi" because that's the value of the submitter
assert_equals(dialog.returnValue, "", "dialog's returnValue remains the same");
}, "closing the dialog while submitting should stop the submission");
</script>
</body>