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.');
shouldBe('typeof internals.observeGC', '"function"', window.jsTestIsAsync = true;
'this test requires window.internals');
// "Generic Kid's Movie III": ... where nobody dies. function runAsyncGC() {
return new Promise(resolve => asyncGC(resolve));
}
// Do initialization work in an inner function to avoid references to shouldBe('typeof internals.observeGC', '"function"',
// objects remaining live on this function's stack frame. 'this test requires window.internals');
// (http://crbug.com/595672/).
var valueA, observationA;
(function () {
valueA = {};
observationA = internals.observeGC(valueA);
})();
gc(); var valueA, observationA, observationB, observationC;
shouldBeFalse('observationA.wasCollected');
// value ineligible for GC should not be flagged as collected (async () => {
valueA = null; // "Generic Kid's Movie III": ... where nobody dies.
observationA = null;
// Do initialization work in an inner function to avoid references to
// "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies. // objects remaining live on this function's stack frame.
// (http://crbug.com/595672/).
// Do initialization work in an inner function to avoid references to (function () {
// objects remaining live on this function's stack frame. valueA = {};
// (http://crbug.com/595672/). observationA = internals.observeGC(valueA);
var observationB; })();
(function() {
var valueB = {}; gc();
observationB = internals.observeGC(valueB); 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/).
(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/).
(function() {
var valueC = document.createElement('div');
observationC = internals.observeGC(valueC);
})();
await runAsyncGC();
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"');
gc(); // Try to create objects and observers that will die at once
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(); // Do initialization work in an inner function to avoid references to
shouldBeTrue('observationC.wasCollected'); // objects remaining live on this function's stack frame.
// DOM node eligible for GC should be flagged as collected // (http://crbug.com/595672/).
observationC = null; (function() {
var valueD = {};
var observerD = internals.observeGC(valueD);
valueD.observer = observerD;
observerD.observed = valueD;
})();
// Now, movies that failed: gc();
testPassed('did not crash');
shouldThrow('internals.observeGC(undefined)', finishJSTest();
'"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; 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