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 addListener(eventType, prop) { |
| 12 document.addEventListener(eventType, function(event) { |
| 13 window.prop = prop; |
| 14 // Despite the earlier assignement of the local variable to null and |
| 15 // the following garabage collection, the property should still be |
| 16 // present here. |
| 17 shouldBeEqualToString("event[prop]", "foo"); |
| 18 |
| 19 window.prop = undefined; |
| 20 window.postMessage("done", "*"); |
| 21 }); |
| 22 } |
| 23 |
| 24 // Run the tests whenever a notification arrives, which indicates that the |
| 25 // previous test has finished. |
| 26 window.addEventListener("message", function(message) { |
| 27 runNextTest(); |
| 28 }, false); |
| 29 |
| 30 function newEvent(eventType, prop, value) { |
| 31 return eval("new " + eventType + "('" + eventType + "', { " + prop + ": valu
e })"); |
| 32 } |
| 33 |
| 34 // The events that we want to test, with the properties that each one uses. |
| 35 var events = [ |
| 36 { eventType: "CustomEvent", prop: "detail" }, |
| 37 { eventType: "MessageEvent", prop: "data" }, |
| 38 { eventType: "PopStateEvent", prop: "state" } |
| 39 ]; |
| 40 |
| 41 function runNextTest () { |
| 42 var evt = events.pop(); |
| 43 if (!evt) { |
| 44 finishJSTest(); |
| 45 return; |
| 46 } |
| 47 |
| 48 var value = "foo"; |
| 49 var eventToDispatch = newEvent(evt.eventType, evt.prop, value); |
| 50 value = null; |
| 51 gc(); |
| 52 |
| 53 addListener(evt.eventType, evt.prop); |
| 54 document.dispatchEvent(eventToDispatch); |
| 55 }; |
| 56 |
| 57 // This test is meaningless without testRunner. |
| 58 if (window.testRunner) { |
| 59 runNextTest(); |
| 60 } |
| 61 </script> |
| 62 </body> |
| 63 <script src="../js/resources/js-test-post.js"></script> |
| 64 </html> |
OLD | NEW |