nodejs/test/parallel/test-finalization-group-error.js
Anna Henningsen fad952adbd
src: use uv_async_t for WeakRefs
Schedule a task on the main event loop, similar to what the HTML
spec recommends for browsers.

Alternative to https://github.com/nodejs/node/pull/30198

PR-URL: https://github.com/nodejs/node/pull/30616
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2019-11-29 02:17:12 +01:00

28 lines
599 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
// Flags: --expose-gc --harmony-weak-refs
const common = require('../common');
const assert = require('assert');
const g = new globalThis.FinalizationGroup(common.mustCallAtLeast(() => {
throw new Error('test');
}, 1));
g.register({}, 42);
setTimeout(() => {
globalThis.gc();
assert.throws(() => {
g.cleanupSome();
}, {
name: 'Error',
message: 'test',
});
// Give the callbacks scheduled by global.gc() time to run, as the underlying
// uv_async_t is unrefed.
setTimeout(() => {}, 200);
}, 200);
process.on('uncaughtException', common.mustCall());