Commit 686612918b6 for nodejs
commit 686612918b6c1d812830743aeb207cd0674593de
Author: Nigro Simone <nigro.simone@gmail.com>
Date: Sat Sep 26 14:59:55 2026 +0200
test: check frame restore in CallbackScope
A CallbackScope must restore the async context frame that was active
before it, when there was none and when there was one.
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66316
Refs: https://github.com/nodejs/performance/issues/24
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
diff --git a/test/addons/callback-scope/test-async-local-storage.js b/test/addons/callback-scope/test-async-local-storage.js
new file mode 100644
index 00000000000..cef08ddfa34
--- /dev/null
+++ b/test/addons/callback-scope/test-async-local-storage.js
@@ -0,0 +1,23 @@
+'use strict';
+
+const common = require('../../common');
+const assert = require('assert');
+const { AsyncLocalStorage } = require('async_hooks');
+const { runInCallbackScope } = require(`./build/${common.buildType}/binding`);
+
+// A CallbackScope must restore the async context frame that was active
+// before it, when there was none and when there was one.
+
+const als = new AsyncLocalStorage();
+
+runInCallbackScope({}, 0, 0, common.mustCall(() => {
+ als.enterWith('inner');
+}));
+assert.strictEqual(als.getStore(), undefined);
+
+als.run('outer', common.mustCall(() => {
+ runInCallbackScope({}, 0, 0, common.mustCall(() => {
+ als.enterWith('inner');
+ }));
+ assert.strictEqual(als.getStore(), 'outer');
+}));