8000 Allow self to be passed as validation anchor · WebKit/WebKit@f04ebd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f04ebd9

Browse files
committed
Allow self to be passed as validation anchor
https://bugs.webkit.org/show_bug.cgi?id=294903 Reviewed by Ryosuke Niwa. In 292770@main we made the control the fallback when the validation anchor was not given. This created a slight inconsistency with the API which would throw if you passed the control as validation anchor. This changes the API to allow passing the control as per step 8 of https://html.spec.whatwg.org/multipage/custom-elements.html#dom-elementinternals-setvalidity (Note that the specification implements the fallback as part of the API call, but that is not how we implement it.) Test changes are already upstreamed: web-platform-tests/wpt#53353 Canonical link: https://commits.webkit.org/296622@main
1 parent 2b981ab commit f04ebd9

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

LayoutTests/imported/w3c/web-platform-tests/custom-elements/form-associated/ElementInternals-validation-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PASS willValidate should throw NotSupportedError if the target element is not a
77
PASS validity and set 10BC0 Validity()
88
PASS validity.customError should be false if not explicitly set via setValidity()
99
PASS "anchor" argument of setValidity()
10+
PASS "anchor" argument of setValidity(): passing self
1011
PASS checkValidity() should throw NotSupportedError if the target element is not a form-associated custom element
1112
PASS checkValidity()
1213
PASS reportValidity() should throw NotSupportedError if the target element is not a form-associated custom element

LayoutTests/imported/w3c/web-platform-tests/custom-elements/form-associated/ElementInternals-validation.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@
207207
control.i.setValidity(flags, m, document.body);
208208
}, 'Not a descendant');
209209

210-
assert_throws_dom('NotFoundError', () => {
211-
control.i.setValidity(flags, m, control);
212-
}, 'Self');
213-
214210
let notHTMLElement = document.createElementNS('some-random-namespace', 'foo');
215211
control.appendChild(notHTMLElement);
216212
assert_throws_js(TypeError, () => {
@@ -234,6 +230,17 @@
234230
control.i.setValidity(flags, m, nestedShadowChild);
235231
}, '"anchor" argument of setValidity()');
236232

233+
test(t => {
234+
const control = document.createElement('my-control');
235+
document.body.appendChild(control);
236+
t.add_cleanup(() => control.remove());
237+
const flags = {valueMissing: true};
238+
const m = 'non-empty message';
239+
240+
// Self
241+
control.i.setValidity(flags, m, control);
242+
}, '"anchor" argument of setValidity(): passing self');
243+
237244
test(() => {
238245
const element = new NotFormAssociatedElement();
239246
assert_throws_dom('NotSupportedError', () => element.i.checkValidity());

LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/custom-elements/form-associated/ElementInternals-validation-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PASS willValidate should throw NotSupportedError if the target element is not a
77
PASS validity and setValidity()
88
PASS validity.customError should be false if not explicitly set via setValidity()
99
PASS "anchor" argument of setValidity()
10+
PASS "anchor" argument of setValidity(): passing self
1011
PASS checkValidity() should throw NotSupportedError if the target element is not a form-associated custom element
1112
PASS checkValidity()
1213
PASS reportValidity() should throw NotSupportedError if the target element is not a form-associated custom element

Source/WebCore/html/FormAssociatedCustomElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ExceptionOr<void> FormAssociatedCustomElement::setValidity(ValidityStateFlags va
6868
m_validityStateFlags = validityStateFlags;
6969
setCustomValidity(validityStateFlags.isValid() ? emptyString() : WTFMove(message));
7070

71-
if (validationAnchor && !validationAnchor->isShadowIncludingDescendantOf(*m_element))
71+
if (validationAnchor && !m_element->isShadowIncludingInclusiveAncestorOf(*validationAnchor))
7272
return Exception { ExceptionCode::NotFoundError };
7373

7474
m_validationAnchor = validationAnchor;

0 commit comments

Comments
 (0)
0