1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1275835
-->
<head>
<title>Test registering invalid lifecycle callbacks for custom elements.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1275835">Bug 1275835</a>
<iframe id="iframe"></iframe>
<script>
// Use window from iframe to isolate the test.
const testWindow = iframe.contentDocument.defaultView;
// This is for backward compatibility.
// We should do the same checks for the callbacks from v0 spec.
[
'createdCallback',
'attributeChangedCallback',
].forEach(callback => {
var c = class {};
var p = c.prototype;
// Test getting callback throws exception.
Object.defineProperty(p, callback, {
get() {
const e = new Error('this is rethrown');
e.name = 'rethrown';
throw e;
}
});
SimpleTest.doesThrow(() => {
testWindow.document.registerElement(`test-register-${callback}-rethrown`,
{ prototype: p });
}, `document.registerElement should throw exception if prototype.${callback} throws`);
SimpleTest.doesThrow(() => {
testWindow.customElements.define(`test-define-${callback}-rethrown`, c);
}, `customElements.define should throw exception if constructor.${callback} throws`);
// Test callback is not callable.
[
{ name: 'null', value: null },
{ name: 'object', value: {} },
{ name: 'integer', value: 1 },
].forEach(data => {
var c = class {};
var p = c.prototype;
p[callback] = data.value;
SimpleTest.doesThrow(() => {
testWindow.document.registerElement(`test-register-${callback}-${data.name}`,
{ prototype: p });
}, `document.registerElement should throw exception if ${callback} is ${data.name}`);
SimpleTest.doesThrow(() => {
testWindow.customElements.define(`test-define-${callback}-${data.name}`, c);
}, `customElements.define should throw exception if ${callback} is ${data.name}`);
});
});
</script>
</body>
</html>
|