├── .gitignore ├── LICENSE ├── README.md ├── VroomJS.sln ├── appveyor.yml ├── build.cake ├── build.cmd ├── build.ps1 ├── common.cake ├── global.json ├── native ├── compiled │ ├── VroomJsNative-x64.dll │ ├── VroomJsNative-x86.dll │ ├── v8-x64.dll │ └── v8-x86.dll └── libVroomJs │ ├── bridge.cpp │ ├── jscontext.cpp │ ├── jsengine.cpp │ ├── jsscript.cpp │ ├── jsscript.h │ ├── libVroomJs.vcxproj │ ├── libVroomJs.vcxproj.filters │ ├── managedref.cpp │ └── vroomjs.h ├── src ├── Sandbox │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Sandbox.xproj │ └── project.json └── VroomJs │ ├── AssemblyLoader.cs │ ├── BoundWeakDelegate.cs │ ├── IKeepAliveStore.cs │ ├── JsContext.Dynamic.cs │ ├── JsContext.cs │ ├── JsConvert.cs │ ├── JsEngine.cs │ ├── JsEngineStats.cs │ ├── JsError.cs │ ├── JsException.cs │ ├── JsExecutionTimedOutException.cs │ ├── JsFunction.cs │ ├── JsInteropException.cs │ ├── JsObject.Dynamic.cs │ ├── JsObjectMarshalType.cs │ ├── JsScript.cs │ ├── JsValue.cs │ ├── JsValueType.cs │ ├── KeepAliveDictionaryStore.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── VroomJS.xproj │ ├── WeakDelegate.cs │ ├── key.snk │ └── project.json └── tools ├── batchcopy.cmd └── batchcopy.sh /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.db 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | 84 | # Visual Studio profiler 85 | *.psess 86 | *.vsp 87 | *.vspx 88 | *.sap 89 | 90 | # TFS 2012 Local Workspace 91 | $tf/ 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | *.DotSettings.user 100 | 101 | # JustCode is a .NET coding add-in 102 | .JustCode 103 | 104 | # TeamCity is a build add-in 105 | _TeamCity* 106 | 107 | # DotCover is a Code Coverage Tool 108 | *.dotCover 109 | 110 | # NCrunch 111 | _NCrunch_* 112 | .*crunch*.local.xml 113 | nCrunchTemp_* 114 | 115 | # MightyMoose 116 | *.mm.* 117 | AutoTest.Net/ 118 | 119 | # Web workbench (sass) 120 | .sass-cache/ 121 | 122 | # Installshield output folder 123 | [Ee]xpress/ 124 | 125 | # DocProject is a documentation generator add-in 126 | DocProject/buildhelp/ 127 | DocProject/Help/*.HxT 128 | DocProject/Help/*.HxC 129 | DocProject/Help/*.hhc 130 | DocProject/Help/*.hhk 131 | DocProject/Help/*.hhp 132 | DocProject/Help/Html2 133 | DocProject/Help/html 134 | 135 | # Click-Once directory 136 | publish/ 137 | 138 | # Publish Web Output 139 | *.[Pp]ublish.xml 140 | *.azurePubxml 141 | # TODO: Comment the next line if you want to checkin your web deploy settings 142 | # but database connection strings (with potential passwords) will be unencrypted 143 | *.pubxml 144 | *.publishproj 145 | 146 | # NuGet Packages 147 | *.nupkg 148 | # The packages folder can be ignored because of Package Restore 149 | **/packages/* 150 | # except build/, which is used as an MSBuild target. 151 | !**/packages/build/ 152 | # Uncomment if necessary however generally it will be regenerated when needed 153 | #!**/packages/repositories.config 154 | # NuGet v3's project.json files produces more ignoreable files 155 | *.nuget.props 156 | *.nuget.targets 157 | 158 | # Microsoft Azure Build Output 159 | csx/ 160 | *.build.csdef 161 | 162 | # Microsoft Azure Emulator 163 | ecf/ 164 | rcf/ 165 | 166 | # Microsoft Azure ApplicationInsights config file 167 | ApplicationInsights.config 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | ~$* 182 | *~ 183 | *.dbmdl 184 | *.dbproj.schemaview 185 | *.pfx 186 | *.publishsettings 187 | node_modules/ 188 | orleans.codegen.cs 189 | 190 | # RIA/Silverlight projects 191 | Generated_Code/ 192 | 193 | # Backup & report files from converting an old project file 194 | # to a newer Visual Studio version. Backup files are not needed, 195 | # because we have git ;-) 196 | _UpgradeReport_Files/ 197 | Backup*/ 198 | UpgradeLog*.XML 199 | UpgradeLog*.htm 200 | 201 | # SQL Server files 202 | *.mdf 203 | *.ldf 204 | 205 | # Business Intelligence projects 206 | *.rdl.data 207 | *.bim.layout 208 | *.bim_*.settings 209 | 210 | # Microsoft Fakes 211 | FakesAssemblies/ 212 | 213 | # GhostDoc plugin setting file 214 | *.GhostDoc.xml 215 | 216 | # Node.js Tools for Visual Studio 217 | .ntvs_analysis.dat 218 | 219 | # Visual Studio 6 build log 220 | *.plg 221 | 222 | # Visual Studio 6 workspace options file 223 | *.opt 224 | 225 | # Visual Studio LightSwitch build output 226 | **/*.HTMLClient/GeneratedArtifacts 227 | **/*.DesktopClient/GeneratedArtifacts 228 | **/*.DesktopClient/ModelManifest.xml 229 | **/*.Server/GeneratedArtifacts 230 | **/*.Server/ModelManifest.xml 231 | _Pvt_Extensions 232 | 233 | # Paket dependency manager 234 | .paket/paket.exe 235 | 236 | # FAKE - F# Make 237 | .fake/ 238 | vendor/v8/ 239 | temp/ 240 | tools/ 241 | dist/ 242 | build/ 243 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Paul Knopf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VroomJs [![NuGet](https://img.shields.io/nuget/v/VroomJs.svg?maxAge=2592000)](https://www.nuget.org/packages/VroomJs/) 2 | 3 | This is a version of VroomJs that can on on the new .NET Core runtime. 4 | 5 | ## Examples 6 | 7 | Execute some Javascript: 8 | 9 | ```c# 10 | using (var engine = new JsEngine()) 11 | { 12 | using (var context = engine.CreateContext()) 13 | { 14 | var x = (double)context.Execute("3.14159+2.71828"); 15 | Console.WriteLine(x); // prints 5.85987 16 | } 17 | } 18 | ``` 19 | 20 | Create and return a Javascript object, then call a method on it: 21 | 22 | ```c# 23 | using (JsEngine js = new JsEngine(4, 32)) 24 | { 25 | using (JsContext context = js.CreateContext()) 26 | { 27 | // Create a global variable on the JS side. 28 | context.Execute("var x = {'answer':42, 'tellme':function (x) { return x+' '+this.answer; }}"); 29 | // Get it and use "dynamic" to tell the compiler to use runtime binding. 30 | dynamic x = context.GetVariable("x"); 31 | // Call the method and print the result. This will print: 32 | // "What is the answer to ...? 42" 33 | Console.WriteLine(x.tellme("What is the answer to ...?")); 34 | } 35 | } 36 | ``` 37 | 38 | Access properties and call methods on CLR objects from Javascript: 39 | 40 | ```c# 41 | class Test 42 | { 43 | public int Value { get; set; } 44 | public void PrintValue(string msg) 45 | { 46 | Console.WriteLine(msg+" "+Value); 47 | } 48 | } 49 | 50 | using (JsEngine js = new JsEngine(4, 32)) 51 | { 52 | using (JsContext context = js.CreateContext()) 53 | { 54 | context.SetVariable("m", new Test()); 55 | // Sets the property from Javascript. 56 | context.Execute("m.Value = 42"); 57 | // Call a method on the CLR object from Javascript. This prints: 58 | // "And the answer is (again!): 42" 59 | context.Execute("m.PrintValue('And the answer is (again!):')"); 60 | } 61 | } 62 | ``` 63 | ## Platforms 64 | 65 | ### Windows 66 | 67 | There are embedded .dlls (x64/x86) in the project that can be loaded dynamically. 68 | 69 | ```c# 70 | VroomJs.AssemblyLoader.EnsureLoaded(); // windows only 71 | ``` 72 | 73 | Call this method on start of your application. 74 | 75 | ### Mac/Linux 76 | 77 | The native libraries used in this project must be manually built for Mac/Linux. We are using a forked version of VroomJs used by [ReactJS.NET](http://reactjs.net/). The instructions to generate a native assembly are the same (found [here](http://reactjs.net/guides/mono.html)). 78 | 79 | ```bash 80 | # Get a supported version of V8 81 | cd /usr/local/src/ 82 | git clone https://github.com/v8/v8.git v8-3.17 83 | cd v8-3.17 84 | git checkout tags/3.17.16.2 85 | 86 | # Build V8 87 | make dependencies 88 | make native werror=no library=shared soname_version=3.17.16.2 -j4 89 | cp out/native/lib.target/libv8.so.3.17.16.2 /usr/local/lib/ 90 | 91 | # Get VroomJs's version of libvroomjs 92 | cd /usr/local/src/ 93 | git clone https://github.com/pauldotknopf/vroomjs-core.git 94 | cd vroomjs-core 95 | cd native/libVroomJs/ 96 | 97 | # Build libvroomjs 98 | g++ jscontext.cpp jsengine.cpp managedref.cpp bridge.cpp jsscript.cpp -o libVroomJsNative.so -shared -L /usr/local/src/v8-3.17/out/native/lib.target/ -I /usr/local/src/v8-3.17/include/ -fPIC -Wl,--no-as-needed -l:/usr/local/lib/libv8.so.3.17.16.2 99 | cp libVroomJsNative.so /usr/local/lib/ 100 | ldconfig 101 | ``` 102 | -------------------------------------------------------------------------------- /VroomJS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8C87E388-CD2C-47F7-84A6-4FC247F71F6C}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1EAD6E52-71D5-425F-869B-4315DED8ECDC}" 9 | ProjectSection(SolutionItems) = preProject 10 | global.json = global.json 11 | EndProjectSection 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libVroomJs", "native\libVroomJs\libVroomJs.vcxproj", "{6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}" 14 | EndProject 15 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sandbox", "src\Sandbox\Sandbox.xproj", "{1FF5093A-97D0-4692-A4CD-A5939CDF1096}" 16 | EndProject 17 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "VroomJs", "src\VroomJs\VroomJs.xproj", "{8971EFE7-4922-4FCA-9FD2-908B3077BDB4}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Debug|x64 = Debug|x64 23 | Debug|x86 = Debug|x86 24 | Release|Any CPU = Release|Any CPU 25 | Release|x64 = Release|x64 26 | Release|x86 = Release|x86 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Debug|Any CPU.ActiveCfg = Debug|Win32 30 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Debug|x64.ActiveCfg = Debug|x64 31 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Debug|x64.Build.0 = Debug|x64 32 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Debug|x86.ActiveCfg = Debug|Win32 33 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Debug|x86.Build.0 = Debug|Win32 34 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Release|Any CPU.ActiveCfg = Release|Win32 35 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Release|x64.ActiveCfg = Release|x64 36 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Release|x64.Build.0 = Release|x64 37 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Release|x86.ActiveCfg = Release|Win32 38 | {6CFA51CD-7028-4CBB-8A7A-1DFCFAA9172B}.Release|x86.Build.0 = Release|Win32 39 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|x64.ActiveCfg = Debug|Any CPU 42 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|x64.Build.0 = Debug|Any CPU 43 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|x86.ActiveCfg = Debug|Any CPU 44 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Debug|x86.Build.0 = Debug|Any CPU 45 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|x64.ActiveCfg = Release|Any CPU 48 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|x64.Build.0 = Release|Any CPU 49 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|x86.ActiveCfg = Release|Any CPU 50 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096}.Release|x86.Build.0 = Release|Any CPU 51 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|x64.ActiveCfg = Debug|Any CPU 54 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|x64.Build.0 = Debug|Any CPU 55 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|x86.ActiveCfg = Debug|Any CPU 56 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Debug|x86.Build.0 = Debug|Any CPU 57 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|Any CPU.ActiveCfg = Release|Any CPU 58 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|Any CPU.Build.0 = Release|Any CPU 59 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|x64.ActiveCfg = Release|Any CPU 60 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|x64.Build.0 = Release|Any CPU 61 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|x86.ActiveCfg = Release|Any CPU 62 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4}.Release|x86.Build.0 = Release|Any CPU 63 | EndGlobalSection 64 | GlobalSection(SolutionProperties) = preSolution 65 | HideSolutionNode = FALSE 66 | EndGlobalSection 67 | GlobalSection(NestedProjects) = preSolution 68 | {1FF5093A-97D0-4692-A4CD-A5939CDF1096} = {8C87E388-CD2C-47F7-84A6-4FC247F71F6C} 69 | {8971EFE7-4922-4FCA-9FD2-908B3077BDB4} = {8C87E388-CD2C-47F7-84A6-4FC247F71F6C} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | build_script: 2 | - ps: .\build.ps1 -Target "CI" 3 | 4 | test: off 5 | 6 | branches: 7 | only: 8 | - develop 9 | - main 10 | -------------------------------------------------------------------------------- /build.cake: -------------------------------------------------------------------------------- 1 | #l "common.cake" 2 | 3 | ////////////////////////////////////////////////////////////////////// 4 | // ARGUMENTS 5 | ////////////////////////////////////////////////////////////////////// 6 | 7 | var target = Argument("target", "Default"); 8 | var configuration = Argument("configuration", "Release"); 9 | var versionPrefix = Argument("versionPrefix", ""); 10 | 11 | ////////////////////////////////////////////////////////////////////// 12 | // PREPARATION 13 | ////////////////////////////////////////////////////////////////////// 14 | 15 | var buildNumber=9999; 16 | var baseDir=System.IO.Directory.GetCurrentDirectory(); 17 | var buildDir=System.IO.Path.Combine(baseDir, "build"); 18 | var distDir=System.IO.Path.Combine(baseDir, "dist"); 19 | var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor; 20 | if(isRunningOnAppVeyor) 21 | buildNumber = AppVeyor.Environment.Build.Number; 22 | var version = buildNumber.ToString(); 23 | if(!string.IsNullOrEmpty(versionPrefix)) 24 | version = versionPrefix + "-" + version; 25 | //System.Environment.SetEnvironmentVariable("DOTNET_BUILD_VERSION", version, System.EnvironmentVariableTarget.Process); 26 | 27 | ////////////////////////////////////////////////////////////////////// 28 | // TASKS 29 | ////////////////////////////////////////////////////////////////////// 30 | 31 | Task("EnsureDependencies") 32 | .Does(() => 33 | { 34 | EnsureTool("dotnet", "--version"); 35 | }); 36 | 37 | Task("Clean") 38 | .Does(() => 39 | { 40 | CleanDirectory(buildDir); 41 | CleanDirectory(distDir); 42 | }); 43 | 44 | Task("Build") 45 | .Does(() => 46 | { 47 | ExecuteCommand("dotnet restore src"); 48 | ExecuteCommand(string.Format("dotnet build \"src/VroomJs/project.json\" --configuration \"{0}\"", configuration)); 49 | }); 50 | 51 | Task("Test") 52 | .WithCriteria(() => !isRunningOnAppVeyor) 53 | .Does(() => 54 | { 55 | // no tests 56 | }); 57 | 58 | Task("Deploy") 59 | .Does(() => 60 | { 61 | if(!DirectoryExists(distDir)) 62 | CreateDirectory(distDir); 63 | 64 | ExecuteCommand(string.Format("dotnet pack \"src/VroomJs/project.json\" --configuration \"{0}\" -o \"{1}\"", configuration, distDir, versionPrefix)); 65 | }); 66 | 67 | ////////////////////////////////////////////////////////////////////// 68 | // TASK TARGETS 69 | ////////////////////////////////////////////////////////////////////// 70 | 71 | Task("Default") 72 | .IsDependentOn("EnsureDependencies") 73 | .IsDependentOn("Clean") 74 | .IsDependentOn("Build") 75 | .IsDependentOn("Test"); 76 | 77 | Task("CI") 78 | .IsDependentOn("EnsureDependencies") 79 | .IsDependentOn("Clean") 80 | .IsDependentOn("Build") 81 | .IsDependentOn("Test") 82 | .IsDependentOn("Deploy"); 83 | 84 | ////////////////////////////////////////////////////////////////////// 85 | // EXECUTION 86 | ////////////////////////////////////////////////////////////////////// 87 | 88 | RunTarget(target); 89 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\build.ps1' %*" 3 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | .SYNOPSIS 4 | This is a Powershell script to bootstrap a Cake build. 5 | 6 | .DESCRIPTION 7 | This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) 8 | and execute your Cake build script with the parameters you provide. 9 | 10 | .PARAMETER Script 11 | The build script to execute. 12 | .PARAMETER Target 13 | The build script target to run. 14 | .PARAMETER Configuration 15 | The build configuration to use. 16 | .PARAMETER Verbosity 17 | Specifies the amount of information to be displayed. 18 | .PARAMETER Experimental 19 | Tells Cake to use the latest Roslyn release. 20 | .PARAMETER WhatIf 21 | Performs a dry run of the build script. 22 | No tasks will be executed. 23 | .PARAMETER Mono 24 | Tells Cake to use the Mono scripting engine. 25 | 26 | .LINK 27 | http://cakebuild.net 28 | 29 | #> 30 | 31 | Param( 32 | [string]$Script = "build.cake", 33 | [string]$Target = "Default", 34 | [string]$Configuration = "Release", 35 | [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] 36 | [string]$Verbosity = "Verbose", 37 | [switch]$Experimental, 38 | [Alias("DryRun","Noop")] 39 | [switch]$WhatIf, 40 | [switch]$Mono, 41 | [switch]$SkipToolPackageRestore, 42 | [switch]$Verbose 43 | ) 44 | 45 | Write-Host "Preparing to run build script..." 46 | 47 | # Should we show verbose messages? 48 | if($Verbose.IsPresent) 49 | { 50 | $VerbosePreference = "continue" 51 | } 52 | 53 | $TOOLS_DIR = Join-Path $PSScriptRoot "tools" 54 | $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" 55 | $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" 56 | $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" 57 | 58 | # Should we use mono? 59 | $UseMono = ""; 60 | if($Mono.IsPresent) { 61 | Write-Verbose -Message "Using the Mono based scripting engine." 62 | $UseMono = "-mono" 63 | } 64 | 65 | # Should we use the new Roslyn? 66 | $UseExperimental = ""; 67 | if($Experimental.IsPresent -and !($Mono.IsPresent)) { 68 | Write-Verbose -Message "Using experimental version of Roslyn." 69 | $UseExperimental = "-experimental" 70 | } 71 | 72 | # Is this a dry run? 73 | $UseDryRun = ""; 74 | if($WhatIf.IsPresent) { 75 | $UseDryRun = "-dryrun" 76 | } 77 | 78 | # Make sure tools folder exists 79 | if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { 80 | Write-Verbose -Message "Creating tools directory..." 81 | New-Item -Path $TOOLS_DIR -Type directory | out-null 82 | } 83 | 84 | # Make sure that packages.config exist. 85 | if (!(Test-Path $PACKAGES_CONFIG)) { 86 | Write-Verbose -Message "Downloading packages.config..." 87 | try { Invoke-WebRequest -Uri http://cakebuild.net/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch { 88 | Throw "Could not download packages.config." 89 | } 90 | } 91 | 92 | # Try find NuGet.exe in path if not exists 93 | if (!(Test-Path $NUGET_EXE)) { 94 | Write-Verbose -Message "Trying to find nuget.exe in PATH..." 95 | $existingPaths = $Env:Path -Split ';' | Where-Object { Test-Path $_ } 96 | $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 97 | if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { 98 | Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." 99 | $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName 100 | } 101 | } 102 | 103 | # Try download NuGet.exe if not exists 104 | if (!(Test-Path $NUGET_EXE)) { 105 | Write-Verbose -Message "Downloading NuGet.exe..." 106 | try { Invoke-WebRequest -Uri http://nuget.org/nuget.exe -OutFile $NUGET_EXE } catch { 107 | Throw "Could not download NuGet.exe." 108 | } 109 | } 110 | 111 | # Save nuget.exe path to environment to be available to child processed 112 | $ENV:NUGET_EXE = $NUGET_EXE 113 | 114 | # Restore tools from NuGet? 115 | if(-Not $SkipToolPackageRestore.IsPresent) 116 | { 117 | # Restore packages from NuGet. 118 | Push-Location 119 | Set-Location $TOOLS_DIR 120 | 121 | Write-Verbose -Message "Restoring tools from NuGet..." 122 | $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" 123 | Write-Verbose -Message ($NuGetOutput | out-string) 124 | 125 | Pop-Location 126 | if ($LASTEXITCODE -ne 0) 127 | { 128 | exit $LASTEXITCODE 129 | } 130 | } 131 | 132 | # Make sure that Cake has been installed. 133 | if (!(Test-Path $CAKE_EXE)) { 134 | Throw "Could not find Cake.exe at $CAKE_EXE" 135 | } 136 | 137 | # Start Cake 138 | Write-Host "Running build script..." 139 | Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental" 140 | exit $LASTEXITCODE 141 | -------------------------------------------------------------------------------- /common.cake: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // HELPERS 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | void EnsureTool(string tool, string arguements) 6 | { 7 | try 8 | { 9 | ExecuteCommand(tool + (!string.IsNullOrEmpty(arguements) ? " " + arguements : null)); 10 | Information("The tool \"" + tool + "\" is present..."); 11 | } 12 | catch(Exception ex) 13 | { 14 | Error("The tool \"" + tool + "\" is not present..."); 15 | throw; 16 | } 17 | } 18 | 19 | void ExecuteCommand(string command, string workingDir = null) 20 | { 21 | if (string.IsNullOrEmpty(workingDir)) 22 | workingDir = System.IO.Directory.GetCurrentDirectory(); 23 | 24 | System.Diagnostics.ProcessStartInfo processStartInfo; 25 | 26 | if (IsRunningOnWindows()) 27 | { 28 | processStartInfo = new System.Diagnostics.ProcessStartInfo 29 | { 30 | UseShellExecute = false, 31 | WorkingDirectory = workingDir, 32 | FileName = "cmd", 33 | Arguments = "/C " + command, 34 | }; 35 | } 36 | else 37 | { 38 | processStartInfo = new System.Diagnostics.ProcessStartInfo 39 | { 40 | UseShellExecute = false, 41 | WorkingDirectory = workingDir, 42 | Arguments = command, 43 | }; 44 | } 45 | 46 | using (var process = System.Diagnostics.Process.Start(processStartInfo)) 47 | { 48 | process.WaitForExit(); 49 | 50 | if (process.ExitCode != 0) 51 | throw new Exception(string.Format("Exit code {0} from {1}", process.ExitCode, command)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src" ] 3 | } 4 | -------------------------------------------------------------------------------- /native/compiled/VroomJsNative-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pauldotknopf/vroomjs-core/5bf321aec90677771e0acb2614d209cbd02970a9/native/compiled/VroomJsNative-x64.dll -------------------------------------------------------------------------------- /native/compiled/VroomJsNative-x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pauldotknopf/vroomjs-core/5bf321aec90677771e0acb2614d209cbd02970a9/native/compiled/VroomJsNative-x86.dll -------------------------------------------------------------------------------- /native/compiled/v8-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pauldotknopf/vroomjs-core/5bf321aec90677771e0acb2614d209cbd02970a9/native/compiled/v8-x64.dll -------------------------------------------------------------------------------- /native/compiled/v8-x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pauldotknopf/vroomjs-core/5bf321aec90677771e0acb2614d209cbd02970a9/native/compiled/v8-x86.dll -------------------------------------------------------------------------------- /native/libVroomJs/bridge.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the VroomJs library. 2 | // 3 | // Author: 4 | // Federico Di Gregorio 5 | // 6 | // Copyright © 2013 Federico Di Gregorio 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #include 27 | #include "vroomjs.h" 28 | 29 | using namespace v8; 30 | 31 | int32_t js_object_marshal_type; 32 | 33 | extern "C" 34 | { 35 | EXPORT void CALLINGCONVENTION js_set_object_marshal_type(int32_t type) 36 | { 37 | #ifdef DEBUG_TRACE_API 38 | std::wcout << "js_object_marshal_type " << type << std::endl; 39 | #endif 40 | js_object_marshal_type = type; 41 | } 42 | 43 | EXPORT JsEngine* CALLINGCONVENTION jsengine_new(keepalive_remove_f keepalive_remove, 44 | keepalive_get_property_value_f keepalive_get_property_value, 45 | keepalive_set_property_value_f keepalive_set_property_value, 46 | keepalive_valueof_f keepalive_valueof, 47 | keepalive_invoke_f keepalive_invoke, 48 | keepalive_delete_property_f keepalive_delete_property, 49 | keepalive_enumerate_properties_f keepalive_enumerate_properties, 50 | int32_t max_young_space, int32_t max_old_space) 51 | { 52 | #ifdef DEBUG_TRACE_API 53 | std::wcout << "jsengine_new" << std::endl; 54 | #endif 55 | JsEngine *engine = JsEngine::New(max_young_space, max_old_space); 56 | if (engine != NULL) { 57 | engine->SetRemoveDelegate(keepalive_remove); 58 | engine->SetGetPropertyValueDelegate(keepalive_get_property_value); 59 | engine->SetSetPropertyValueDelegate(keepalive_set_property_value); 60 | engine->SetValueOfDelegate(keepalive_valueof); 61 | engine->SetInvokeDelegate(keepalive_invoke); 62 | engine->SetDeletePropertyDelegate(keepalive_delete_property); 63 | engine->SetEnumeratePropertiesDelegate(keepalive_enumerate_properties); 64 | } 65 | return engine; 66 | } 67 | 68 | EXPORT void CALLINGCONVENTION jsengine_terminate_execution(JsEngine* engine) { 69 | #ifdef DEBUG_TRACE_API 70 | std::wcout << "jsengine_terminate_execution" << std::endl; 71 | #endif 72 | 73 | engine->TerminateExecution(); 74 | } 75 | 76 | EXPORT void CALLINGCONVENTION jsengine_dump_heap_stats(JsEngine* engine) { 77 | #ifdef DEBUG_TRACE_API 78 | std::wcout << "jsengine_dump_heap_stats" << std::endl; 79 | #endif 80 | engine->DumpHeapStats(); 81 | } 82 | 83 | EXPORT void CALLINGCONVENTION js_dump_allocated_items() { 84 | #ifdef DEBUG_TRACE_API 85 | std::wcout << "js_dump_allocated_items" << std::endl; 86 | #endif 87 | std::wcout << "Total allocated Js engines " << js_mem_debug_engine_count << std::endl; 88 | std::wcout << "Total allocated Js contexts " << js_mem_debug_context_count << std::endl; 89 | std::wcout << "Total allocated Js scripts " << js_mem_debug_script_count << std::endl; 90 | std::wcout << "Total allocated Managed Refs " << js_mem_debug_managedref_count << std::endl; 91 | } 92 | 93 | EXPORT void CALLINGCONVENTION jsengine_dispose(JsEngine* engine) 94 | { 95 | #ifdef DEBUG_TRACE_API 96 | std::wcout << "jsengine_dispose" << std::endl; 97 | #endif 98 | engine->Dispose(); 99 | delete engine; 100 | } 101 | 102 | EXPORT JsContext* CALLINGCONVENTION jscontext_new(int32_t id, JsEngine *engine) 103 | { 104 | #ifdef DEBUG_TRACE_API 105 | std::wcout << "jscontext_new" << std::endl; 106 | #endif 107 | JsContext* context = JsContext::New(id, engine); 108 | return context; 109 | } 110 | 111 | EXPORT void CALLINGCONVENTION jscontext_force_gc() 112 | { 113 | #ifdef DEBUG_TRACE_API 114 | std::wcout << "jscontext_force_gc" << std::endl; 115 | #endif 116 | while(!V8::IdleNotification()) {}; 117 | } 118 | 119 | EXPORT void CALLINGCONVENTION jscontext_dispose(JsContext* context) 120 | { 121 | #ifdef DEBUG_TRACE_API 122 | std::wcout << "jscontext_dispose" << std::endl; 123 | #endif 124 | context->Dispose(); 125 | delete context; 126 | } 127 | 128 | EXPORT void CALLINGCONVENTION jsengine_dispose_object(JsEngine* engine, Persistent* obj) 129 | { 130 | #ifdef DEBUG_TRACE_API 131 | std::wcout << "jscontext_dispose_object" << std::endl; 132 | #endif 133 | if (engine != NULL) { 134 | engine->DisposeObject(obj); 135 | } 136 | delete obj; 137 | } 138 | 139 | EXPORT jsvalue CALLINGCONVENTION jscontext_execute(JsContext* context, const uint16_t* str, const uint16_t *resourceName) 140 | { 141 | #ifdef DEBUG_TRACE_API 142 | std::wcout << "jscontext_execute" << std::endl; 143 | #endif 144 | return context->Execute(str, resourceName); 145 | } 146 | 147 | EXPORT jsvalue CALLINGCONVENTION jscontext_execute_script(JsContext* context, JsScript *script) 148 | { 149 | #ifdef DEBUG_TRACE_API 150 | std::wcout << "jscontext_execute_script" << std::endl; 151 | #endif 152 | return context->Execute(script); 153 | } 154 | 155 | EXPORT jsvalue CALLINGCONVENTION jscontext_get_global(JsContext* context) 156 | { 157 | #ifdef DEBUG_TRACE_API 158 | std::wcout << "jscontext_get_global" << std::endl; 159 | #endif 160 | return context->GetGlobal(); 161 | } 162 | 163 | EXPORT jsvalue CALLINGCONVENTION jscontext_set_variable(JsContext* context, const uint16_t* name, jsvalue value) 164 | { 165 | #ifdef DEBUG_TRACE_API 166 | std::wcout << "jscontext_set_variable" << std::endl; 167 | #endif 168 | return context->SetVariable(name, value); 169 | } 170 | 171 | EXPORT jsvalue CALLINGCONVENTION jscontext_get_variable(JsContext* context, const uint16_t* name) 172 | { 173 | #ifdef DEBUG_TRACE_API 174 | std::wcout << "jscontext_get_variable" << std::endl; 175 | #endif 176 | return context->GetVariable(name); 177 | } 178 | 179 | EXPORT jsvalue CALLINGCONVENTION jscontext_get_property_value(JsContext* context, Persistent* obj, const uint16_t* name) 180 | { 181 | #ifdef DEBUG_TRACE_API 182 | std::wcout << "jscontext_get_property_value" << std::endl; 183 | #endif 184 | return context->GetPropertyValue(obj, name); 185 | } 186 | 187 | EXPORT jsvalue CALLINGCONVENTION jscontext_set_property_value(JsContext* context, Persistent* obj, const uint16_t* name, jsvalue value) 188 | { 189 | #ifdef DEBUG_TRACE_API 190 | std::wcout << "jscontext_set_property_value" << std::endl; 191 | #endif 192 | return context->SetPropertyValue(obj, name, value); 193 | } 194 | 195 | EXPORT jsvalue CALLINGCONVENTION jscontext_get_property_names(JsContext* context, Persistent* obj) 196 | { 197 | #ifdef DEBUG_TRACE_API 198 | std::wcout << "jscontext_get_property_names" << std::endl; 199 | #endif 200 | return context->GetPropertyNames(obj); 201 | } 202 | 203 | EXPORT jsvalue CALLINGCONVENTION jscontext_invoke_property(JsContext* context, Persistent* obj, const uint16_t* name, jsvalue args) 204 | { 205 | #ifdef DEBUG_TRACE_API 206 | std::wcout << "jscontext_invoke_property" << std::endl; 207 | #endif 208 | return context->InvokeProperty(obj, name, args); 209 | } 210 | 211 | EXPORT jsvalue CALLINGCONVENTION jscontext_invoke(JsContext* context, Persistent* funcArg, Persistent* thisArg, jsvalue args) 212 | { 213 | #ifdef DEBUG_TRACE_API 214 | std::wcout << "jscontext_invoke" << std::endl; 215 | #endif 216 | return context->InvokeFunction(funcArg, thisArg, args); 217 | } 218 | 219 | EXPORT JsScript* CALLINGCONVENTION jsscript_new(JsEngine *engine) 220 | { 221 | #ifdef DEBUG_TRACE_API 222 | std::wcout << "jsscript_new" << std::endl; 223 | #endif 224 | JsScript* script = JsScript::New(engine); 225 | return script; 226 | } 227 | 228 | EXPORT void CALLINGCONVENTION jsscript_dispose(JsScript *script) 229 | { 230 | #ifdef DEBUG_TRACE_API 231 | std::wcout << "jsscript_dispose" << std::endl; 232 | #endif 233 | script->Dispose(); 234 | delete script; 235 | } 236 | 237 | EXPORT jsvalue CALLINGCONVENTION jsscript_compile(JsScript* script, const uint16_t* str, const uint16_t *resourceName) 238 | { 239 | #ifdef DEBUG_TRACE_API 240 | std::wcout << "jsscript_compile" << std::endl; 241 | #endif 242 | return script->Compile(str, resourceName); 243 | } 244 | 245 | EXPORT jsvalue CALLINGCONVENTION jsvalue_alloc_string(const uint16_t* str) 246 | { 247 | #ifdef DEBUG_TRACE_API 248 | std::wcout << "jsvalue_alloc_string" << std::endl; 249 | #endif 250 | jsvalue v; 251 | 252 | int length = 0; 253 | while (str[length] != '\0') 254 | length++; 255 | 256 | v.length = length; 257 | v.value.str = new uint16_t[length+1]; 258 | if (v.value.str != NULL) { 259 | for (int i=0 ; i < length ; i++) 260 | v.value.str[i] = str[i]; 261 | v.value.str[length] = '\0'; 262 | v.type = JSVALUE_TYPE_STRING; 263 | } 264 | 265 | return v; 266 | } 267 | 268 | EXPORT jsvalue CALLINGCONVENTION jsvalue_alloc_array(const int32_t length) 269 | { 270 | #ifdef DEBUG_TRACE_API 271 | std::wcout << "jsvalue_alloc_array" << std::endl; 272 | #endif 273 | jsvalue v; 274 | 275 | v.value.arr = new jsvalue[length]; 276 | if (v.value.arr != NULL) { 277 | v.length = length; 278 | v.type = JSVALUE_TYPE_ARRAY; 279 | } 280 | 281 | return v; 282 | } 283 | 284 | EXPORT void CALLINGCONVENTION jsvalue_dispose(jsvalue value) 285 | { 286 | #ifdef DEBUG_TRACE_API 287 | std::wcout << "jsvalue_dispose" << std::endl; 288 | #endif 289 | if (value.type == JSVALUE_TYPE_STRING || value.type == JSVALUE_TYPE_STRING_ERROR) { 290 | if (value.value.str != NULL) { 291 | delete[] value.value.str; 292 | } 293 | } 294 | else if (value.type == JSVALUE_TYPE_ARRAY || value.type == JSVALUE_TYPE_FUNCTION) { 295 | for (int i=0 ; i < value.length ; i++) { 296 | jsvalue_dispose(value.value.arr[i]); 297 | } 298 | if (value.value.arr != NULL) { 299 | delete[] value.value.arr; 300 | } 301 | } 302 | else if (value.type == JSVALUE_TYPE_DICT) { 303 | for (int i=0 ; i < value.length * 2; i++) { 304 | jsvalue_dispose(value.value.arr[i]); 305 | } 306 | if (value.value.arr != NULL) { 307 | delete[] value.value.arr; 308 | } 309 | } 310 | else if (value.type == JSVALUE_TYPE_ERROR) { 311 | jserror *error = (jserror*)value.value.ptr; 312 | jsvalue_dispose(error->resource); 313 | jsvalue_dispose(error->message); 314 | jsvalue_dispose(error->exception); 315 | delete error; 316 | } 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /native/libVroomJs/jscontext.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the VroomJs library. 2 | // 3 | // Author: 4 | // Federico Di Gregorio 5 | // 6 | // Copyright © 2013 Federico Di Gregorio 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #include 27 | #include 28 | #include "vroomjs.h" 29 | 30 | using namespace v8; 31 | 32 | long js_mem_debug_context_count; 33 | 34 | JsContext* JsContext::New(int id, JsEngine *engine) 35 | { 36 | JsContext* context = new JsContext(); 37 | if (context != NULL) { 38 | context->id_ = id; 39 | context->engine_ = engine; 40 | context->isolate_ = engine->GetIsolate(); 41 | 42 | Locker locker(context->isolate_); 43 | Isolate::Scope isolate_scope(context->isolate_); 44 | 45 | context->context_ = new Persistent(Context::New()); 46 | } 47 | return context; 48 | } 49 | 50 | void JsContext::Dispose() 51 | { 52 | if(engine_->GetIsolate() != NULL) { 53 | Locker locker(isolate_); 54 | Isolate::Scope isolate_scope(isolate_); 55 | context_->Dispose(); 56 | delete context_; 57 | } 58 | } 59 | 60 | jsvalue JsContext::Execute(const uint16_t* str, const uint16_t *resourceName = NULL) 61 | { 62 | jsvalue v; 63 | 64 | Locker locker(isolate_); 65 | Isolate::Scope isolate_scope(isolate_); 66 | (*context_)->Enter(); 67 | 68 | HandleScope scope; 69 | TryCatch trycatch; 70 | 71 | Handle source = String::New(str); 72 | Handle