@@ -7,28 +7,17 @@ const {
77
88let enabled_ ;
99
10- class AsyncContextFrame extends Map {
11- constructor ( store , data ) {
12- super ( AsyncContextFrame . current ( ) ) ;
13- this . set ( store , data ) ;
14- }
15-
10+ class ActiveAsyncContextFrame {
1611 static get enabled ( ) {
17- enabled_ ??= require ( 'internal/options' )
18- . getOptionValue ( '--experimental-async-context-frame' ) ;
19- return enabled_ ;
12+ return true ;
2013 }
2114
2215 static current ( ) {
23- if ( this . enabled ) {
24- return getContinuationPreservedEmbedderData ( ) ;
25- }
16+ return getContinuationPreservedEmbedderData ( ) ;
2617 }
2718
2819 static set ( frame ) {
29- if ( this . enabled ) {
30- setContinuationPreservedEmbedderData ( frame ) ;
31- }
20+ setContinuationPreservedEmbedderData ( frame ) ;
3221 }
3322
3423 static exchange ( frame ) {
@@ -41,6 +30,36 @@ class AsyncContextFrame extends Map {
4130 const frame = this . current ( ) ;
4231 frame ?. disable ( store ) ;
4332 }
33+ }
34+
35+ function checkEnabled ( ) {
36+ const enabled = require ( 'internal/options' )
37+ . getOptionValue ( '--experimental-async-context-frame' ) ;
38+
39+ // If enabled, swap to active prototype so we don't need to check status
40+ // on every interaction with the async context frame.
41+ if ( enabled ) {
42+ ObjectSetPrototypeOf ( AsyncContextFrame , ActiveAsyncContextFrame ) ;
43+ }
44+
45+ return enabled ;
46+ }
47+
48+ class AsyncContextFrame extends Map {
49+ constructor ( store , data ) {
50+ super ( AsyncContextFrame . current ( ) ) ;
51+ this . set ( store , data ) ;
52+ }
53+
54+ static get enabled ( ) {
55+ enabled_ ??= checkEnabled ( ) ;
56+ return enabled_ ;
57+ }
58+
59+ static current ( ) { }
60+ static set ( frame ) { }
61+ static exchange ( frame ) { }
62+ static disable ( store ) { }
4463
4564 disable ( store ) {
4665 this . delete ( store ) ;
0 commit comments