| <!DOCTYPE html> |
| <script src="../../../resources/gc.js"></script> |
| <script src='../../../resources/testharness.js'></script> |
| <script src='../../../resources/testharnessreport.js'></script> |
| <script> |
| |
| // All the following tests make sure that the observer callback is called even |
| // if there are no references to the nodes and a garbage collection kicks in |
| // before returning to the event loop. |
| |
| async_test(function(t) { |
| |
| (function simple() { |
| var d = document.createElement('div'); |
| var c = document.createElement('div'); |
| var obs = new MutationObserver(t.step_func_done(function() {})); |
| obs.observe(d, {childList: true}); |
| d.appendChild(c); |
| })(); |
| gc(); |
| }, "Tests that pending callbacks retain the nodes even in the presence of garbage collection"); |
| |
| async_test(function(t) { |
| (function addedChildNodes() { |
| var d = document.createElement('div'); |
| var c = document.createElement('div'); |
| c.expando = "c"; |
| var obs = new MutationObserver(t.step_func_done(function(records) { |
| assert_equals(1, records[0].addedNodes.length, "one node added"); |
| assert_equals("c", records[0].addedNodes[0].expando, "expando preserved"); |
| })); |
| obs.observe(d, {childList: true}); |
| d.appendChild(c); |
| })(); |
| gc(); |
| }, "Tests that pending callbacks retain the nodes even in the presence of garbage collection"); |
| |
| async_test(function(t) { |
| (function siblings() { |
| var d = document.createElement('div'); |
| var b = document.createElement('b'); |
| var i = document.createElement('i'); |
| var p = document.createElement('p'); |
| d.appendChild(b); |
| d.appendChild(i); |
| d.appendChild(p); |
| b.expando = "hello"; |
| p.expando = "goodbye"; |
| |
| var obs = new MutationObserver(t.step_func_done(function(records) { |
| assert_equals(3, records.length, "number of records"); |
| assert_equals("hello", records[0].previousSibling.expando, "expando preserved"); |
| assert_equals("goodbye", records[0].nextSibling.expando, "expando preserved"); |
| })); |
| obs.observe(d, {childList: true}); |
| d = null; |
| i.remove(); |
| i = null; |
| b.remove(); |
| b = null; |
| p.remove(); |
| p = null; |
| })(); |
| gc(); |
| }, "Tests that pending callbacks retain the nodes even in the presence of garbage collection"); |
| |
| </script> |