33
44using Microsoft . JavaScript . NodeApi ;
55using Microsoft . JavaScript . NodeApi . Interop ;
6+ using Microsoft . JavaScript . NodeApi . Runtime ;
67using static Hermes . Example . HermesApi . Interop ;
7- using static Microsoft . JavaScript . NodeApi . JSNativeApi . Interop ;
8+ using static Microsoft . JavaScript . NodeApi . Runtime . JSRuntime ;
89
910namespace Hermes . Example ;
1011
@@ -26,10 +27,10 @@ public sealed class HermesRuntime : IDisposable
2627 private HermesRuntime ( JSDispatcherQueue dispatcherQueue )
2728 {
2829 _dispatcherQueue = dispatcherQueue ;
29- HermesApi . Load ( "hermes.dll" ) ;
30+ JSRuntime runtime = HermesApi . Load ( "hermes.dll" ) ;
3031 using HermesConfig tempConfig = new ( ) ;
3132 hermes_create_runtime ( ( hermes_config ) tempConfig , out _runtime ) . ThrowIfFailed ( ) ;
32- _rootScope = new JSValueScope ( JSValueScopeType . Root , ( napi_env ) this ) ;
33+ _rootScope = new JSValueScope ( JSValueScopeType . Root , ( napi_env ) this , runtime ) ;
3334 CreatePolyfills ( ) ;
3435 }
3536
@@ -103,37 +104,37 @@ private void CreatePolyfills()
103104 JSValue global = JSValue . Global ;
104105 global [ "global" ] = global ;
105106
106- global [ "setImmediate" ] = ( JSCallback ) ( args =>
107+ global [ "setImmediate" ] = new JSFunction ( "setImmediate" , args =>
107108 {
108109 JSValue immediateCallback = AsFunction ( args , 0 ) ;
109110 int taskId = AddImmediateTask ( immediateCallback ) ;
110111 return taskId ;
111112 } ) ;
112113
113- global [ "clearImmediate" ] = ( JSCallback ) ( args =>
114+ global [ "clearImmediate" ] = new JSFunction ( "clearImmediate" , args =>
114115 {
115116 int taskId = AsInt32 ( args , 0 ) ;
116117 RemoveImmediateTask ( taskId ) ;
117118 return default ;
118119 } ) ;
119120
120- global [ "setTimeout" ] = ( JSCallback ) ( args =>
121+ global [ "setTimeout" ] = new JSFunction ( "setTimeout" , args =>
121122 {
122123 JSValue timeoutCallback = AsFunction ( args , 0 ) ;
123124 int delayInMs = AsInt32 ( args , 1 ) ;
124125 int taskId = AddTimerTask ( timeoutCallback , delayInMs ) ;
125126 return taskId ;
126127 } ) ;
127128
128- global [ "clearTimeout" ] = ( JSCallback ) ( args =>
129+ global [ "clearTimeout" ] = new JSFunction ( "clearTimeout" , args =>
129130 {
130131 int taskId = AsInt32 ( args , 0 ) ;
131132 RemoveTimerTask ( taskId ) ;
132133 return default ;
133134 } ) ;
134135
135136 var console = new JSObject ( ) ;
136- console [ "log" ] = ( JSCallback ) ( args =>
137+ console [ "log" ] = new JSFunction ( "log" , args =>
137138 {
138139 Console . WriteLine ( ( string ) args [ 0 ] . CoerceToString ( ) ) ;
139140 return default ;
0 commit comments