OLD | NEW |
1 <html> | 1 <!DOCTYPE html> |
2 <head></head> | 2 <script src="../../../resources/testharness.js"></script> |
3 <body> | 3 <script src="../../../resources/testharnessreport.js"></script> |
4 <p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=47422">bug 47422</a>
: | |
5 window constructor shouldn't be directly callable.</p> | |
6 <div id="console"></div> | |
7 <script> | 4 <script> |
8 if (window.testRunner) { | 5 test(() => { |
9 window.testRunner.dumpAsText(); | 6 assert_equals(window.constructor.prototype, window.__proto__, |
10 } | 7 "Window constructor prototype is window prototype."); |
11 | 8 |
12 function log(message, color) | 9 assert_throws(null, () => { window.constructor(); }, |
13 { | 10 "Window constructor must be non-callable."); |
14 var paragraph = document.createElement("div"); | 11 assert_throws(null, () => { new window.constructor; }, |
15 paragraph.appendChild(document.createTextNode(message)); | 12 "Window constructor must be non-callable."); |
16 paragraph.style.fontFamily = "monospace"; | |
17 if (color) | |
18 paragraph.style.color = color; | |
19 document.getElementById("console").appendChild(paragraph); | |
20 } | |
21 | |
22 function testConstructorProto() | |
23 { | |
24 var testName = "Window constructor prototype is window prototype" | |
25 if (window.constructor.prototype === window.__proto__) | |
26 log(testName + ": PASS", "green"); | |
27 else | |
28 log(testName + ": FAIL", "red"); | |
29 } | |
30 | 13 |
31 function testConstructorNotCallable() | 14 assert_throws(null, () => { window.__proto__.constructor(); }, |
32 { | 15 "Window.prototype constructor must be non-callable."); |
33 var testName = "Window constructor not callable" | 16 assert_throws(null, () => { new window.__proto__.constructor; }, |
34 | 17 "Window.prototype constructor must be non-callable."); |
35 var threwExc = false; | |
36 | |
37 try { | |
38 newW = window.constructor() | |
39 } catch(e) { | |
40 threwExc = true; | |
41 } | |
42 | 18 |
43 if (threwExc) { | 19 assert_throws(null, () => { window.__proto__.__proto__.constructor(); }, |
44 log(testName + ": PASS", "green"); | 20 "WindowProperties constructor must be non-callable."); |
45 } else { | 21 assert_throws(null, () => { new window.__proto__.__proto__.constructor; }, |
46 log(testName + ": FAIL", "red"); | 22 "WindowProperties constructor must be non-callable."); |
47 } | 23 }, "Test Window and its prototype chain's constructors."); |
48 } | |
49 | |
50 testConstructorProto(); | |
51 testConstructorNotCallable(); | |
52 </script> | 24 </script> |
53 </body> | |
54 </html> | |
OLD | NEW |