Commit 931a1dde authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Changes DOMExpcetion types for attachShadow() and attachInternals().

They should throw NotSupportedError, not InvalidStateError.

https://dom.spec.whatwg.org/#dom-element-attachshadow
https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals

Bug: 905922, 963920
Change-Id: Ica8ebee70dd2d69312971e6df1e8ad3b728458df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1616864Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661271}
parent e85f4ae5
...@@ -2893,7 +2893,7 @@ ShadowRoot* Element::attachShadow(const ShadowRootInit* shadow_root_init_dict, ...@@ -2893,7 +2893,7 @@ ShadowRoot* Element::attachShadow(const ShadowRootInit* shadow_root_init_dict,
} }
if (GetShadowRoot()) { if (GetShadowRoot()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Shadow root cannot be created on a host " "Shadow root cannot be created on a host "
"which already hosts a shadow tree."); "which already hosts a shadow tree.");
return nullptr; return nullptr;
......
...@@ -1469,7 +1469,7 @@ ElementInternals* HTMLElement::attachInternals( ...@@ -1469,7 +1469,7 @@ ElementInternals* HTMLElement::attachInternals(
registry ? registry->DefinitionForName(localName()) : nullptr; registry ? registry->DefinitionForName(localName()) : nullptr;
if (!definition) { if (!definition) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"Unable to attach ElementInternals to non-custom elements."); "Unable to attach ElementInternals to non-custom elements.");
return nullptr; return nullptr;
} }
...@@ -1481,7 +1481,7 @@ ElementInternals* HTMLElement::attachInternals( ...@@ -1481,7 +1481,7 @@ ElementInternals* HTMLElement::attachInternals(
} }
if (DidAttachInternals()) { if (DidAttachInternals()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kNotSupportedError,
"ElementInternals for the specified element was already attached."); "ElementInternals for the specified element was already attached.");
return nullptr; return nullptr;
} }
......
This is a testharness.js-based test.
FAIL Successful attachInternals() and the second call. assert_throws: New - 2nd call function "() => { element.attachInternals(); }" threw object "InvalidStateError: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached." that is not a DOMException NotSupportedError: property "code" is equal to 11, expected 9
PASS attachInternals() throws a NotSupportedError if it is called for a customized built-in element
FAIL If a custom element definition for the local name of the element doesn't exist, throw an NotSupportedError assert_throws: function "() => { builtin.attachInternals() }" threw object "InvalidStateError: Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements." that is not a DOMException NotSupportedError: property "code" is equal to 11, expected 9
PASS If a custom element definition for the local name of the element has disable internals flag, throw a NotSupportedError
Harness: the test ran to completion.
This is a testharness.js-based test. This is a testharness.js-based test.
PASS Element.attachShadow must create an instance of ShadowRoot for autonomous custom elements PASS Element.attachShadow must create an instance of ShadowRoot for autonomous custom elements
PASS Element.attachShadow must create an instance of ShadowRoot for undefined autonomous custom elements PASS Element.attachShadow must create an instance of ShadowRoot for undefined autonomous custom elements
FAIL Element.attachShadow for an autonomous custom element with disabledFeatures=["shadow"] should throw a NotSupportedError assert_throws: No definition, host function "() => { FAIL Element.attachShadow for an autonomous custom element with disabledFeatures=["shadow"] should throw a NotSupportedError assert_throws: Definition, not a host function "() => {
element.attachShadow({mode: 'closed'}); document.createElement('shadow-disabled-element').attachShadow({mode: 'closed'});
}" threw object "InvalidStateError: Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree." that is not a DOMException NotSupportedError: property "code" is equal to 11, expected 9 }" did not throw
FAIL Element.attachShadow for a customized built-in element with disabledFeatures=["shadow"] should throw a NotSupportedError assert_throws: No definition, host. function "() => { FAIL Element.attachShadow for a customized built-in element with disabledFeatures=["shadow"] should throw a NotSupportedError assert_throws: Definition, not a host function "() => {
element.attachShadow({mode: 'closed'}); h2.attachShadow({mode: 'closed'});
}" threw object "InvalidStateError: Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree." that is not a DOMException NotSupportedError: property "code" is equal to 11, expected 9 }" did not throw
PASS Element.attachShadow for a custom element with disabledFeatures=["SHADOW"] should not throw a NotSupportedError PASS Element.attachShadow for a custom element with disabledFeatures=["SHADOW"] should not throw a NotSupportedError
PASS Element.attachShadow must throw a NotSupportedError for customized built-in elements PASS Element.attachShadow must throw a NotSupportedError for customized built-in elements
Harness: the test ran to completion. Harness: the test ran to completion.
......
This is a testharness.js-based test.
PASS Check the existence of Element.attachShadow
PASS Nodes other than Element should not have attachShadow
PASS Element.attachShadow must throw a TypeError if mode is not "open" or "closed"
PASS Element.attachShadow must create an instance of ShadowRoot
FAIL Element.attachShadow must throw a NotSupportedError if the context object already hosts a shadow tree assert_throws: Calling attachShadow({mode: "open"}) twice on the same element must throw function "function () {
var div = document.createElement('div');
div.attachShadow({mode: "open"});
div.attachShadow({mode: "open"});
}" threw object "InvalidStateError: Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree." ("InvalidStateError") expected object "[object Object]" ("NotSupportedError")
PASS Element.attachShadow must throw a NotSupportedError for non-safelisted elements
Harness: the test ran to completion.
...@@ -22,9 +22,9 @@ test(() => { ...@@ -22,9 +22,9 @@ test(() => {
assert_throws({name: 'TypeError'}, () => { host3.attachShadow({mode: 'illegal'}); }, assert_throws({name: 'TypeError'}, () => { host3.attachShadow({mode: 'illegal'}); },
'Attach shadow root whose mode is neither open nor closed should throw TypeError.'); 'Attach shadow root whose mode is neither open nor closed should throw TypeError.');
assert_throws({name: 'InvalidStateError'}, () => { host1.attachShadow({mode: 'open'}); }, assert_throws({name: 'NotSupportedError'}, () => { host1.attachShadow({mode: 'open'}); },
'Attach shadow on a host which has open shadow root will raise InvalidStateError exception.'); 'Attach shadow on a host which has open shadow root will raise NotSupportedError exception.');
assert_throws({name: 'InvalidStateError'}, () => { host2.attachShadow({mode: 'open'}); }, assert_throws({name: 'NotSupportedError'}, () => { host2.attachShadow({mode: 'open'}); },
'Attach shadow on a host wich has closed shadow root will raise InvalidStateError exception.'); 'Attach shadow on a host wich has closed shadow root will raise NotSupportedError exception.');
}, 'Test for Element.attachShadow() with mode parameter.'); }, 'Test for Element.attachShadow() with mode parameter.');
</script> </script>
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