Commit 760714f2 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Fix internals-observe-gc.html to run precise BlinkGC

We should use asyncGC() instead of gc() to ensure a precise BlinkGC runs, so the wrapper object is collected.

Bug: 1003268
Change-Id: I8210d6d718adb3490752c28f7647f287800d2c9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1800855Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696685}
parent 04dc0257
<!DOCTYPE html> <!DOCTYPE html>
<script src="../../resources/js-test.js"></script> <script src="../../resources/js-test.js"></script>
<script src="../../resources/gc.js"></script>
<body> <body>
<script> <script>
description('Tests that the internals.observeGC hook works.'); description('Tests that the internals.observeGC hook works.');
window.jsTestIsAsync = true;
function runAsyncGC() {
return new Promise(resolve => asyncGC(resolve));
}
shouldBe('typeof internals.observeGC', '"function"', shouldBe('typeof internals.observeGC', '"function"',
'this test requires window.internals'); 'this test requires window.internals');
// "Generic Kid's Movie III": ... where nobody dies. var valueA, observationA, observationB, observationC;
(async () => {
// "Generic Kid's Movie III": ... where nobody dies.
// Do initialization work in an inner function to avoid references to // Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame. // objects remaining live on this function's stack frame.
// (http://crbug.com/595672/). // (http://crbug.com/595672/).
var valueA, observationA; (function () {
(function () {
valueA = {}; valueA = {};
observationA = internals.observeGC(valueA); observationA = internals.observeGC(valueA);
})(); })();
gc(); gc();
shouldBeFalse('observationA.wasCollected'); shouldBeFalse('observationA.wasCollected');
// value ineligible for GC should not be flagged as collected // value ineligible for GC should not be flagged as collected
valueA = null; valueA = null;
observationA = null; observationA = null;
// "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies. // "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies.
// Do initialization work in an inner function to avoid references to // Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame. // objects remaining live on this function's stack frame.
// (http://crbug.com/595672/). // (http://crbug.com/595672/).
var observationB; (function() {
(function() {
var valueB = {}; var valueB = {};
observationB = internals.observeGC(valueB); observationB = internals.observeGC(valueB);
})(); })();
gc(); gc();
shouldBeTrue('observationB.wasCollected'); shouldBeTrue('observationB.wasCollected');
// value eligible for GC should be flagged as collected // value eligible for GC should be flagged as collected
observationB = null; observationB = null;
// "One DOM Tree Hill": A family struggles with the loss of // "One DOM Tree Hill": A family struggles with the loss of
// innocence. And a DOM node. // innocence. And a DOM node.
// Do initialization work in an inner function to avoid references to // Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame. // objects remaining live on this function's stack frame.
// (http://crbug.com/595672/). // (http://crbug.com/595672/).
var observationC; (function() {
(function() {
var valueC = document.createElement('div'); var valueC = document.createElement('div');
observationC = internals.observeGC(valueC); observationC = internals.observeGC(valueC);
})(); })();
gc(); await runAsyncGC();
shouldBeTrue('observationC.wasCollected'); shouldBeTrue('observationC.wasCollected');
// DOM node eligible for GC should be flagged as collected // DOM node eligible for GC should be flagged as collected
observationC = null; observationC = null;
// Now, movies that failed: // Now, movies that failed:
shouldThrow('internals.observeGC(undefined)', shouldThrow('internals.observeGC(undefined)',
'"TypeError: value to observe is null or undefined"'); '"TypeError: value to observe is null or undefined"');
shouldThrow('internals.observeGC(null)', shouldThrow('internals.observeGC(null)',
'"TypeError: value to observe is null or undefined"'); '"TypeError: value to observe is null or undefined"');
// Try to create objects and observers that will die at once // Try to create objects and observers that will die at once
// Do initialization work in an inner function to avoid references to // Do initialization work in an inner function to avoid references to
// objects remaining live on this function's stack frame. // objects remaining live on this function's stack frame.
// (http://crbug.com/595672/). // (http://crbug.com/595672/).
(function() { (function() {
var valueD = {}; var valueD = {};
var observerD = internals.observeGC(valueD); var observerD = internals.observeGC(valueD);
valueD.observer = observerD; valueD.observer = observerD;
observerD.observed = valueD; observerD.observed = valueD;
})(); })();
gc(); gc();
testPassed('did not crash'); testPassed('did not crash');
finishJSTest();
})();
var successfullyParsed = true; var successfullyParsed = true;
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment