Skip to content

Commit 39556cf

Browse files
committed
Added a JavaScriptEngineSwitcher.ChakraCore project
1 parent ee7822e commit 39556cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4212
-0
lines changed

Binaries/ChakraCore/License.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ChakraCore
2+
The MIT License (MIT)
3+
4+
Copyright (c) Microsoft Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
5.65 MB
Binary file not shown.
4.17 MB
Binary file not shown.
1.04 KB
Loading

JavaScriptEngineSwitcher.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptEngineSwitcher.V8
2424
EndProject
2525
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptEngineSwitcher.Tests", "test\JavaScriptEngineSwitcher.Tests\JavaScriptEngineSwitcher.Tests.csproj", "{7C91107D-6DC4-41FC-B976-0C76E1DFD52A}"
2626
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptEngineSwitcher.ChakraCore", "src\JavaScriptEngineSwitcher.ChakraCore\JavaScriptEngineSwitcher.ChakraCore.csproj", "{698A1AFF-B84D-4FB1-B514-D18FFAB5066D}"
28+
EndProject
2729
Global
2830
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2931
Debug|Any CPU = Debug|Any CPU
@@ -54,6 +56,10 @@ Global
5456
{7C91107D-6DC4-41FC-B976-0C76E1DFD52A}.Debug|Any CPU.Build.0 = Debug|Any CPU
5557
{7C91107D-6DC4-41FC-B976-0C76E1DFD52A}.Release|Any CPU.ActiveCfg = Release|Any CPU
5658
{7C91107D-6DC4-41FC-B976-0C76E1DFD52A}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{698A1AFF-B84D-4FB1-B514-D18FFAB5066D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60+
{698A1AFF-B84D-4FB1-B514-D18FFAB5066D}.Debug|Any CPU.Build.0 = Debug|Any CPU
61+
{698A1AFF-B84D-4FB1-B514-D18FFAB5066D}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{698A1AFF-B84D-4FB1-B514-D18FFAB5066D}.Release|Any CPU.Build.0 = Release|Any CPU
5763
EndGlobalSection
5864
GlobalSection(SolutionProperties) = preSolution
5965
HideSolutionNode = FALSE
@@ -64,6 +70,7 @@ Global
6470
{2E667689-F072-401F-A9A5-09F1A2ED025C} = {FF05A998-0DDD-40EC-9B92-7A8FF1AA9888}
6571
{50AD3B1C-A295-42AC-979A-CD244429983C} = {FF05A998-0DDD-40EC-9B92-7A8FF1AA9888}
6672
{1BAEC601-B244-48D3-BE27-351E133EEF73} = {FF05A998-0DDD-40EC-9B92-7A8FF1AA9888}
73+
{698A1AFF-B84D-4FB1-B514-D18FFAB5066D} = {FF05A998-0DDD-40EC-9B92-7A8FF1AA9888}
6774
{7C91107D-6DC4-41FC-B976-0C76E1DFD52A} = {0A72641D-5115-4199-9496-973092040ADF}
6875
EndGlobalSection
6976
EndGlobal

Licenses/chakra-core-license.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ChakraCore
2+
The MIT License (MIT)
3+
4+
Copyright (c) Microsoft Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
namespace JavaScriptEngineSwitcher.ChakraCore
2+
{
3+
using System;
4+
using System.IO;
5+
using System.Runtime.InteropServices;
6+
using System.Text.RegularExpressions;
7+
8+
using Resources;
9+
10+
/// <summary>
11+
/// Assembly resolver
12+
/// </summary>
13+
internal static class AssemblyResolver
14+
{
15+
/// <summary>
16+
/// Name of directory, that contains the ChakraCore assemblies
17+
/// </summary>
18+
private const string ASSEMBLY_DIRECTORY_NAME = "ChakraCore";
19+
20+
/// <summary>
21+
/// Regular expression for working with the `bin` directory path
22+
/// </summary>
23+
private static readonly Regex _binDirectoryRegex = new Regex(@"\\bin\\?$", RegexOptions.IgnoreCase);
24+
25+
26+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
27+
private static extern bool SetDllDirectory(string lpPathName);
28+
29+
/// <summary>
30+
/// Initialize a assembly resolver
31+
/// </summary>
32+
public static void Initialize()
33+
{
34+
var currentDomain = AppDomain.CurrentDomain;
35+
string platform = Environment.Is64BitProcess ? "x64" : "x86";
36+
37+
string binDirectoryPath = currentDomain.SetupInformation.PrivateBinPath;
38+
if (string.IsNullOrEmpty(binDirectoryPath))
39+
{
40+
// `PrivateBinPath` property is empty in test scenarios, so
41+
// need to use the `BaseDirectory` property
42+
binDirectoryPath = currentDomain.BaseDirectory;
43+
}
44+
45+
string assemblyDirectoryPath = Path.Combine(binDirectoryPath, ASSEMBLY_DIRECTORY_NAME, platform);
46+
47+
if (!Directory.Exists(assemblyDirectoryPath))
48+
{
49+
if (_binDirectoryRegex.IsMatch(binDirectoryPath))
50+
{
51+
string applicationRootPath = _binDirectoryRegex.Replace(binDirectoryPath, string.Empty);
52+
assemblyDirectoryPath = Path.Combine(applicationRootPath, ASSEMBLY_DIRECTORY_NAME, platform);
53+
54+
if (!Directory.Exists(assemblyDirectoryPath))
55+
{
56+
throw new DirectoryNotFoundException(
57+
string.Format(Strings.Engines_ChakraCoreAssemblyDirectoryNotFound, assemblyDirectoryPath));
58+
}
59+
}
60+
else
61+
{
62+
throw new DirectoryNotFoundException(
63+
string.Format(Strings.Engines_ChakraCoreAssemblyDirectoryNotFound, assemblyDirectoryPath));
64+
}
65+
}
66+
67+
if (!SetDllDirectory(assemblyDirectoryPath))
68+
{
69+
throw new InvalidOperationException(
70+
string.Format(Strings.Engines_AddingDirectoryToDllSearchPathFailed, assemblyDirectoryPath));
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)