Chromium Code Reviews| 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..d7fe1052a56ec26f7f2fd13037f86d0a5e8abdd4 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html |
| @@ -0,0 +1,159 @@ |
| +<!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]: |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
"it report" isn't right; it would need to be repor
|
| + |
| +1. In the [create an element for a token], step 7. |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Omit 'the', or give the article something to name,
|
| + 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. |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Might be more readable to avoid Latin, id est avoi
|
| +2. In the [invoke custom element reactions], step 2.1. |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Same as above, the ... algorithm or simply drop "t
|
| + |
| +Also it is likely that platform may run different code paths for: |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
singular "platform" needs an article. The platform
|
| +1. When JavaScript throws and the platform rethrows. |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Again, grammar; "for when JavaScript throws" isn't
|
| +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="constructor-throws"> |
| + <script> |
| +'use strict'; |
| +window.errors = []; |
| +// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes:handler-onerror |
| +window.onerror = function (event, source, lineno, colno, error) { |
| + errors.push({ |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Thank you. I know it is a bit verbose, but it is v
|
| + event: event, |
| + source: source, |
| + lineno: lineno, |
| + colno: colno, |
| + error: error, |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Maybe omit the trailing comma?
|
| + }); |
| + return true; // Cancel the error event. |
| +}; |
| + |
| +const rethrowErrorName = 'rethrown'; |
| +const rethrowErrorMessage = 'check this is rethrown'; |
| + |
| +function create_rethrow_error() { |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
This is only used in one place; just inline it?
|
| + 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_not_muted_error_event(error) { |
| + // Report an error, 6. If script has muted errors, ... |
| + // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error |
| + assert_false(error.event === 'Script error.' |
| + && error.source === '' && error.lineno === 0 && error.colno === 0 |
| + && error.error === null, |
| + 'the error should not be muted.'); |
| + assert_false(!error.event, 'event (1st arg) should not be null'); |
| + assert_false(!error.source, 'source (2nd arg) should not be null'); |
| + // The spec doesn't define valid values for lineno/colno. |
| + assert_false(!error.error, 'error (5th arg) should not be null'); |
| +} |
| + |
| +function assert_rethrown_error_event(error) { |
| + assert_not_muted_error_event(error); |
| + assert_equals(error.error.name, rethrowErrorName); |
| + assert_equals(error.error.message, rethrowErrorMessage); |
| +} |
| + |
| +const constructor_throws = |
| + document.getElementById('constructor-throws').innerHTML; |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
Indent two additional spaces.
|
| +const instantiate = document.getElementById('instantiate').innerHTML; |
| + |
| +test_with_window((w) => { |
| + assert_rethrown_error_event(w.errors[0]); |
| +}, 'Document parser invokes the constructor that throws', |
| + constructor_throws + instantiate); |
| + |
| +test_with_window((w) => { |
| + w.document.body.innerHTML = instantiate; |
| + assert_rethrown_error_event(w.errors[0]); |
| +}, 'Upgrade reaction invokes the constructor that throws', |
| + constructor_throws); |
| +</script> |
| + |
| +<!-- |
| +Test when JavaScript returns without throwing errors, but the result is invalid |
| +and thus UA should [report the exception]. |
| +--> |
| +<template id="constructor-returns-bad-object"> |
| + <script> |
| +'use strict'; |
| +window.errors = []; |
| +// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes:handler-onerror |
| +window.onerror = function (event, source, lineno, colno, error) { |
| + errors.push({ |
| + event: event, |
| + source: source, |
| + lineno: lineno, |
| + colno: colno, |
| + error: error, |
| + }); |
| + return true; // Cancel the error event. |
| +}; |
| + |
| +customElements.define('a-a', class extends HTMLElement { |
| + constructor() { |
| + super(); |
| + return []; // returning other objects than "this" is invalid. |
|
dominicc (has gone to gerrit)
2016/08/19 07:51:29
objects other than "this"
I'm not 100% sure this
|
| + } |
| +}); |
| + </script> |
| +</template> |
| +<script> |
| +const constructor_returns_bad_object = |
| + document.getElementById('constructor-returns-bad-object').innerHTML; |
| + |
| +function assert_type_error_event(error) { |
| + assert_not_muted_error_event(error); |
| + assert_equals(error.error.name, 'TypeError'); |
| +} |
| + |
| +function assert_invalid_state_dom_error_event(error) { |
| + assert_not_muted_error_event(error); |
| + assert_equals(error.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_event(w.errors[0]); |
| +}, '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_event(w.errors[0]); |
| +}, 'Upgrade reaction invokes the constructor that returns a bad object', |
| + constructor_returns_bad_object); |
| +</script> |
| +</body> |