Skip to content

Commit 6e46ef8

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore was made switch to new ChakraCore API
1 parent 2065447 commit 6e46ef8

File tree

11 files changed

+37
-115
lines changed

11 files changed

+37
-115
lines changed

NuGet/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.nuspec

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
For correct working of the ChakraCore require assemblies `msvcp120.dll` and `msvcr120.dll` from the Visual C++ Redistributable Packages for Visual Studio 2013.</description>
1616
<summary>JavaScriptEngineSwitcher.ChakraCore contains adapter `ChakraCoreJsEngine` (wrapper for the ChakraCore version 1.3).</summary>
17-
<releaseNotes>1. Added support of .NET Core 1.0.1 and .NET Framework 4.5.1;
18-
2. ChakraCore was updated to version 1.3;
19-
3. Added the ability to change configuration settings of the ChakraCore JS engine: `DisableBackgroundWork` (default `false`), `DisableNativeCodeGeneration` (default `false`), `DisableEval` (default `false`) and `EnableExperimentalFeatures` (default `false`).</releaseNotes>
17+
<releaseNotes>Was made switch to new ChakraCore API.</releaseNotes>
2018
<copyright>Copyright (c) 2013-2016 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2119
<language>en-US</language>
2220
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript ChakraCore</tags>

NuGet/JavaScriptEngineSwitcher.ChakraCore/readme.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
=============
2525
RELEASE NOTES
2626
=============
27-
1. Added support of .NET Core 1.0.1 and .NET Framework 4.5.1;
28-
2. ChakraCore was updated to version 1.3;
29-
3. Added the ability to change configuration settings of the ChakraCore JS
30-
engine: `DisableBackgroundWork` (default `false`),
31-
`DisableNativeCodeGeneration` (default `false`), `DisableEval` (default
32-
`false`) and `EnableExperimentalFeatures` (default `false`).
27+
Was made switch to new ChakraCore API.
3328

3429
====================
3530
POST-INSTALL ACTIONS

NuGet/JavaScriptEngineSwitcher.Vroom/JavaScriptEngineSwitcher.Vroom.nuspec

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ For correct working of the VroomJs on Windows require assemblies `msvcr110.dll`
3131
<dependency id="JavaScriptEngineSwitcher.Core" version="2.0.0" />
3232
</group>
3333
</dependencies>
34-
<frameworkAssemblies>
35-
<frameworkAssembly assemblyName="System.Runtime" targetFramework=".NETFramework4.5.1" />
36-
</frameworkAssemblies>
3734
<references>
3835
<reference file="JavaScriptEngineSwitcher.Vroom.dll" />
3936
</references>

samples/JavaScriptEngineSwitcher.Sample.AspNet4.Mvc4/App_Start/JsEngineSwitcherConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static void Configure(JsEngineSwitcher engineSwitcher)
1818
.AddJurassic()
1919
.AddMsie(new MsieSettings
2020
{
21+
EngineMode = JsEngineMode.ChakraIeJsRt,
2122
UseEcmaScript5Polyfill = true,
2223
UseJson2Library = true
2324
})

samples/JavaScriptEngineSwitcher.Sample.AspNetCore1.Mvc1/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void ConfigureServices(IServiceCollection services)
5555
.AddChakraCore()
5656
.AddMsie(options =>
5757
{
58+
options.EngineMode = JsEngineMode.ChakraIeJsRt;
5859
options.UseEcmaScript5Polyfill = true;
5960
options.UseJson2Library = true;
6061
})

samples/JavaScriptEngineSwitcher.Sample.AspNetCore1Full.Mvc1/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void ConfigureServices(IServiceCollection services)
6060
.AddJurassic()
6161
.AddMsie(options =>
6262
{
63+
options.EngineMode = JsEngineMode.ChakraIeJsRt;
6364
options.UseEcmaScript5Polyfill = true;
6465
options.UseJson2Library = true;
6566
})

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsContext.cs

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,7 @@ public static uint Idle()
155155
public static JsValue ParseScript(string script, JsSourceContext sourceContext, string sourceName)
156156
{
157157
JsValue result;
158-
JsErrorHelpers.ThrowIfError(NativeMethods.JsParseScript(script, sourceContext, sourceName, out result));
159-
160-
return result;
161-
}
162-
163-
/// <summary>
164-
/// Parses a serialized script and returns a <c>Function</c> representing the script
165-
/// </summary>
166-
/// <remarks>
167-
/// Requires an active script context.
168-
/// </remarks>
169-
/// <param name="script">The script to parse</param>
170-
/// <param name="buffer">The serialized script</param>
171-
/// <param name="sourceContext">Thw cookie identifying the script that can be used
172-
/// by script contexts that have debugging enabled</param>
173-
/// <param name="sourceName">The location the script came from</param>
174-
/// <returns>The <c>Function</c> representing the script code</returns>
175-
public static JsValue ParseScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceName)
176-
{
177-
JsValue result;
178-
JsErrorHelpers.ThrowIfError(NativeMethods.JsParseSerializedScript(script, buffer, sourceContext, sourceName, out result));
158+
JsErrorHelpers.ThrowIfError(NativeMethods.JsParseScriptUtf8(script, sourceContext, sourceName, out result));
179159

180160
return result;
181161
}
@@ -193,20 +173,6 @@ public static JsValue ParseScript(string script)
193173
return ParseScript(script, JsSourceContext.None, string.Empty);
194174
}
195175

196-
/// <summary>
197-
/// Parses a serialized script and returns a <c>Function</c> representing the script
198-
/// </summary>
199-
/// <remarks>
200-
/// Requires an active script context.
201-
/// </remarks>
202-
/// <param name="script">The script to parse</param>
203-
/// <param name="buffer">The serialized script</param>
204-
/// <returns>The <c>Function</c> representing the script code</returns>
205-
public static JsValue ParseScript(string script, byte[] buffer)
206-
{
207-
return ParseScript(script, buffer, JsSourceContext.None, string.Empty);
208-
}
209-
210176
/// <summary>
211177
/// Executes a script
212178
/// </summary>
@@ -221,27 +187,7 @@ public static JsValue ParseScript(string script, byte[] buffer)
221187
public static JsValue RunScript(string script, JsSourceContext sourceContext, string sourceName)
222188
{
223189
JsValue result;
224-
JsErrorHelpers.ThrowIfError(NativeMethods.JsRunScript(script, sourceContext, sourceName, out result));
225-
226-
return result;
227-
}
228-
229-
/// <summary>
230-
/// Runs a serialized script
231-
/// </summary>
232-
/// <remarks>
233-
/// Requires an active script context
234-
/// </remarks>
235-
/// <param name="script">The source code of the serialized script</param>
236-
/// <param name="buffer">The serialized script</param>
237-
/// <param name="sourceContext">The cookie identifying the script that can be used
238-
/// by script contexts that have debugging enabled</param>
239-
/// <param name="sourceName">The location the script came from</param>
240-
/// <returns>The result of the script, if any</returns>
241-
public static JsValue RunScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceName)
242-
{
243-
JsValue result;
244-
JsErrorHelpers.ThrowIfError(NativeMethods.JsRunSerializedScript(script, buffer, sourceContext, sourceName, out result));
190+
JsErrorHelpers.ThrowIfError(NativeMethods.JsRunScriptUtf8(script, sourceContext, sourceName, out result));
245191

246192
return result;
247193
}
@@ -259,20 +205,6 @@ public static JsValue RunScript(string script)
259205
return RunScript(script, JsSourceContext.None, string.Empty);
260206
}
261207

262-
/// <summary>
263-
/// Runs a serialized script
264-
/// </summary>
265-
/// <remarks>
266-
/// Requires an active script context.
267-
/// </remarks>
268-
/// <param name="script">The source code of the serialized script</param>
269-
/// <param name="buffer">The serialized script</param>
270-
/// <returns>The result of the script, if any</returns>
271-
public static JsValue RunScript(string script, byte[] buffer)
272-
{
273-
return RunScript(script, buffer, JsSourceContext.None, string.Empty);
274-
}
275-
276208
/// <summary>
277209
/// Serializes a parsed script to a buffer than can be reused
278210
/// </summary>
@@ -292,7 +224,7 @@ public static JsValue RunScript(string script, byte[] buffer)
292224
public static ulong SerializeScript(string script, byte[] buffer)
293225
{
294226
var bufferSize = (ulong)buffer.Length;
295-
JsErrorHelpers.ThrowIfError(NativeMethods.JsSerializeScript(script, buffer, ref bufferSize));
227+
JsErrorHelpers.ThrowIfError(NativeMethods.JsSerializeScriptUtf8(script, buffer, ref bufferSize));
296228

297229
return bufferSize;
298230
}

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsPropertyId.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public string Name
3737
get
3838
{
3939
string name;
40-
JsErrorHelpers.ThrowIfError(NativeMethods.JsGetPropertyNameFromId(this, out name));
40+
JsErrorHelpers.ThrowIfError(NativeMethods.JsGetPropertyNameFromIdUtf8Copy(this, out name));
4141

4242
return name;
4343
}
@@ -71,7 +71,7 @@ internal JsPropertyId(IntPtr id)
7171
public static JsPropertyId FromString(string name)
7272
{
7373
JsPropertyId id;
74-
JsErrorHelpers.ThrowIfError(NativeMethods.JsGetPropertyIdFromName(name, out id));
74+
JsErrorHelpers.ThrowIfError(NativeMethods.JsGetPropertyIdFromNameUtf8(name, out id));
7575

7676
return id;
7777
}

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsValue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public static JsValue FromInt32(int value)
301301
public static JsValue FromString(string value)
302302
{
303303
JsValue reference;
304-
JsErrorHelpers.ThrowIfError(NativeMethods.JsPointerToString(value, new UIntPtr((uint)value.Length), out reference));
304+
JsErrorHelpers.ThrowIfError(NativeMethods.JsPointerToStringUtf8(value, new UIntPtr((uint)value.Length), out reference));
305305

306306
return reference;
307307
}
@@ -569,9 +569,9 @@ public double ToDouble()
569569
IntPtr buffer;
570570
UIntPtr length;
571571

572-
JsErrorHelpers.ThrowIfError(NativeMethods.JsStringToPointer(this, out buffer, out length));
572+
JsErrorHelpers.ThrowIfError(NativeMethods.JsStringToPointerUtf8Copy(this, out buffer, out length));
573573

574-
return Marshal.PtrToStringUni(buffer, (int)length);
574+
return Marshal.PtrToStringAnsi(buffer, (int)length);
575575
}
576576

577577
/// <summary>

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/NativeMethods.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
88
/// </summary>
99
internal static class NativeMethods
1010
{
11-
const string DllName = "ChakraCore.dll";
11+
const string DllName = "ChakraCore";
1212

1313
[DllImport(DllName)]
1414
internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, out JsRuntime runtime);
@@ -61,26 +61,28 @@ internal static class NativeMethods
6161
[DllImport(DllName)]
6262
internal static extern JsErrorCode JsIdle(out uint nextIdleTick);
6363

64-
[DllImport(DllName, CharSet = CharSet.Unicode)]
65-
internal static extern JsErrorCode JsParseScript(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
64+
[DllImport(DllName)]
65+
internal static extern JsErrorCode JsParseScriptUtf8(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
6666

67-
[DllImport(DllName, CharSet = CharSet.Unicode)]
68-
internal static extern JsErrorCode JsRunScript(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
67+
[DllImport(DllName)]
68+
internal static extern JsErrorCode JsRunScriptUtf8(string script, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
6969

70-
[DllImport(DllName, CharSet = CharSet.Unicode)]
71-
internal static extern JsErrorCode JsSerializeScript(string script, byte[] buffer, ref ulong bufferSize);
70+
[DllImport(DllName)]
71+
internal static extern JsErrorCode JsSerializeScriptUtf8(string script, byte[] buffer, ref ulong bufferSize);
7272

73-
[DllImport(DllName, CharSet = CharSet.Unicode)]
74-
internal static extern JsErrorCode JsParseSerializedScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
73+
[DllImport(DllName)]
74+
internal static extern JsErrorCode JsParseSerializedScriptUtf8(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
75+
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
7576

76-
[DllImport(DllName, CharSet = CharSet.Unicode)]
77-
internal static extern JsErrorCode JsRunSerializedScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
77+
[DllImport(DllName)]
78+
internal static extern JsErrorCode JsRunSerializedScriptUtf8(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
79+
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
7880

79-
[DllImport(DllName, CharSet = CharSet.Unicode)]
80-
internal static extern JsErrorCode JsGetPropertyIdFromName(string name, out JsPropertyId propertyId);
81+
[DllImport(DllName)]
82+
internal static extern JsErrorCode JsGetPropertyIdFromNameUtf8(string name, out JsPropertyId propertyId);
8183

82-
[DllImport(DllName, CharSet = CharSet.Unicode)]
83-
internal static extern JsErrorCode JsGetPropertyNameFromId(JsPropertyId propertyId, out string name);
84+
[DllImport(DllName)]
85+
internal static extern JsErrorCode JsGetPropertyNameFromIdUtf8Copy(JsPropertyId propertyId, out string name);
8486

8587
[DllImport(DllName)]
8688
internal static extern JsErrorCode JsGetUndefinedValue(out JsValue undefinedValue);
@@ -121,11 +123,11 @@ internal static class NativeMethods
121123
[DllImport(DllName)]
122124
internal static extern JsErrorCode JsGetStringLength(JsValue sringValue, out int length);
123125

124-
[DllImport(DllName, CharSet = CharSet.Unicode)]
125-
internal static extern JsErrorCode JsPointerToString(string value, UIntPtr stringLength, out JsValue stringValue);
126+
[DllImport(DllName)]
127+
internal static extern JsErrorCode JsPointerToStringUtf8(string value, UIntPtr stringLength, out JsValue stringValue);
126128

127129
[DllImport(DllName)]
128-
internal static extern JsErrorCode JsStringToPointer(JsValue value, out IntPtr stringValue, out UIntPtr stringLength);
130+
internal static extern JsErrorCode JsStringToPointerUtf8Copy(JsValue value, out IntPtr stringValue, out UIntPtr stringLength);
129131

130132
[DllImport(DllName)]
131133
internal static extern JsErrorCode JsConvertValueToString(JsValue value, out JsValue stringValue);
@@ -322,13 +324,5 @@ internal static extern JsErrorCode JsCreateTypedArray(JsTypedArrayType arrayType
322324

323325
[DllImport(DllName)]
324326
internal static extern JsErrorCode JsSetContextData(JsContext context, IntPtr data);
325-
326-
[DllImport(DllName)]
327-
internal static extern JsErrorCode JsParseSerializedScriptWithCallback(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
328-
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
329-
330-
[DllImport(DllName)]
331-
internal static extern JsErrorCode JsRunSerializedScriptWithCallback(JsSerializedScriptLoadSourceCallback scriptLoadCallback,
332-
JsSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JsSourceContext sourceContext, string sourceUrl, out JsValue result);
333327
}
334328
}

0 commit comments

Comments
 (0)