Files
node/test/parallel/test-als-defaultvalue.js
Matteo Collina 984aa0c25e async_hooks: remove legacy AsyncLocalStorage implementation
Remove the async_hooks-based AsyncLocalStorage fallback and the
--no-async-context-frame flag, making AsyncContextFrame the sole
implementation.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/63641
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2026-10-03 06:41:28 +00:00

37 lines
998 B
JavaScript

'use strict';
require('../common');
const {
AsyncLocalStorage,
} = require('async_hooks');
const assert = require('assert');
// ============================================================================
// The defaultValue option
const als1 = new AsyncLocalStorage();
assert.strictEqual(als1.getStore(), undefined);
const als2 = new AsyncLocalStorage({ defaultValue: 'default' });
assert.strictEqual(als2.getStore(), 'default');
const als3 = new AsyncLocalStorage({ defaultValue: 42 });
assert.strictEqual(als3.getStore(), 42);
const als4 = new AsyncLocalStorage({ defaultValue: null });
assert.strictEqual(als4.getStore(), null);
assert.throws(() => new AsyncLocalStorage(null), {
code: 'ERR_INVALID_ARG_TYPE',
});
// ============================================================================
// The name option
const als5 = new AsyncLocalStorage({ name: 'test' });
assert.strictEqual(als5.name, 'test');
const als6 = new AsyncLocalStorage();
assert.strictEqual(als6.name, '');