blob: 6ff207c83cbfa136ea5b450a3b284c4de8d2901a [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/js-test.js"></script>
<script src="resources/netinfo_common.js"></script>
description('Tests that unused listeners are collected.');
shouldBe('typeof window.internals.observeGC', '"function"',
'this test requires window.internals');
let callback = function(e) {
testFailed("Should not get here.");
// Add a listener.
var callbackObserver;
// Do not pass the object directly to observeGC function. It 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. (
(function() {
callbackObserver = internals.observeGC(callback);
connection.addEventListener('typechange', callback);
// Remove the listener and its callback reference.
// Access objects in an inner function to avoid references to objects
// remaining live on this function's stack frame (
(() => {connection.removeEventListener('typechange', callback);})();
callback = null;