Bug 1603330 - Update test to prevent JIT keeps the retval of wr.deref(). r=jonco

Move allocation into a function call can prevent JIT keeps the return
value of weakRef.deref().

Differential Revision: https://phabricator.services.mozilla.com/D60662

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yoshi Cheng-Hao Huang 2020-01-23 14:15:51 +00:00
parent 2dd304ff1d
commit b4e01399cf
2 changed files with 25 additions and 7 deletions

View File

@ -0,0 +1,18 @@
// |jit-test| --enable-weak-refs
// Allocate the object in the function to prevent marked as a singleton so the
// object won't be kept alive by IC stub.
function allocObj() { return {}; }
let wr;
{
let obj = allocObj();
wr = new WeakRef(obj);
}
assertEq(wr.deref() !== undefined, true);
clearKeptObjects();
gc();
assertEq(wr.deref(), undefined);

View File

@ -44,17 +44,17 @@ var that = this;
gc();
let wr1;
(function() {
let obj = {};
// Allocate the object in the function to prevent marked as a singleton so the
// object won't be kept alive by IC stub.
function allocObj() { return {}; }
(function () {
let obj = allocObj();
wr1 = new WeakRef(obj);
obj = null;
})();
// TODO:
// Bug 1603330: WeakRef.deref() makes the target being kept even
// ClearKeptObjects() is called.
//
// don't call wr1.deref() here to prevent the target of wr1 is kept.
assertEq(undefined === wr1.deref(), false);
gc();