diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp
index 5af7d6cf75387..c80d4e6298010 100644
--- a/dom/html/HTMLDialogElement.cpp
+++ b/dom/html/HTMLDialogElement.cpp
@@ -71,7 +71,11 @@ void HTMLDialogElement::Close(
void HTMLDialogElement::Show(ErrorResult& aError) {
if (Open()) {
- return;
+ if (!IsInTopLayer()) {
+ return;
+ }
+ return aError.ThrowInvalidStateError(
+ "Cannot call show() on an open modal dialog.");
}
if (IsPopoverOpen()) {
@@ -121,13 +125,16 @@ void HTMLDialogElement::UnbindFromTree(bool aNullParent) {
}
void HTMLDialogElement::ShowModal(ErrorResult& aError) {
- if (!IsInComposedDoc()) {
- return aError.ThrowInvalidStateError("Dialog element is not connected");
- }
-
if (Open()) {
+ if (IsInTopLayer()) {
+ return;
+ }
return aError.ThrowInvalidStateError(
- "Dialog element already has an 'open' attribute");
+ "Cannot call showModal() on an open non-modal dialog.");
+ }
+
+ if (!IsInComposedDoc()) {
+ return aError.ThrowInvalidStateError("Dialog element is not connected");
}
if (IsPopoverOpen()) {
diff --git a/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-no-throw-requested-state.html.ini b/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-no-throw-requested-state.html.ini
deleted file mode 100644
index d1af0a488be0f..0000000000000
--- a/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-no-throw-requested-state.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[dialog-no-throw-requested-state.html]
- [dialog-no-throw-requested-state]
- expected: FAIL