Skip to content

Commit da8e202

Browse files
committed
Add support for V8 on Windows via ClearScript
1 parent 488a60e commit da8e202

20 files changed

+335
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ src/**/*.nuspec
55
!src/template.nuspec
66
site/jekyll/_site
77
src/React.Sample.Cassette/cassette-cache
8+
src/React.Sample.Mvc4/ClearScript.V8
89
*.generated.js
910

1011
## Ignore Visual Studio temporary files, build results, and

build.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of patent rights can be found in the PATENTS file in the same directory.
2727
<PackageAssemblies Include="Cassette.React" />
2828
<PackageAssemblies Include="React.MSBuild" />
2929
<PackageAssemblies Include="React.JavaScriptEngine.VroomJs" />
30+
<PackageAssemblies Include="React.JavaScriptEngine.ClearScriptV8" />
3031
</ItemGroup>
3132

3233
<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using JavaScriptEngineSwitcher.V8;
11+
using React.TinyIoC;
12+
13+
namespace React.JavaScriptEngine.ClearScriptV8
14+
{
15+
/// <summary>
16+
/// Handles registration of ClearScript V8 for ReactJS.NET.
17+
/// </summary>
18+
public class AssemblyRegistration : IAssemblyRegistration
19+
{
20+
/// <summary>
21+
/// Registers components in the React IoC container
22+
/// </summary>
23+
/// <param name="container">Container to register components in</param>
24+
public void Register(TinyIoCContainer container)
25+
{
26+
// Only supported on Windows
27+
if (!ClearScriptV8Utils.IsEnvironmentSupported())
28+
{
29+
return;
30+
}
31+
32+
ClearScriptV8Utils.EnsureEngineFunctional();
33+
container.Register(new JavaScriptEngineFactory.Registration
34+
{
35+
Factory = () => new V8JsEngine(),
36+
Priority = 10
37+
}, "ClearScriptV8");
38+
}
39+
}
40+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System;
11+
using System.Runtime.Serialization;
12+
using React.Exceptions;
13+
14+
namespace React.JavaScriptEngine.ClearScriptV8
15+
{
16+
/// <summary>
17+
/// Thrown when the JavaScript engine does not support JSX transformation
18+
/// </summary>
19+
[Serializable]
20+
public class ClearScriptV8InitialisationException : ReactException
21+
{
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="ClearScriptV8InitialisationException"/> class.
24+
/// </summary>
25+
public ClearScriptV8InitialisationException(string innerMessage) :
26+
base(GetMessage(innerMessage)) { }
27+
28+
/// <summary>
29+
/// Used by deserialization
30+
/// </summary>
31+
protected ClearScriptV8InitialisationException(SerializationInfo info, StreamingContext context)
32+
: base(info, context) { }
33+
34+
/// <summary>
35+
/// Gets a message that describes the current exception.
36+
/// </summary>
37+
private static string GetMessage(string innerMessage)
38+
{
39+
return
40+
"Failed to initialise ClearScript V8. This is most likely caused by the native libraries " +
41+
"(ClearScriptV8-64.dll and v8-x64.dll) missing from your app's Bin directory. Please " +
42+
"ensure your app is referencing the JavaScriptEngineSwitcher.V8 NuGet package.\n\n" +
43+
"More details: " + innerMessage;
44+
}
45+
}
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System;
11+
using JavaScriptEngineSwitcher.V8;
12+
using React.Exceptions;
13+
14+
namespace React.JavaScriptEngine.ClearScriptV8
15+
{
16+
/// <summary>
17+
/// Utility methods for VroomJs JavaScript engine
18+
/// </summary>
19+
public static class ClearScriptV8Utils
20+
{
21+
/// <summary>
22+
/// Determines if the current environment supports the ClearScript V8 engine
23+
/// </summary>
24+
/// <returns></returns>
25+
public static bool IsEnvironmentSupported()
26+
{
27+
return Environment.OSVersion.Platform == PlatformID.Win32NT;
28+
}
29+
30+
/// <summary>
31+
/// If the user is explicitly referencing this assembly, they probably want to use it.
32+
/// Attempt to use the engine and throw an exception if it doesn't work.
33+
/// </summary>
34+
public static void EnsureEngineFunctional()
35+
{
36+
int result = 0;
37+
try
38+
{
39+
using (var engine = new V8JsEngine())
40+
{
41+
result = engine.Evaluate<int>("1 + 1");
42+
}
43+
}
44+
catch (Exception ex)
45+
{
46+
throw new ClearScriptV8InitialisationException(ex.Message);
47+
}
48+
49+
if (result != 2)
50+
{
51+
throw new ReactException("Mathematics is broken. 1 + 1 = " + result);
52+
}
53+
}
54+
}
55+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System.Reflection;
11+
using System.Runtime.InteropServices;
12+
13+
[assembly: AssemblyTitle("React.JavaScriptEngine.ClearScriptV8")]
14+
[assembly: AssemblyDescription("ClearScript V8 JavaScript library for ReactJS.NET")]
15+
[assembly: ComVisible(false)]
16+
[assembly: Guid("fcc41d93-09d7-4053-8d87-da2b9d0c7030")]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{7FBE07B3-C7BA-48DA-8B53-0DB0BB82DA09}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>React.JavaScriptEngine.ClearScriptV8</RootNamespace>
11+
<AssemblyName>React.JavaScriptEngine.ClearScriptV8</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>..\..\bin\Debug\React.JavaScriptEngine.ClearScriptV8\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<NoWarn>1607</NoWarn>
25+
<DocumentationFile>..\..\bin\Debug\React.JavaScriptEngine.ClearScriptV8\React.JavaScriptEngine.ClearScriptV8.XML</DocumentationFile>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>..\..\bin\Release\React.JavaScriptEngine.ClearScriptV8\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<NoWarn>1607</NoWarn>
35+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
36+
<DocumentationFile>..\..\bin\Release\React.JavaScriptEngine.ClearScriptV8\React.JavaScriptEngine.ClearScriptV8.XML</DocumentationFile>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="ClearScript">
40+
<HintPath>..\packages\JavaScriptEngineSwitcher.V8.1.2.1\lib\net40\ClearScript.dll</HintPath>
41+
</Reference>
42+
<Reference Include="JavaScriptEngineSwitcher.Core">
43+
<HintPath>..\packages\JavaScriptEngineSwitcher.Core.1.2.0\lib\net40\JavaScriptEngineSwitcher.Core.dll</HintPath>
44+
</Reference>
45+
<Reference Include="JavaScriptEngineSwitcher.V8">
46+
<HintPath>..\packages\JavaScriptEngineSwitcher.V8.1.2.1\lib\net40\JavaScriptEngineSwitcher.V8.dll</HintPath>
47+
</Reference>
48+
<Reference Include="System" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="Microsoft.CSharp" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Compile Include="..\SharedAssemblyInfo.cs">
54+
<Link>Properties\SharedAssemblyInfo.cs</Link>
55+
</Compile>
56+
<Compile Include="..\SharedAssemblyVersionInfo.cs">
57+
<Link>Properties\SharedAssemblyVersionInfo.cs</Link>
58+
</Compile>
59+
<Compile Include="AssemblyRegistration.cs" />
60+
<Compile Include="ClearScriptV8Utils.cs" />
61+
<Compile Include="ClearScriptV8InitialisationException.cs" />
62+
<Compile Include="Properties\AssemblyInfo.cs" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<None Include="packages.config" />
66+
<None Include="React.JavaScriptEngine.ClearScriptV8.nutrans" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="..\React\React.csproj">
70+
<Project>{d0cc8a22-cee6-485c-924b-1f94426fea59}</Project>
71+
<Name>React</Name>
72+
</ProjectReference>
73+
</ItemGroup>
74+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
75+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
76+
Other similar extension points exist, see Microsoft.Common.targets.
77+
<Target Name="BeforeBuild">
78+
</Target>
79+
<Target Name="AfterBuild">
80+
</Target>
81+
-->
82+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (c) 2014, Facebook, Inc.
4+
All rights reserved.
5+
6+
This source code is licensed under the BSD-style license found in the
7+
LICENSE file in the root directory of this source tree. An additional grant
8+
of patent rights can be found in the PATENTS file in the same directory.
9+
-->
10+
<package
11+
xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
12+
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
13+
<metadata>
14+
<title xdt:Transform="Insert">ReactJS.NET - ClearScript V8</title>
15+
<description xdt:Transform="Insert">V8 support for ReactJS.NET, using ClearScript. Install this package in addition to the regular ReactJS.NET packages (eg. React.Web.Mvc4 for ASP.NET MVC 4 integration). Only works on Windows, See React.JavaScriptEngine.VroomJs for a Mono (Linux and Mac OS X) version
16+
Please refer to project site (http://reactjs.net/) for more details, usage examples and sample code.
17+
</description>
18+
<summary xdt:Transform="Insert">V8 support for ReactJS.NET</summary>
19+
<tags xdt:Transform="Replace">asp.net mvc asp jquery javascript js react facebook reactjs v8 clearscript</tags>
20+
</metadata>
21+
</package>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="JavaScriptEngineSwitcher.Core" version="1.2.0" targetFramework="net451" />
4+
<package id="JavaScriptEngineSwitcher.V8" version="1.2.1" targetFramework="net451" />
5+
</packages>

src/React.JavaScriptEngine.VroomJs/React.JavaScriptEngine.VroomJs.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
<AssemblyOriginatorKeyFile>..\Key.snk</AssemblyOriginatorKeyFile>
4242
</PropertyGroup>
4343
<ItemGroup>
44-
<Reference Include="JavaScriptEngineSwitcher.Core">
45-
<HintPath>..\packages\JavaScriptEngineSwitcher.Core.1.1.3\lib\net40\JavaScriptEngineSwitcher.Core.dll</HintPath>
44+
<Reference Include="JavaScriptEngineSwitcher.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=c608b2a8cc9e4472, processorArchitecture=MSIL">
45+
<SpecificVersion>False</SpecificVersion>
46+
<HintPath>..\packages\JavaScriptEngineSwitcher.Core.1.2.0\lib\net40\JavaScriptEngineSwitcher.Core.dll</HintPath>
4647
</Reference>
4748
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4849
<HintPath>..\packages\Newtonsoft.Json.5.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>

0 commit comments

Comments
 (0)