/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; // Test the ObjectCommand add_task(async function testObjectRelease() { const tab = await addTab("data:text/html;charset=utf-8,Test page"); const commands = await CommandsFactory.forTab(tab); await commands.targetCommand.startListening(); const { objectCommand } = commands; const evaluationResponse = await commands.scriptCommand.execute( "window.foo" ); // Execute a second time so that the WebConsoleActor set this._lastConsoleInputEvaluation to another value // and so we prevent freeing `window.foo` await commands.scriptCommand.execute(""); await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { is(content.wrappedJSObject.foo.bar, 42); const weakRef = Cu.getWeakReference(content.wrappedJSObject.foo); // Hold off the weak reference on SpecialPowsers so that it can be accessed in the next SpecialPowers.spawn SpecialPowers.weakRef = weakRef; // Nullify this variable so that it should be freed // unless the DevTools inspection still hold it in memory content.wrappedJSObject.foo = null; Cu.forceGC(); Cu.forceCC(); ok(SpecialPowers.weakRef.get(), "The 'foo' object can't be freed because of DevTools keeping a reference on it"); }); info("Release the server side actors which are keeping the object in memory"); const objectFront = evaluationResponse.result; await commands.objectCommand.releaseObjects([objectFront]); ok(objectFront.isDestroyed(), "The passed object front has been destroyed"); await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { await ContentTaskUtils.waitForCondition(() => { Cu.forceGC(); Cu.forceCC(); return !SpecialPowers.weakRef.get(); }, "Wait for JS object to be freed", 500); ok(!SpecialPowers.weakRef.get(), "The 'foo' object has been freed"); }); await commands.destroy(); BrowserTestUtils.removeTab(tab); }); add_task(async function testMultiTargetObjectRelease() { // This test fails with EFT disabled if (!isEveryFrameTargetEnabled()) { return; } const tab = await addTab(`data:text/html;charset=utf-8,Test page