11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose_gc 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that userland-only AsyncResources cause a destroy event to 51cb0ef41Sopenharmony_ci// be emitted when they get gced. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst common = require('../common'); 81cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst hook = async_hooks.createHook({ 111cb0ef41Sopenharmony_ci destroy: common.mustCallAtLeast(2) // 1 immediate + manual destroy 121cb0ef41Sopenharmony_ci}).enable(); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci{ 151cb0ef41Sopenharmony_ci const res = new async_hooks.AsyncResource('foobar'); 161cb0ef41Sopenharmony_ci res.emitDestroy(); 171cb0ef41Sopenharmony_ci} 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_cisetImmediate(() => { 201cb0ef41Sopenharmony_ci global.gc(); 211cb0ef41Sopenharmony_ci setImmediate(() => { 221cb0ef41Sopenharmony_ci hook.disable(); 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci}); 25