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,
ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return;
}
......@@ -70,7 +70,7 @@ void ElementInternals::setFormValue(const FileOrUSVString& value,
HTMLFormElement* ElementInternals::form(ExceptionState& exception_state) const {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return nullptr;
}
......@@ -87,7 +87,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags,
ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return;
}
......@@ -108,7 +108,7 @@ void ElementInternals::setValidity(ValidityStateFlags* flags,
bool ElementInternals::willValidate(ExceptionState& exception_state) const {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return false;
}
......@@ -118,7 +118,7 @@ bool ElementInternals::willValidate(ExceptionState& exception_state) const {
ValidityState* ElementInternals::validity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return nullptr;
}
......@@ -129,7 +129,7 @@ String ElementInternals::ValidationMessageForBinding(
ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return String();
}
......@@ -151,7 +151,7 @@ String ElementInternals::ValidationSubMessage() const {
bool ElementInternals::checkValidity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return false;
}
......@@ -161,14 +161,20 @@ bool ElementInternals::checkValidity(ExceptionState& exception_state) {
bool ElementInternals::reportValidity(ExceptionState& exception_state) {
if (!IsTargetFormAssociated()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
DOMExceptionCode::kNotSupportedError,
"The target element is not a form-associated custom element.");
return false;
}
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();
}
......
......@@ -43,7 +43,7 @@ class ElementInternals : public ScriptWrappable, public ListedElement {
String ValidationMessageForBinding(ExceptionState& exception_state);
bool checkValidity(ExceptionState& exception_state);
bool reportValidity(ExceptionState& exception_state);
LabelsNodeList* labels();
LabelsNodeList* labels(ExceptionState& exception_state);
private:
bool IsTargetFormAssociated() const;
......
......@@ -21,6 +21,6 @@ interface ElementInternals {
[RaisesException] boolean checkValidity();
[RaisesException] boolean reportValidity();
readonly attribute NodeList labels;
[RaisesException] readonly attribute NodeList labels;
};
......@@ -9,15 +9,16 @@ test(() => {
const element = new MyElement1();
const internals = element.attachInternals();
assert_throws('InvalidStateError', () => { internals.setFormValue(''); });
assert_throws('InvalidStateError', () => { internals.form; });
assert_throws('InvalidStateError', () => { internals.setValidity({}); });
assert_throws('InvalidStateError', () => { internals.willValidate; });
assert_throws('InvalidStateError', () => { internals.validity; });
assert_throws('InvalidStateError', () => { internals.validationMessage; });
assert_throws('InvalidStateError', () => { internals.checkValidity(); });
assert_throws('InvalidStateError', () => { internals.reportValidity(); });
}, 'Form-related operations and attributes should throw InvalidStateErrors for' +
'non-form-associated custom elements.');
assert_throws('NotSupportedError', () => { internals.setFormValue(''); });
assert_throws('NotSupportedError', () => { internals.form; });
assert_throws('NotSupportedError', () => { internals.setValidity({}); });
assert_throws('NotSupportedError', () => { internals.willValidate; });
assert_throws('NotSupportedError', () => { internals.validity; });
assert_throws('NotSupportedError', () => { internals.validationMessage; });
assert_throws('NotSupportedError', () => { internals.checkValidity(); });
assert_throws('NotSupportedError', () => { internals.reportValidity(); });
assert_throws('NotSupportedError', () => { internals.labels; });
}, 'Form-related operations and attributes should throw NotSupportedErrors' +
' for non-form-associated custom elements.');
</script>
</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