Commit 4e094bff authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Form-associated custom elements: ElementInternals methods should throw...

Form-associated custom elements: ElementInternals methods should throw NotSupportedError instead of InvalidStateError

to match to the latest specification pull request [1].
Also, 'labels' attribute should throw a NotSupportedError.

[1] https://github.com/whatwg/html/pull/4383

Change-Id: Ie1679e0746d72d5f2c06423eba70d8f570b61911
Bug: 905922
Reviewed-on: https://chromium-review.googlesource.com/c/1491055
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635895}
parent ee572e99
...@@ -53,7 +53,7 @@ void ElementInternals::setFormValue(const FileOrUSVString& value, ...@@ -53,7 +53,7 @@ void ElementInternals::setFormValue(const FileOrUSVString& value,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return; return;
} }
...@@ -70,7 +70,7 @@ void ElementInternals::setFormValue(const FileOrUSVString& value, ...@@ -70,7 +70,7 @@ void ElementInternals::setFormValue(const FileOrUSVString& value,
HTMLFormElement* ElementInternals::form(ExceptionState& exception_state) const { HTMLFormElement* ElementInternals::form(ExceptionState& exception_state) const {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return nullptr; return nullptr;
} }
...@@ -87,7 +87,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags, ...@@ -87,7 +87,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return; return;
} }
...@@ -108,7 +108,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags, ...@@ -108,7 +108,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags,
bool ElementInternals::willValidate(ExceptionState& exception_state) const { bool ElementInternals::willValidate(ExceptionState& exception_state) const {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return false; return false;
} }
...@@ -118,7 +118,7 @@ bool ElementInternals::willValidate(ExceptionState& exception_state) const { ...@@ -118,7 +118,7 @@ bool ElementInternals::willValidate(ExceptionState& exception_state) const {
ValidityState* ElementInternals::validity(ExceptionState& exception_state) { ValidityState* ElementInternals::validity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return nullptr; return nullptr;
} }
...@@ -129,7 +129,7 @@ String ElementInternals::ValidationMessageForBinding( ...@@ -129,7 +129,7 @@ String ElementInternals::ValidationMessageForBinding(
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return String(); return String();
} }
...@@ -151,7 +151,7 @@ String ElementInternals::ValidationSubMessage() const { ...@@ -151,7 +151,7 @@ String ElementInternals::ValidationSubMessage() const {
bool ElementInternals::checkValidity(ExceptionState& exception_state) { bool ElementInternals::checkValidity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return false; return false;
} }
...@@ -161,14 +161,20 @@ bool ElementInternals::checkValidity(ExceptionState& exception_state) { ...@@ -161,14 +161,20 @@ bool ElementInternals::checkValidity(ExceptionState& exception_state) {
bool ElementInternals::reportValidity(ExceptionState& exception_state) { bool ElementInternals::reportValidity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) { if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element."); "The target element is not a form-associated custom element.");
return false; return false;
} }
return ListedElement::reportValidity(); return ListedElement::reportValidity();
} }
LabelsNodeList* ElementInternals::labels() { LabelsNodeList* ElementInternals::labels(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return nullptr;
}
return Target().labels(); return Target().labels();
} }
......
...@@ -43,7 +43,7 @@ class ElementInternals : public ScriptWrappable, public ListedElement { ...@@ -43,7 +43,7 @@ class ElementInternals : public ScriptWrappable, public ListedElement {
String ValidationMessageForBinding(ExceptionState& exception_state); String ValidationMessageForBinding(ExceptionState& exception_state);
bool checkValidity(ExceptionState& exception_state); bool checkValidity(ExceptionState& exception_state);
bool reportValidity(ExceptionState& exception_state); bool reportValidity(ExceptionState& exception_state);
LabelsNodeList* labels(); LabelsNodeList* labels(ExceptionState& exception_state);
private: private:
bool IsTargetFormAssociated() const; bool IsTargetFormAssociated() const;
......
...@@ -21,6 +21,6 @@ interface ElementInternals { ...@@ -21,6 +21,6 @@ interface ElementInternals {
[RaisesException] boolean checkValidity(); [RaisesException] boolean checkValidity();
[RaisesException] boolean reportValidity(); [RaisesException] boolean reportValidity();
readonly attribute NodeList labels; [RaisesException] readonly attribute NodeList labels;
}; };
...@@ -9,15 +9,16 @@ test(() => { ...@@ -9,15 +9,16 @@ test(() => {
const element = new MyElement1(); const element = new MyElement1();
const internals = element.attachInternals(); const internals = element.attachInternals();
assert_throws('InvalidStateError', () => { internals.setFormValue(''); }); assert_throws('NotSupportedError', () => { internals.setFormValue(''); });
assert_throws('InvalidStateError', () => { internals.form; }); assert_throws('NotSupportedError', () => { internals.form; });
assert_throws('InvalidStateError', () => { internals.setValidity({}); }); assert_throws('NotSupportedError', () => { internals.setValidity({}); });
assert_throws('InvalidStateError', () => { internals.willValidate; }); assert_throws('NotSupportedError', () => { internals.willValidate; });
assert_throws('InvalidStateError', () => { internals.validity; }); assert_throws('NotSupportedError', () => { internals.validity; });
assert_throws('InvalidStateError', () => { internals.validationMessage; }); assert_throws('NotSupportedError', () => { internals.validationMessage; });
assert_throws('InvalidStateError', () => { internals.checkValidity(); }); assert_throws('NotSupportedError', () => { internals.checkValidity(); });
assert_throws('InvalidStateError', () => { internals.reportValidity(); }); assert_throws('NotSupportedError', () => { internals.reportValidity(); });
}, 'Form-related operations and attributes should throw InvalidStateErrors for' + assert_throws('NotSupportedError', () => { internals.labels; });
'non-form-associated custom elements.'); }, 'Form-related operations and attributes should throw NotSupportedErrors' +
' for non-form-associated custom elements.');
</script> </script>
</body> </body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment