Commit 9d6db8a3 authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Show console errors for illegal declarative Shadow DOM

Prior to this CL, these errors were just logged to stdout; now they
are proper console errors. Needed to add a non-WPT layout test here
because there is no way to test console messages in WPT.

Fixed: 1067488
Change-Id: I4c46c64dbc80449338c699490e1ab0dda32cd833
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231918
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776534}
parent 7431408d
...@@ -3679,12 +3679,13 @@ void Element::AttachDeclarativeShadowRoot(HTMLTemplateElement* template_element, ...@@ -3679,12 +3679,13 @@ void Element::AttachDeclarativeShadowRoot(HTMLTemplateElement* template_element,
// 12. Run attach a shadow root with shadow host equal to declarative shadow // 12. Run attach a shadow root with shadow host equal to declarative shadow
// host element, mode equal to declarative shadow mode, and delegates focus // host element, mode equal to declarative shadow mode, and delegates focus
// equal to declarative shadow delegates focus. If an exception was thrown by // equal to declarative shadow delegates focus. If an exception was thrown by
// attach a shadow root, catch it, and report the exception. // attach a shadow root, catch it, and ignore the exception.
if (const char* error_message = ErrorMessageForAttachShadow()) { if (const char* error_message = ErrorMessageForAttachShadow()) {
// TODO(1067488): Fire this exception at Window.
LOG(ERROR) << error_message;
template_element->SetDeclarativeShadowRootType( template_element->SetDeclarativeShadowRootType(
DeclarativeShadowRootType::kNone); DeclarativeShadowRootType::kNone);
GetDocument().AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kOther,
mojom::blink::ConsoleMessageLevel::kError, error_message));
return; return;
} }
ShadowRoot& shadow_root = ShadowRoot& shadow_root =
......
CONSOLE ERROR: line 17: This element does not support attachShadow
CONSOLE ERROR: line 37: attachShadow() is disabled by disabledFeatures static field.
CONSOLE ERROR: line 50: Shadow root cannot be created on a host which already hosts a shadow tree.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<meta charset="utf-8">
<title>Declarative Shadow DOM Errors</title>
<script src="../resources/js-test.js"></script>
<!--
1. If shadow host’s namespace is not the HTML namespace, then throw a
"NotSupportedError" DOMException.
2. If shadow host’s local name is not a valid custom element name,
"article", "aside", "blockquote", "body", "div", "footer", "h1", "h2",
"h3", "h4", "h5", "h6", "header", "main", "nav", "p", "section", or "span",
then throw a "NotSupportedError" DOMException.
-->
<video>
<template shadowroot=open>
</template>
</video>
<!--
3. If shadow host’s local name is a valid custom element name, or shadow
host’s is value is not null, then:
3.1 Let definition be the result of looking up a custom element
definition given shadow host’s node document, its namespace, its local
name, and its is value.
3.2 If definition is not null and definition’s
disable shadow is true, then throw a "NotSupportedError" DOMException.
-->
<script>
class ShadowDisabledElement extends HTMLElement {
static get disabledFeatures() { return ['shadow']; }
}
customElements.define('shadow-disabled-element', ShadowDisabledElement);
</script>
<shadow-disabled-element>
<template shadowroot=open>
</template>
</shadow-disabled-element>
<!--
4. If shadow host has a non-null shadow root whose "is declarative shadow
root" property is false, then throw an "NotSupportedError" DOMException.
-->
<div id=host>
<span></span>
<script>
host.attachShadow({mode:'open'});
</script>
<template shadowroot=open>
</template>
</div>
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