| Index: third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html
|
| diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html b/third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8ac5cdfb385161040e35e83145694efb40fbd85d
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html
|
| @@ -0,0 +1,124 @@
|
| +<!DOCTYPE html>
|
| +<title>Custom Elements: report the exception</title>
|
| +<script src="../../resources/testharness.js"></script>
|
| +<script src="../../resources/testharnessreport.js"></script>
|
| +<script src="resources/custom-elements-helpers.js"></script>
|
| +<body>
|
| +<!--
|
| +The custom elements spec has 2 places where it [report the exception]:
|
| +
|
| +1. In the [create an element for a token], step 7.
|
| + This can occur only when [create an element] is invoked from
|
| + [create an element for a token] with the synchronous custom elements flag
|
| + set; i.e., the document parser.
|
| +2. In the [invoke custom element reactions], step 2.1.
|
| +
|
| +Also it is likely that platform may run different code paths for:
|
| +1. When JavaScript throws and the platform rethrows.
|
| +2. When the platform throws.
|
| +
|
| +This test contains 4 tests for the combination of the above 2x2.
|
| +
|
| +[report the exception]: https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
|
| +[create an element for a token]: https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token
|
| +[create an element]: https://dom.spec.whatwg.org/#concept-create-element
|
| +[invoke custom element reactions]: https://html.spec.whatwg.org/multipage/scripting.html#invoke-custom-element-reactions
|
| +-->
|
| +<template id="common">
|
| + <script>
|
| +'use strict';
|
| +window.errors = [];
|
| +window.onerror = function () {
|
| + errors.push(Array.prototype.slice.call(arguments));
|
| + return true; // Cancel the error event.
|
| +};
|
| + </script>
|
| +</template>
|
| +<template id="constructor-throws">
|
| + <script>
|
| +const rethrowErrorName = 'rethrown';
|
| +const rethrowErrorMessage = 'check this is rethrown';
|
| +
|
| +function create_rethrow_error() {
|
| + const error = new Error(rethrowErrorMessage);
|
| + error.name = rethrowErrorName;
|
| + return error;
|
| +}
|
| +
|
| +customElements.define('a-a', class extends HTMLElement {
|
| + constructor() {
|
| + throw create_rethrow_error();
|
| + }
|
| +});
|
| + </script>
|
| +</template>
|
| +<template id="instantiate">
|
| + <a-a></a-a>
|
| +</template>
|
| +<script>
|
| +'use strict';
|
| +const rethrowErrorName = 'rethrown';
|
| +const rethrowErrorMessage = 'check this is rethrown';
|
| +
|
| +function assert_rethrown(error) {
|
| + assert_equals(error.name, rethrowErrorName);
|
| + assert_equals(error.message, rethrowErrorMessage);
|
| +}
|
| +
|
| +const common = document.getElementById('common').innerHTML;
|
| +const constructor_throws = common
|
| + + document.getElementById('constructor-throws').innerHTML;
|
| +const instantiate = document.getElementById('instantiate').innerHTML;
|
| +
|
| +test_with_window(w => {
|
| + assert_rethrown(w.errors[0][4]);
|
| +}, 'Document parser invokes the constructor that throws',
|
| + constructor_throws + instantiate);
|
| +
|
| +test_with_window(w => {
|
| + w.document.body.innerHTML = instantiate;
|
| + assert_rethrown(w.errors[0][4]);
|
| +}, 'Upgrade reaction invokes the constructor that throws',
|
| + constructor_throws);
|
| +</script>
|
| +
|
| +<!--
|
| +-->
|
| +<template id="constructor-returns-bad-object">
|
| + <script>
|
| +customElements.define('a-a', class extends HTMLElement {
|
| + constructor() {
|
| + super();
|
| + return []; // returning other objects than "this" is invalid.
|
| + }
|
| +});
|
| + </script>
|
| +</template>
|
| +<script>
|
| +const constructor_returns_bad_object = common
|
| + + document.getElementById('constructor-returns-bad-object').innerHTML;
|
| +
|
| +function assert_type_error(error) {
|
| + assert_equals(error.name, 'TypeError');
|
| +}
|
| +
|
| +function assert_invalid_state_dom_error(error) {
|
| + assert_equals(error.name, 'InvalidStateError');
|
| +}
|
| +
|
| +test_with_window(w => {
|
| + // "create an element" 6.1.3, throw a TypeError.
|
| + // https://dom.spec.whatwg.org/#concept-create-element
|
| + assert_type_error(w.errors[0][4]);
|
| +}, 'Document parser invokes the constructor that returns a bad object',
|
| + constructor_returns_bad_object + instantiate);
|
| +
|
| +test_with_window(w => {
|
| + // "upgrade an element" 10, throw an InvalidStateError DOMException.
|
| + // https://html.spec.whatwg.org/multipage/scripting.html#upgrades
|
| + w.document.body.innerHTML = instantiate;
|
| + assert_invalid_state_dom_error(w.errors[0][4]);
|
| +}, 'Upgrade reaction invokes the constructor that returns a bad object',
|
| + constructor_returns_bad_object);
|
| +</script>
|
| +</body>
|
|
|