@@ -50,7 +50,8 @@ public static void Main(string[] args)
50
50
GetCurrentPlatformRuntimeIdentifier ( ) ,
51
51
"libnode" + GetSharedLibraryExtension ( ) ) ;
52
52
53
- private napi_env _env ;
53
+ private NodeEmbeddingRuntime ? _runtime ;
54
+ private NodeEmbeddingNodeApiScope ? _nodeApiScope ;
54
55
private JSValue _jsString ;
55
56
private JSFunction _jsFunction ;
56
57
private JSFunction _jsFunctionWithArgs ;
@@ -64,6 +65,9 @@ public static void Main(string[] args)
64
65
private JSFunction _jsFunctionCallMethod ;
65
66
private JSFunction _jsFunctionCallMethodWithArgs ;
66
67
private JSReference _reference = null ! ;
68
+ private static readonly string [ ] s_settings = new [ ] { "node" , "--expose-gc" } ;
69
+ private static string s_mainScript { get ; } =
70
+ "globalThis.require = require('module').createRequire(process.execPath);\n " ;
67
71
68
72
/// <summary>
69
73
/// Simple class that is exported to JS and used in some benchmarks.
@@ -84,16 +88,19 @@ public static void Method() { }
84
88
/// </summary>
85
89
protected void Setup ( )
86
90
{
87
- NodejsPlatform platform = new ( LibnodePath /*, args: new[] { "node", "--expose-gc" }*/ ) ;
88
-
89
- // This setup avoids using NodejsEnvironment so benchmarks can run on the same thread.
90
- // NodejsEnvironment creates a separate thread that would slow down the micro-benchmarks.
91
- platform . Runtime . CreateEnvironment (
92
- platform , Console . WriteLine , null , NodejsEnvironment . NodeApiVersion , out _env )
93
- . ThrowIfFailed ( ) ;
94
-
95
- // The new scope instance saves itself as the thread-local JSValueScope.Current.
96
- JSValueScope scope = new ( JSValueScopeType . Root , _env , platform . Runtime ) ;
91
+ NodeEmbeddingPlatform platform = new (
92
+ LibnodePath ,
93
+ new NodeEmbeddingPlatformSettings { Args = s_settings } ) ;
94
+
95
+ // This setup avoids using NodejsEmbeddingThreadRuntime so benchmarks can run on
96
+ // the same thread. NodejsEmbeddingThreadRuntime creates a separate thread that would slow
97
+ // down the micro-benchmarks.
98
+ _runtime = NodeEmbeddingRuntime . Create ( platform ,
99
+ new NodeEmbeddingRuntimeSettings { MainScript = s_mainScript } ) ;
100
+
101
+ // The nodeApiScope creates JSValueScope instance that saves itself as
102
+ // the thread-local JSValueScope.Current.
103
+ _nodeApiScope = new ( _runtime ) ;
97
104
98
105
// Create some JS values that will be used by the benchmarks.
99
106
0 commit comments