Commit 0bf2260f authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

std-switch: Disallow extending StdSwitchElement

Bug: 972476
Change-Id: I1cca5af7809c0575f9c34a5d11068dc41aea157b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1672847Reviewed-by: default avatarRakina Zata Amni <rakina@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671994}
parent b9e1a4f9
...@@ -27,6 +27,10 @@ export class StdSwitchElement extends HTMLElement { ...@@ -27,6 +27,10 @@ export class StdSwitchElement extends HTMLElement {
constructor() { constructor() {
super(); super();
if (new.target !== StdSwitchElement) {
throw new TypeError('Illegal constructor: StdSwitchElement is not ' +
'extensible for now');
}
this[_internals] = this.attachInternals(); this[_internals] = this.attachInternals();
this._initializeDOM(); this._initializeDOM();
} }
......
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script type="module">
import { StdSwitchElement } from 'std:elements/switch';
setup({allow_uncaught_exception:true});
test(()=> {
class MySwitchElement extends StdSwitchElement {
}
customElements.define('my-switch', MySwitchElement);
let uncaughtError = null;
window.addEventListener('error', e => {
uncaughtError = e.error;
}, {once: true});
document.createElement('my-switch');
assert_true(uncaughtError instanceof TypeError);
}, 'Should not be able to create an autonomous custom element extending StdSwitchElement');
test(()=> {
class MySwitchElement2 extends StdSwitchElement {
}
assert_throws('NotSupportedError', () => {
customElements.define('my-switch2', MySwitchElement2, {extends: 'std-switch'});
});
}, 'Should not be able to define a customized built-in element for std-switch');
</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