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>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/gc.js"></script>
<body>
<script>
description('Tests that the internals.observeGC hook works.');
window.jsTestIsAsync = true;
function runAsyncGC() {
return new Promise(resolve => asyncGC(resolve));
}
shouldBe('typeof internals.observeGC', '"function"',
'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
// objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
var valueA, observationA;
(function () {
// 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 () {
valueA = {};
observationA = internals.observeGC(valueA);
})();
})();
gc();
shouldBeFalse('observationA.wasCollected');
// value ineligible for GC should not be flagged as collected
valueA = null;
observationA = null;
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.
// "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() {
// 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 valueB = {};
observationB = internals.observeGC(valueB);
})();
})();
gc();
shouldBeTrue('observationB.wasCollected');
// value eligible for GC should be flagged as collected
observationB = null;
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.
// "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() {
// 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 valueC = document.createElement('div');
observationC = internals.observeGC(valueC);
})();
})();
gc();
shouldBeTrue('observationC.wasCollected');
// DOM node eligible for GC should be flagged as collected
observationC = null;
await runAsyncGC();
shouldBeTrue('observationC.wasCollected');
// DOM node eligible for GC should be flagged as collected
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"');
shouldThrow('internals.observeGC(null)',
shouldThrow('internals.observeGC(null)',
'"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
// objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
(function() {
// 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');
gc();
testPassed('did not crash');
finishJSTest();
})();
var successfullyParsed = true;
</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