Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make sure weak references are not GCed to early #27482

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ util.inspect(process);
assert.strict.equal(out, expected);
}

{ // Test WeakMap
{ // Test WeakMap && WeakSet
const obj = {};
const arr = [];
const weakMap = new WeakMap([[obj, arr], [arr, obj]]);
Expand All @@ -1634,16 +1634,16 @@ util.inspect(process);
out = util.inspect(weakMap, { maxArrayLength: 1, showHidden: true });
// It is not possible to determine the output reliable.
expect = 'WeakMap { [ [length]: 0 ] => {}, ... 1 more item, extra: true }';
const expectAlt = 'WeakMap { {} => [ [length]: 0 ], ... 1 more item, ' +
'extra: true }';
let expectAlt = 'WeakMap { {} => [ [length]: 0 ], ... 1 more item, ' +
'extra: true }';
assert(out === expect || out === expectAlt,
`Found: "${out}"\nrather than: "${expect}"\nor: "${expectAlt}"`);
}

{ // Test WeakSet
const weakSet = new WeakSet([{}, [1]]);
let out = util.inspect(weakSet, { showHidden: true });
let expect = 'WeakSet { [ 1, [length]: 1 ], {} }';
// Test WeakSet
arr.push(1);
const weakSet = new WeakSet([obj, arr]);
out = util.inspect(weakSet, { showHidden: true });
expect = 'WeakSet { [ 1, [length]: 1 ], {} }';
assert.strictEqual(out, expect);

out = util.inspect(weakSet);
Expand All @@ -1658,10 +1658,12 @@ util.inspect(process);
out = util.inspect(weakSet, { maxArrayLength: 1, showHidden: true });
// It is not possible to determine the output reliable.
expect = 'WeakSet { {}, ... 1 more item, extra: true }';
const expectAlt = 'WeakSet { [ 1, [length]: 1 ], ... 1 more item, ' +
'extra: true }';
expectAlt = 'WeakSet { [ 1, [length]: 1 ], ... 1 more item, extra: true }';
assert(out === expect || out === expectAlt,
`Found: "${out}"\nrather than: "${expect}"\nor: "${expectAlt}"`);
// Keep references to the WeakMap entries, otherwise they could be GCed too
// early.
assert(obj && arr);
}

{ // Test argument objects.
Expand Down