Skip to content

Commit df4b7ba

Browse files
bengltpoisseau
authored andcommitted
async_hooks: add an InactiveAsyncContextFrame class
This gives a class prototype for AsyncContextFrame that contains the required methods, so that when we swap the prototype, ActiveAsyncContextFrame methods are used instead. Previously, the methods were defined in AsyncContextFrame, so swapping the prototype didn't swap those static methods. Also, make the ActiveAsyncContextFrame extend from Map. Fixes: nodejs#54503 PR-URL: nodejs#54510 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent e525eb0 commit df4b7ba

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/internal/async_context_frame.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111

1212
let enabled_;
1313

14-
class ActiveAsyncContextFrame {
14+
class ActiveAsyncContextFrame extends Map {
1515
static get enabled() {
1616
return true;
1717
}
@@ -50,12 +50,7 @@ function checkEnabled() {
5050
return enabled;
5151
}
5252

53-
class AsyncContextFrame extends Map {
54-
constructor(store, data) {
55-
super(AsyncContextFrame.current());
56-
this.set(store, data);
57-
}
58-
53+
class InactiveAsyncContextFrame extends Map {
5954
static get enabled() {
6055
enabled_ ??= checkEnabled();
6156
return enabled_;
@@ -65,6 +60,13 @@ class AsyncContextFrame extends Map {
6560
static set(frame) {}
6661
static exchange(frame) {}
6762
static disable(store) {}
63+
}
64+
65+
class AsyncContextFrame extends InactiveAsyncContextFrame {
66+
constructor(store, data) {
67+
super(AsyncContextFrame.current());
68+
this.set(store, data);
69+
}
6870

6971
disable(store) {
7072
this.delete(store);

test/parallel/test-async-context-frame.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { opendir } from 'node:fs/promises';
55
import { fileURLToPath } from 'node:url';
66
import { describe, it } from 'node:test';
77
import { sep } from 'node:path';
8+
import { strictEqual } from 'node:assert';
89

910
const python = process.env.PYTHON || (isWindows ? 'python' : 'python3');
1011

@@ -53,7 +54,8 @@ describe('AsyncContextFrame', {
5354
stdio: ['ignore', 'ignore', 'inherit'],
5455
});
5556

56-
await once(proc, 'exit');
57+
const [code] = await once(proc, 'exit');
58+
strictEqual(code, 0, `Test ${test} failed with exit code ${code}`);
5759
});
5860
}
5961
});

0 commit comments

Comments
 (0)