From 8cbe612512c81c0353fc4a0b9d9d9d28db7096c2 Mon Sep 17 00:00:00 2001 From: Rob Buis Date: Thu, 23 Mar 2023 12:18:15 -0700 Subject: [PATCH] [popover] Handle showPopover changing popover attribute during beforetoggle https://bugs.webkit.org/show_bug.cgi?id=254268 Reviewed by Tim Nguyen. Handle showPopover changing popover attribute during beforetoggle by throwing an exception: https://github.com/whatwg/html/pull/9058 * LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt: * LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt: * Source/WebCore/html/HTMLElement.cpp: (WebCore::HTMLElement::showPopover): Canonical link: https://commits.webkit.org/262026@main --- .../semantics/popovers/popover-attribute-basic-expected.txt | 2 +- .../semantics/popovers/popover-attribute-basic-expected.txt | 2 +- Source/WebCore/html/HTMLElement.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt index 9da2aebf0c9d3..e69fdfadf1719 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt @@ -25,7 +25,7 @@ PASS Removing a visible popover=auto element from the document should close the PASS A showing popover=auto does not match :modal PASS Removing a visible popover=manual element from the document should close the popover PASS A showing popover=manual does not match :modal -FAIL Changing the popover type in a "beforetoggle" event handler should throw an exception (during showPopover()) assert_throws_dom: function "() => popover.showPopover()" did not throw +PASS Changing the popover type in a "beforetoggle" event handler should throw an exception (during showPopover()) PASS Changing the popover type in a "beforetoggle" event handler should throw an exception (during hidePopover()) PASS Changing a popover from auto to auto (via attr), and then auto during 'beforetoggle' works PASS Changing a popover from auto to auto (via attr), and then manual during 'beforetoggle' works diff --git a/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt b/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt index 953310b92d3ef..0045946556022 100644 --- a/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt +++ b/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic-expected.txt @@ -25,7 +25,7 @@ PASS Removing a visible popover=auto element from the document should close the PASS A showing popover=auto does not match :modal PASS Removing a visible popover=manual element from the document should close the popover PASS A showing popover=manual does not match :modal -FAIL Changing the popover type in a "beforetoggle" event handler should throw an exception (during showPopover()) assert_throws_dom: function "() => popover.showPopover()" did not throw +PASS Changing the popover type in a "beforetoggle" event handler should throw an exception (during showPopover()) PASS Changing the popover type in a "beforetoggle" event handler should throw an exception (during hidePopover()) PASS Changing a popover from auto to auto (via attr), and then auto during 'beforetoggle' works PASS Changing a popover from auto to auto (via attr), and then manual during 'beforetoggle' works diff --git a/Source/WebCore/html/HTMLElement.cpp b/Source/WebCore/html/HTMLElement.cpp index ae44394c8a234..05ad5cc11aec8 100644 --- a/Source/WebCore/html/HTMLElement.cpp +++ b/Source/WebCore/html/HTMLElement.cpp @@ -1344,7 +1344,7 @@ ExceptionOr HTMLElement::showPopover() document().hideAllPopoversUntil(ancestor.get(), FocusPreviousElement::No, FireEvents::Yes); if (popoverState() != originalState) - return { }; + return Exception { InvalidStateError, "The value of the popover attribute was changed while hiding the popover."_s }; if (auto check = checkPopoverValidity(*this, PopoverVisibilityState::Hidden); check.hasException()) return check.releaseException();