Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/netinfo/gc-frame-listeners.html |
| diff --git a/third_party/WebKit/LayoutTests/netinfo/gc-frame-listeners.html b/third_party/WebKit/LayoutTests/netinfo/gc-frame-listeners.html |
| index 1112ed393c207bd74941034a63baff0fe5440d1c..de80777c564a32191764a24591b7a9ebcb36a9fc 100644 |
| --- a/third_party/WebKit/LayoutTests/netinfo/gc-frame-listeners.html |
| +++ b/third_party/WebKit/LayoutTests/netinfo/gc-frame-listeners.html |
| @@ -11,33 +11,27 @@ description('Tests that listeners in closed frames are collected.'); |
| shouldBe('typeof window.internals.observeGC', '"function"', |
| 'this test requires window.internals'); |
| -var childFrame = document.createElement('iframe'); |
| -// Do not pass the object directly to observeGC function. This may |
| -// remain live on this function's stack preventing GC from collecting |
| -// it. Accessing the object inside an inner function will prevent any |
| -// unneeded references on this function's stack. |
| -var childFrameObserver = internals.observeGC((() => {return childFrame;})()); |
| - |
| -document.body.appendChild(childFrame); |
| - |
| -var childConnection = childFrame.contentWindow.navigator.connection; |
| -// Do not pass the object directly to observeGC function. This may |
| -// remain live on this function's stack preventing GC from collecting |
| -// it. Accessing the object inside an inner function will prevent any |
| -// unneeded references on this function's stack. |
| -var childConnectionObserver = internals.observeGC((() => {return childConnection;})()); |
| +var childFrame, childConnection; |
| +var childFrameObserver, childConnectionObserver; |
| var callback = function(e) { |
| testFailed("Should not get here."); |
| }; |
| -// Do not pass the object directly to observeGC function. This may |
| -// remain live on this function's stack preventing GC from collecting |
| -// it. Accessing the object inside an inner function will prevent any |
| -// unneeded references on this function's stack. |
| -var callbackObserver = internals.observeGC((() => {return callback;})()); |
| - |
| -// Add the event listener and make sure it doesn't get collected. |
| -childConnection.addEventListener('typechange', callback); |
| + |
| +// Do initialization work in an inner function to avoid references to |
| +// objects remaining live on this function's stack frame. |
| +// (http://crbug.com/595672/). |
| +function initialize() { |
| + childFrame = document.createElement('iframe'); |
| + childFrameObserver = internals.observeGC(childFrame); |
| + document.body.appendChild(childFrame); |
| + childConnection = childFrame.contentWindow.navigator.connection; |
| + childConnectionObserver = internals.observeGC(childConnection); |
| + callbackObserver = internals.observeGC(callback); |
| + childConnection.addEventListener('typechange', callback); |
| +} |
| + |
| +initialize(); |
| childConnection = null; |
| callback = null; |
|
rmcilroy
2016/05/20 14:53:39
nit - could you move childConnection and callback
mythria
2016/05/23 10:35:44
Done.
|
| gc(); |
| @@ -46,7 +40,9 @@ shouldBeFalse('childFrameObserver.wasCollected'); |
| shouldBeFalse('childConnectionObserver.wasCollected'); |
| shouldBeFalse('callbackObserver.wasCollected'); |
| -document.body.removeChild(childFrame); |
| +// Access objects in an inner function to avoid references to objects |
| +// remaining live on this function's stack frame (http://crbug.com/595672/). |
| +(() => {document.body.removeChild(childFrame);})(); |
| childFrame = null; |
| gc(); |
| shouldBeTrue('childFrameObserver.wasCollected'); |