OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 description("Tests the RTCPeerConnection lifetime."); | 8 description("Tests the RTCPeerConnection lifetime."); |
9 | 9 |
10 var dc = null; | 10 var dc = null; |
(...skipping 17 matching lines...) Expand all Loading... |
28 var pc = new webkitRTCPeerConnection({iceServers:[]}, null); | 28 var pc = new webkitRTCPeerConnection({iceServers:[]}, null); |
29 dc = pc.createDataChannel("label"); | 29 dc = pc.createDataChannel("label"); |
30 dc.onopen = dataChannelOpen; | 30 dc.onopen = dataChannelOpen; |
31 } | 31 } |
32 | 32 |
33 var pcB = null; | 33 var pcB = null; |
34 var observationB = null; | 34 var observationB = null; |
35 | 35 |
36 // Test that the PeerConnection object is gc'd if close is called. | 36 // Test that the PeerConnection object is gc'd if close is called. |
37 var pcA = new webkitRTCPeerConnection(null, null); | 37 var pcA = new webkitRTCPeerConnection(null, null); |
38 var observationA = internals.observeGC(pcA); | 38 // Do not pass the object directly to observeGC function. This may |
| 39 // remain live on this function's stack preventing GC from collecting |
| 40 // it. Accessing the object inside an inner function will prevent any |
| 41 // unneeded references on this function's stack. |
| 42 var observationA = internals.observeGC((() => {return pcA;})()); |
39 pcA.close(); | 43 pcA.close(); |
40 pcA = null; | 44 pcA = null; |
41 asyncGC(function() { | 45 asyncGC(function() { |
42 shouldBeTrue('observationA.wasCollected'); | 46 shouldBeTrue('observationA.wasCollected'); |
43 observationA = null; | 47 observationA = null; |
44 | 48 |
45 // Test that the PeerConnection object is not gc'd if close is not called. | 49 // Test that the PeerConnection object is not gc'd if close is not called. |
46 pcB = new webkitRTCPeerConnection(null, null); | 50 pcB = new webkitRTCPeerConnection(null, null); |
47 observationB = internals.observeGC(pcB); | 51 // Do not pass the object directly to observeGC function. This may |
| 52 // remain live on this function's stack preventing GC from collecting |
| 53 // it. Accessing the object inside an inner function will prevent any |
| 54 // unneeded references on this function's stack. |
| 55 observationB = internals.observeGC((() => {return pcB;})()); |
48 pcB = null; | 56 pcB = null; |
49 asyncGC(function() { | 57 asyncGC(function() { |
50 shouldBeFalse('observationB.wasCollected'); | 58 shouldBeFalse('observationB.wasCollected'); |
51 observationB = null; | 59 observationB = null; |
52 | 60 |
53 // This test times out if the Peer connection object is garbage collecte
d. | 61 // This test times out if the Peer connection object is garbage collecte
d. |
54 createPeerConnectionAndDataChannel(); | 62 createPeerConnectionAndDataChannel(); |
55 gc(); | 63 gc(); |
56 }); | 64 }); |
57 }); | 65 }); |
58 | 66 |
59 window.jsTestIsAsync = true; | 67 window.jsTestIsAsync = true; |
60 </script> | 68 </script> |
61 </body> | 69 </body> |
62 </html> | 70 </html> |
OLD | NEW |