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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="element" name="element_name"></div>
<script>
description('This test checks that all but a handful of dom constructors throw exceptions, and the rest return reasonable objects. It also tests that those constructors have higher precedence than a document element with the same ID or name.');
var element = document.getElementById("element");
// These objects should throw an exception when their constructor is called
// with no arguments. (Some of them may have working constructors that require
// arguments to be valid.)
var objects_exception = [
'Attr',
'CharacterData',
'CDATASection',
'Document',
'DocumentType',
'Element',
'EventTarget',
'HTMLDocument',
'Node',
'ProcessingInstruction',
'HTMLAllCollection',
'HTMLAnchorElement',
'HTMLAreaElement',
'HTMLBaseElement',
'HTMLBodyElement',
'HTMLBRElement',
'HTMLButtonElement',
'HTMLCanvasElement',
'HTMLDirectoryElement',
'HTMLDivElement',
'HTMLDListElement',
'HTMLEmbedElement',
'HTMLFieldSetElement',
'HTMLFontElement',
'HTMLFormElement',
'HTMLFrameElement',
'HTMLFrameSetElement',
'HTMLHeadingElement',
'HTMLHeadElement',
'HTMLHRElement',
'HTMLHtmlElement',
'HTMLIFrameElement',
'HTMLImageElement',
'HTMLInputElement',
'HTMLLabelElement',
'HTMLLegendElement',
'HTMLLIElement',
'HTMLLinkElement',
'HTMLMapElement',
'HTMLMarqueeElement',
'HTMLMenuElement',
'HTMLMetaElement',
'HTMLModElement',
'HTMLObjectElement',
'HTMLOListElement',
'HTMLOptGroupElement',
'HTMLOptionElement',
'HTMLParagraphElement',
'HTMLParamElement',
'HTMLPreElement',
'HTMLQuoteElement',
'HTMLScriptElement',
'HTMLSelectElement',
'HTMLStyleElement',
'HTMLTableCaptionElement',
'HTMLTableColElement',
'HTMLTableElement',
'HTMLTableSectionElement',
'HTMLTableCellElement',
'HTMLTableRowElement',
'HTMLTextAreaElement',
'HTMLTitleElement',
'HTMLUListElement',
'HTMLElement',
'CanvasRenderingContext2D',
'CSSFontFaceRule',
'CSSImportRule',
'CSSMediaRule',
'CSSPageRule',
'CSSRule',
'CSSRuleList',
'CSSStyleDeclaration',
'CSSStyleRule',
'CSSStyleSheet',
'DOMImplementation',
'DataTransfer',
'HTMLCollection',
'MediaList',
'MimeType',
'MimeTypeArray',
'MutationEvent',
'NamedNodeMap',
'NodeFilter',
'NodeList',
'Plugin',
'PluginArray',
'StyleSheet',
'StyleSheetList',
'TextEvent',
'XPathResult',
'BarInfo',
'CanvasGradient',
'CanvasPattern',
'Console',
'Selection',
'Window',
'History',
'HTMLOptionsCollection',
'Location',
'Navigator',
'NodeIterator',
'Screen',
'TreeWalker',
'XPathExpression',
'Worker'
];
// These objects should have a working constructor.
var objects_constructor = [
'Comment',
'DOMParser',
'DocumentFragment',
'Range',
'Text',
'XMLHttpRequest',
'XMLSerializer',
'XPathEvaluator',
'XSLTProcessor'
];
// These objects should have no constructor.
var objects_no_constructor = [
'EventTargetNode',
'UndetectableHTMLCollection',
'XPathNSResolver',
'EventListener',
'NPObject'
];
// These objects should have a working constructor, but their constructed
// object names differ. This is therefore a map from constructor name to
// constructed object.
var objects_different_constructor = {
'Audio': 'HTMLAudioElement',
'Option': 'HTMLOptionElement',
'Image': 'HTMLImageElement'
}
function TryAllocate(node) {
var Cons = this[node];
if (!Cons) return 'no constructor';
try { return Object.prototype.toString.call(new Cons()); }
catch (e) { return 'exception'; }
}
function check(name, expected) {
actual = TryAllocate(node);
if (actual == expected) {
document.write("PASS: " + name + " '" + expected + "'<br>");
} else {
document.write("FAIL: " + name + " wanted '" + expected + "', got '" +
actual + "'<br>");
}
}
for (var i = 0; i < objects_exception.length; i++) {
var obj = objects_exception[i];
shouldBe("TryAllocate('" + obj + "')", "'exception'");
}
for (var i = 0; i < objects_no_constructor.length; i++) {
var obj = objects_no_constructor[i];
shouldBe("TryAllocate('" + obj + "')", "'no constructor'");
}
for (var i = 0; i < objects_constructor.length; i++) {
var obj = objects_constructor[i];
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.id = obj;
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.id = "element";
element.name = obj;
shouldBe("TryAllocate('" + obj + "')", "'[object " + obj + "]'");
element.name = "element_name";
}
for (var obj in objects_different_constructor) {
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.id = obj;
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.id = "element";
element.name = obj;
shouldBe("TryAllocate('" + obj + "')",
"'[object " + objects_different_constructor[obj] + "]'");
element.name = "element_name";
}
</script>
</body>
</html>
|