mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 20:08:02 +00:00

In particular, this comes into play in the node repl, which apparently enables domains by default. Whenever any Promise gets inspected, a `.domain` property is displayed, which is *very confusing*, especially since it has some kind of WeakReference attached to it, which is not yet a language feature. This change will prevent it from showing up in casual inspection, but will leave it available for use. PR-URL: https://github.com/nodejs/node/pull/26210 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
// Flags: --expose-gc
|
|
'use strict';
|
|
const common = require('../common');
|
|
const onGC = require('../common/ongc');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
const domain = require('domain');
|
|
const EventEmitter = require('events');
|
|
const isEnumerable = Function.call.bind(Object.prototype.propertyIsEnumerable);
|
|
|
|
// This test makes sure that the (async id → domain) map which is part of the
|
|
// domain module does not get in the way of garbage collection.
|
|
// See: https://github.com/nodejs/node/issues/23862
|
|
|
|
let d = domain.create();
|
|
d.run(() => {
|
|
const resource = new async_hooks.AsyncResource('TestResource');
|
|
const emitter = new EventEmitter();
|
|
|
|
d.remove(emitter);
|
|
d.add(emitter);
|
|
|
|
emitter.linkToResource = resource;
|
|
assert.strictEqual(emitter.domain, d);
|
|
assert.strictEqual(isEnumerable(emitter, 'domain'), false);
|
|
assert.strictEqual(resource.domain, d);
|
|
assert.strictEqual(isEnumerable(resource, 'domain'), false);
|
|
|
|
// This would otherwise be a circular chain now:
|
|
// emitter → resource → async id ⇒ domain → emitter.
|
|
// Make sure that all of these objects are released:
|
|
|
|
onGC(resource, { ongc: common.mustCall() });
|
|
onGC(d, { ongc: common.mustCall() });
|
|
onGC(emitter, { ongc: common.mustCall() });
|
|
});
|
|
|
|
d = null;
|
|
global.gc();
|