node/test/parallel/test-zlib-invalid-input-memory.js
James M Snell 97a3a8204c test: replace more uses of global with globalThis
PR-URL: https://github.com/nodejs/node/pull/56712
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2025-01-25 07:23:11 +00:00

29 lines
797 B
JavaScript

// Flags: --expose-gc
'use strict';
const common = require('../common');
const { onGC } = require('../common/gc');
const assert = require('assert');
const zlib = require('zlib');
// Checks that, if a zlib context fails with an error, it can still be GC'ed:
// Refs: https://github.com/nodejs/node/issues/22705
const ongc = common.mustCall();
{
const input = Buffer.from('foobar');
const strm = zlib.createInflate();
strm.end(input);
strm.once('error', common.mustCall((err) => {
assert(err);
setImmediate(() => {
globalThis.gc();
// Keep the event loop alive for seeing the async_hooks destroy hook
// we use for GC tracking...
// TODO(addaleax): This should maybe not be necessary?
setImmediate(() => {});
});
}));
onGC(strm, { ongc });
}