11cb0ef41Sopenharmony_ci// Flags: --expose-gc 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst onGC = require('../common/ongc'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Checks that, if a zlib context fails with an error, it can still be GC'ed: 91cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/22705 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst ongc = common.mustCall(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci{ 141cb0ef41Sopenharmony_ci const input = Buffer.from('foobar'); 151cb0ef41Sopenharmony_ci const strm = zlib.createInflate(); 161cb0ef41Sopenharmony_ci strm.end(input); 171cb0ef41Sopenharmony_ci strm.once('error', common.mustCall((err) => { 181cb0ef41Sopenharmony_ci assert(err); 191cb0ef41Sopenharmony_ci setImmediate(() => { 201cb0ef41Sopenharmony_ci global.gc(); 211cb0ef41Sopenharmony_ci // Keep the event loop alive for seeing the async_hooks destroy hook 221cb0ef41Sopenharmony_ci // we use for GC tracking... 231cb0ef41Sopenharmony_ci // TODO(addaleax): This should maybe not be necessary? 241cb0ef41Sopenharmony_ci setImmediate(() => {}); 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci })); 271cb0ef41Sopenharmony_ci onGC(strm, { ongc }); 281cb0ef41Sopenharmony_ci} 29