@@ -51,6 +51,7 @@ public static void Main(string[] args)
5151 "libnode" + GetSharedLibraryExtension ( ) ) ;
5252
5353 private napi_env _env ;
54+ private JSValue _jsString ;
5455 private JSFunction _jsFunction ;
5556 private JSFunction _jsFunctionWithArgs ;
5657 private JSFunction _jsFunctionWithCallback ;
@@ -95,13 +96,14 @@ protected void Setup()
9596
9697 // Create some JS values that will be used by the benchmarks.
9798
98- _jsFunction = ( JSFunction ) JSNativeApi . RunScript ( "function jsFunction() { }; jsFunction" ) ;
99- _jsFunctionWithArgs = ( JSFunction ) JSNativeApi . RunScript (
99+ _jsString = JSValue . RunScript ( "'Hello Node-API .Net!'" ) ;
100+ _jsFunction = ( JSFunction ) JSValue . RunScript ( "function jsFunction() { }; jsFunction" ) ;
101+ _jsFunctionWithArgs = ( JSFunction ) JSValue . RunScript (
100102 "function jsFunctionWithArgs(a, b, c) { }; jsFunctionWithArgs" ) ;
101- _jsFunctionWithCallback = ( JSFunction ) JSNativeApi . RunScript (
103+ _jsFunctionWithCallback = ( JSFunction ) JSValue . RunScript (
102104 "function jsFunctionWithCallback(cb, ...args) { cb(...args); }; " +
103105 "jsFunctionWithCallback" ) ;
104- _jsInstance = ( JSObject ) JSNativeApi . RunScript (
106+ _jsInstance = ( JSObject ) JSValue . RunScript (
105107 "const jsInstance = { method: (...args) => {} }; jsInstance" ) ;
106108
107109 _dotnetFunction = ( JSFunction ) JSValue . CreateFunction (
@@ -125,15 +127,15 @@ protected void Setup()
125127 ( x , value ) => x . Property = ( string ) value ) ;
126128 classBuilder . AddMethod ( "method" , ( x ) => ( args ) => DotnetClass . Method ( ) ) ;
127129 _dotnetClass = ( JSObject ) classBuilder . DefineClass ( ) ;
128- _dotnetInstance = ( JSObject ) JSNativeApi . CallAsConstructor ( _dotnetClass ) ;
130+ _dotnetInstance = ( JSObject ) ( ( JSValue ) _dotnetClass ) . CallAsConstructor ( ) ;
129131
130- _jsFunctionCreateInstance = ( JSFunction ) JSNativeApi . RunScript (
132+ _jsFunctionCreateInstance = ( JSFunction ) JSValue . RunScript (
131133 "function jsFunctionCreateInstance(Class) { new Class() }; " +
132134 "jsFunctionCreateInstance" ) ;
133- _jsFunctionCallMethod = ( JSFunction ) JSNativeApi . RunScript (
135+ _jsFunctionCallMethod = ( JSFunction ) JSValue . RunScript (
134136 "function jsFunctionCallMethod(instance) { instance.method(); }; " +
135137 "jsFunctionCallMethod" ) ;
136- _jsFunctionCallMethodWithArgs = ( JSFunction ) JSNativeApi . RunScript (
138+ _jsFunctionCallMethodWithArgs = ( JSFunction ) JSValue . RunScript (
137139 "function jsFunctionCallMethodWithArgs(instance, ...args) " +
138140 "{ instance.method(...args); }; " +
139141 "jsFunctionCallMethodWithArgs" ) ;
@@ -145,6 +147,18 @@ protected void Setup()
145147
146148 // Benchmarks in the base class run in both CLR and AOT environments.
147149
150+ [ Benchmark ]
151+ public void JSValueToString ( )
152+ {
153+ _jsString . GetValueStringUtf16 ( ) ;
154+ }
155+
156+ [ Benchmark ]
157+ public void JSValueToStringAsCharArray ( )
158+ {
159+ _ = new string ( _jsString . GetValueStringUtf16AsCharArray ( ) ) ;
160+ }
161+
148162 [ Benchmark ]
149163 public void CallJSFunction ( )
150164 {
@@ -229,13 +243,13 @@ public class Clr : Benchmarks
229243 JSObject hostModule = new ( ) ;
230244 _ = new ManagedHost ( hostModule ) ;
231245 _jsHost = hostModule ;
232- _jsFunctionCallMethodDynamic = ( JSFunction ) JSNativeApi . RunScript (
246+ _jsFunctionCallMethodDynamic = ( JSFunction ) JSValue . RunScript (
233247 "function jsFunctionCallMethodDynamic(dotnet) " +
234248 "{ dotnet.System.Object.ReferenceEquals(null, null); }; " +
235249 "jsFunctionCallMethodDynamic" ) ;
236250
237251 // Implement IFormatProvider in JS and pass it to a .NET method.
238- _jsFunctionCallMethodDynamicInterface = ( JSFunction ) JSNativeApi . RunScript (
252+ _jsFunctionCallMethodDynamicInterface = ( JSFunction ) JSValue . RunScript (
239253 "function jsFunctionCallMethodDynamicInterface(dotnet) {" +
240254 " const formatProvider = { GetFormat: (type) => null };" +
241255 " dotnet.System.String.Format(formatProvider, '', null, null);" +
0 commit comments