diff --git a/src/context.ts b/src/context.ts index f456e7cb4e..8236217b12 100644 --- a/src/context.ts +++ b/src/context.ts @@ -47,7 +47,6 @@ export function getCtx() { } export function setRootCtx(ctx: Options) { - storage.enterWith(ctx) root = ctx } diff --git a/src/core.ts b/src/core.ts index 3a1e2b3e8d..1f655f7d3b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -89,8 +89,12 @@ export class ProcessPromise extends Promise { readonly ctx: Context constructor(cb: (resolve: Function, reject?: Function) => void) { super(cb) - this.ctx = {...getCtx()} - Object.defineProperty(this, 'ctx', { value: this.ctx, writable: false, configurable: false }) + this.ctx = { ...getCtx() } + Object.defineProperty(this, 'ctx', { + value: this.ctx, + writable: false, + configurable: false, + }) } get stdin() { diff --git a/test/experimental.test.js b/test/experimental.test.js index 1dd040095d..0336945f69 100644 --- a/test/experimental.test.js +++ b/test/experimental.test.js @@ -111,6 +111,23 @@ test('ctx() provides isolates running scopes', async () => { $.verbose = false }) +test('bound ctx is attached to Promise', async () => { + const kResourceStoreSymbol = Object.getOwnPropertySymbols( + new Promise(() => {}) + )[2] + assert.is(new Promise(() => {})[kResourceStoreSymbol], undefined) + + await ctx(async ($) => { + await ctx(async ($) => { + assert.is(new Promise(() => {})[kResourceStoreSymbol], $) + }) + + assert.is(new Promise(() => {})[kResourceStoreSymbol], $) + }) + + assert.is(new Promise(() => {})[kResourceStoreSymbol], undefined) +}) + test('log() API is available', () => { assert.ok(typeof log === 'function') })