OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../js/resources/js-test-pre.js"></script> | |
5 </head> | |
6 <body> | |
7 <script> | |
8 window.jsTestIsAsync = true; | |
9 description("Tests that properties passed to events are not garbage collected pr ematurely."); | |
10 | |
11 function gc() { | |
haraken
2013/06/26 23:53:04
You don't need to write this. This is already defi
jww
2013/06/27 00:16:19
Done.
| |
12 if (window.GCController) | |
13 return GCController.collect(); | |
14 for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect) | |
15 var s = new String("abc"); | |
16 } | |
17 } | |
18 | |
19 function addListener(eventType, prop) { | |
20 document.addEventListener(eventType, function(event) { | |
21 window.prop = prop; | |
22 // Despite the earlier assignement of the local variable to null and | |
23 // the following garabage collection, the property should still be | |
24 // present here. | |
25 shouldBeEqualToString("event[prop]", "foo"); | |
26 | |
27 window.prop = undefined; | |
28 window.postMessage("done", "*"); | |
29 }); | |
30 } | |
31 | |
32 // Run the tests whenever a notification arrives, which indicates that the | |
33 // previous test has finished. | |
34 window.addEventListener("message", function(message) { | |
35 runNextTest(); | |
36 }, false); | |
37 | |
38 function newEvent(eventType, prop, value) { | |
39 return eval("new " + eventType + "('" + eventType + "', { " + prop + ": valu e })"); | |
40 } | |
41 | |
42 // The events that we want to test, with the properties that each one uses. | |
43 var events = [ | |
44 { eventType: "CustomEvent", prop: "detail" }, | |
45 { eventType: "MessageEvent", prop: "data" }, | |
46 { eventType: "PopStateEvent", prop: "state" } | |
47 ]; | |
48 | |
49 function runNextTest () { | |
50 var evt = events.pop(); | |
51 if (!evt) { | |
52 finishJSTest(); | |
53 return; | |
54 } | |
55 | |
56 var value = "foo"; | |
57 var eventToDispatch = newEvent(evt.eventType, evt.prop, value); | |
58 value = null; | |
59 gc(); | |
60 | |
61 addListener(evt.eventType, evt.prop); | |
62 document.dispatchEvent(eventToDispatch); | |
63 }; | |
64 | |
65 // This test is meaningless without testRunner. | |
66 if (window.testRunner) { | |
67 runNextTest(); | |
68 } | |
69 </script> | |
70 </body> | |
71 <script src="../js/resources/js-test-post.js"></script> | |
72 </html> | |
OLD | NEW |