blob: 5521c6c52a20eb103b1166ac53cf64762cd04c3e [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<body>
<script>
description('Tests that the window.internals.observeGC hook works.');
shouldBe('typeof window.internals.observeGC', '"function"',
'this test requires window.internals');
// "Generic Kid's Movie III": ... where nobody dies.
// Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
var valueA, observationA;
(function () {
valueA = {};
observationA = internals.observeGC(valueA);
})();
gc();
shouldBeFalse('observationA.wasCollected');
// value ineligible for GC should not be flagged as collected
valueA = null;
observationA = null;
// "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies.
// Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
var observationB;
(function() {
var valueB = {};
observationB = internals.observeGC(valueB);
})();
gc();
shouldBeTrue('observationB.wasCollected');
// value eligible for GC should be flagged as collected
observationB = null;
// "One DOM Tree Hill": A family struggles with the loss of
// innocence. And a DOM node.
// Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
var observationC;
(function() {
var valueC = document.createElement('div');
observationC = internals.observeGC(valueC);
})();
gc();
shouldBeTrue('observationC.wasCollected');
// DOM node eligible for GC should be flagged as collected
observationC = null;
// Now, movies that failed:
shouldThrow('internals.observeGC(undefined)',
'"TypeError: value to observe is null or undefined"');
shouldThrow('internals.observeGC(null)',
'"TypeError: value to observe is null or undefined"');
// Try to create objects and observers that will die at once
// 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() {
var valueD = {};
var observerD = internals.observeGC(valueD);
valueD.observer = observerD;
observerD.observed = valueD;
})();
gc();
testPassed('did not crash');
var successfullyParsed = true;
</script>