3 <script src=
"../../resources/js-test.js"></script>
6 <div id=
"element" name=
"element_name"></div>
8 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.');
10 var element
= document
.getElementById("element");
12 // These objects should throw an exception when their constructor is called
13 // with no arguments. (Some of them may have working constructors that require
14 // arguments to be valid.)
15 var objects_exception
= [
25 'ProcessingInstruction',
34 'HTMLDirectoryElement',
38 'HTMLFieldSetElement',
42 'HTMLFrameSetElement',
61 'HTMLOptGroupElement',
63 'HTMLParagraphElement',
70 'HTMLTableCaptionElement',
71 'HTMLTableColElement',
73 'HTMLTableSectionElement',
74 'HTMLTableCellElement',
75 'HTMLTableRowElement',
76 'HTMLTextAreaElement',
80 'CanvasRenderingContext2D',
87 'CSSStyleDeclaration',
113 'HTMLOptionsCollection',
123 // These objects should have a working constructor.
124 var objects_constructor
= [
136 // These objects should have no constructor.
137 var objects_no_constructor
= [
139 'UndetectableHTMLCollection',
145 // These objects should have a working constructor, but their constructed
146 // object names differ. This is therefore a map from constructor name to
147 // constructed object.
148 var objects_different_constructor
= {
149 'Audio': 'HTMLAudioElement',
150 'Option': 'HTMLOptionElement',
151 'Image': 'HTMLImageElement'
154 function TryAllocate(node
) {
155 var Cons
= this[node
];
156 if (!Cons
) return 'no constructor';
157 try { return Object
.prototype.toString
.call(new Cons()); }
158 catch (e
) { return 'exception'; }
161 function check(name
, expected
) {
162 actual
= TryAllocate(node
);
163 if (actual
== expected
) {
164 document
.write("PASS: " + name
+ " '" + expected
+ "'<br>");
166 document
.write("FAIL: " + name
+ " wanted '" + expected
+ "', got '" +
171 for (var i
= 0; i
< objects_exception
.length
; i
++) {
172 var obj
= objects_exception
[i
];
173 shouldBe("TryAllocate('" + obj
+ "')", "'exception'");
176 for (var i
= 0; i
< objects_no_constructor
.length
; i
++) {
177 var obj
= objects_no_constructor
[i
];
178 shouldBe("TryAllocate('" + obj
+ "')", "'no constructor'");
181 for (var i
= 0; i
< objects_constructor
.length
; i
++) {
182 var obj
= objects_constructor
[i
];
183 shouldBe("TryAllocate('" + obj
+ "')", "'[object " + obj
+ "]'");
185 shouldBe("TryAllocate('" + obj
+ "')", "'[object " + obj
+ "]'");
186 element
.id
= "element";
188 shouldBe("TryAllocate('" + obj
+ "')", "'[object " + obj
+ "]'");
189 element
.name
= "element_name";
192 for (var obj
in objects_different_constructor
) {
193 shouldBe("TryAllocate('" + obj
+ "')",
194 "'[object " + objects_different_constructor
[obj
] + "]'");
196 shouldBe("TryAllocate('" + obj
+ "')",
197 "'[object " + objects_different_constructor
[obj
] + "]'");
198 element
.id
= "element";
200 shouldBe("TryAllocate('" + obj
+ "')",
201 "'[object " + objects_different_constructor
[obj
] + "]'");
202 element
.name
= "element_name";