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(1) // only 1 immediate is destroyed 121cb0ef41Sopenharmony_ci}).enable(); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinew async_hooks.AsyncResource('foobar', { requireManualDestroy: true }); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cisetImmediate(() => { 171cb0ef41Sopenharmony_ci global.gc(); 181cb0ef41Sopenharmony_ci setImmediate(() => { 191cb0ef41Sopenharmony_ci hook.disable(); 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci}); 22