Code Monkey home page Code Monkey logo

taritsyn / javascriptengineswitcher Goto Github PK

View Code? Open in Web Editor NEW
428.0 26.0 49.0 830.73 MB

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.

License: Apache License 2.0

C# 80.20% JavaScript 17.35% PowerShell 0.33% HTML 2.02% Handlebars 0.11%
javascript ecmascript dotnet javascript-engine msie v8 jurassic jint chakracore vroomjs

javascriptengineswitcher's Introduction

JavaScript Engine Switcher NuGet version Download count

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (ChakraCore, Jint, Jurassic, MSIE JavaScript Engine for .NET, NiL.JS, Jering.Javascript.NodeJS, Microsoft ClearScript.V8, VroomJs and YantraJS). This library allows you to quickly and easily switch to using of another JavaScript engine.

The supported .NET types are as follows:

  • JavaScriptEngineSwitcher.Core.Undefined
  • System.Boolean
  • System.Int32
  • System.Double
  • System.String

Installation

This library can be installed through NuGet:

Core

JS engines

If you have used the JavaScript Engine Switcher version 2.X, then I recommend to first read “How to upgrade applications to version 3.X” section of the documentation.

Documentation

Documentation is located on the wiki of this Repo.

Release History

See the changelog.

License

Apache License Version 2.0

Who's Using JavaScript Engine Switcher

If you use the JavaScript Engine Switcher in some project, please send me a message so I can include it in this list:

javascriptengineswitcher's People

Contributors

daniilsokolyuk avatar flcdrg avatar lahma avatar mizardx avatar taritsyn avatar trevski avatar vanjoge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascriptengineswitcher's Issues

Documentation says JavaScriptEngineSwitcher.V8 needs Visual C++ 2015 Redistributable

Hi.

We've been trying to upgrade this library. We have the following NuGet packages installed:

  • BundleTransformer.AutoPrefixer => 1.9.166
  • BundleTransformer.Core => 1.9.160
  • BundleTransformer.Less => 1.9.160
  • BundleTransformer.MicrosoftAjax => 1.9.160
  • JavaScriptEngineSwitcher.Core => 2.4.10
  • JavaScriptEngineSwitcher.V8 => 2.4.10
  • JavaScriptEngineSwitcher.V8.Native.win-x64 => 2.4.10

However, installing the Microsoft Visual C++ 2015 Redistributable doesn't work.

We had to install the Visual C++ Redistributable Packages for Visual Studio 2013 in order for our application to run correctly. Otherwise it would fail at runtime when loading v8.

Is this the intended behaviour, or should it work with Microsoft Visual C++ 2015 Redistributable?

System.AccessViolationException in JavascriptEngineSwitcher.ChakraCore

We're using ReactJs.Net on top of JavascriptEngineSwitcher.ChakraCore. Everything works ok on our Win10 dev boxes and our Server 2012r2 CI. However, when deploying to server 2016 we get this error whenever we try to load a view which uses ReactJs.Net on it:

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsGetAndClearExceptionWithMetadata(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsValue ByRef)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorHelpers.ThrowIfError(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorCode)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext.RunScript(System.String, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsSourceContext, System.String)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass45_0.<InnerExecute>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass13_0.<Invoke>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
Faulting application name: w3wp.exe, version: 10.0.14393.0, time stamp: 0x57899b8a
Faulting module name: ChakraCore.DLL, version: 1.5.2.0, time stamp: 0x5943974b
Exception code: 0xc0000005
Fault offset: 0x00000000002e4533
Faulting process id: 0x209c
Faulting application start time: 0x01d3a859ab0b300d
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: PathToWebsiteRoot\bin\x64\ChakraCore.DLL
Report Id: 63809af6-813a-4332-a20a-ba3386c07d16
Faulting package full name: 
Faulting package-relative application ID: 

We're Running on .Net Framework 4.7.1

Support For Native Promises

Currently when I use Promises inside Chakra it throws with this message:

JavaScriptEngineSwitcher.Core.JsRuntimeException : Error: Host may not have set any promise continuation callback. Promises may not be executed.

Help needed on import function

I'm developing a service where people will write their own Javascript code. With it I want them to write modules. Users would also have to explicitely load a given module to use it.

Check the test code below. It does not work because _engine is null when I call ImportModule. I don't know if it's possible to pass back the engine object to the function or how to walk around this issue.

    public class SmartScript
    {
        private IJsEngine _engine;

        public void Test()
        {
            try
            {
                RunJS();
            }
            catch (Exception ex)
            {

            }
        }

        public void RunJS()
        {
            _engine = JsEngineSwitcher.Instance.CreateDefaultEngine();

            try
            {
                _engine.Execute("this.ImSmart = {};");
                _engine.EmbedHostObject("ImSmart", new SmartScript(true));

                _engine.Execute("ImSmart.ImportModule('Nest');");
            }
            finally
            {
                _engine.Dispose();
            }
        }

        public void ImportModule(string name)
        {
            string Code = "(function() { " +
                " this.ImSmart.Nest = function Nest(room){ " +
                " this.room = room; " +
                " this.temperature = null; " +
                " this.ShowRoom = DisplayNest; " +
                " this.SetTemperature = SetTemperature; " +
                " } " +
                " function DisplayNest() " +
                " { " +
                " return 'room is ' + this.room + '. Temperature is ' + this.temperature; " +
                " } " +
                " function SetTemperature(temp) " +
                " { " +
                " this.temperature = temp; " +
                " } " +
                " }());";

            this._engine.Execute(Code);
        }
    }

JavaScriptEngineSwitcher.V8 latest version uses the ClearScript dll whose publickey token is not matching the one that is in the manifest

Hi Taritsyn,

I added the JavaScriptEngineSwitcher.V8 nuget package version 2.4.0 to my asp.net mvc4 application and made necessary changes in the Global.asax.cs file and also in the web.config but when I run my application, I am getting the error as

System.IO.FileLoadException: Could not load file or assembly 'ClearScript, Version=5.4.9.0, Culture=neutral, PublicKeyToken=935d0c957da47c73' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at JavaScriptEngineSwitcher.V8.V8JsEngine.LoadUndefinedValue()
   at JavaScriptEngineSwitcher.V8.V8JsEngine..cctor()

Here I noticed the thing that the public key token 935d0c957da47c73 is coressponds to the ClearScript version 5.4.7

If I install the JavaScriptEngineSwitcher.V8 nuget package version 2.1.0, the application runs fine since it finds the correct version of the ClearScript.

Can you please confirm if this is a potential bug that might have been caused while publishing nuget package? Please find the attached screenshots that corresponds to the public key token of the ClearScript.dll version 5.4.9 and 5.4.7 respectively.

Thanks,
Pramod

clearscript

V8 config can be null

GetV8Configuration returns the value of ConfigurationManager.GetSection("jsEngineSwitcher/v8"). If this configuration section is not in the Web.config or App.config, this returns null, resulting in a NullReferenceException in V8JsEngine's constructor:

image

JavaScriptEngineSwitcher.V8.Native.win-x64 v2.4.13 - Could not load file or assembly ClearScript version 5.4.10.0

Hi Andrey,

after installing JavaScriptEngineSwitcher.V8.Native.win-x64 v2.4.13 to my project (target framework 4.6.2) I got an error "Could not load file or assembly ClearScript version 5.4.10.0, The located assembly manifest doesn't match the assembly version".
The packaged $packages\JavaScriptEngineSwitcher.V8.2.4.10\lib\net45\ClearScript.dll has version 5.4.9.0, so I worked it around adding assembly binding.
<dependentAssembly> <assemblyIdentity name="ClearScript" publicKeyToken="935d0c957da47c73" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.4.10.0" newVersion="5.4.9.0" /> </dependentAssembly>
My main goal is to avoid memory leak issue (reactjs/React.NET#343) which is present (according to my local tests) for v2.4.12 of this library.

P.S. I don't use ClearScript.V8 package :)

AccessViolationException in JavaScriptEngineSwitcher.ChakraCore 2.4.3

When i upgrade ChakraCore (incl. native windows packages) to 2.4.3 in my project, the AccessViolationException is back.
Downgrade to 2.4.2 and everything works perfectly.
It seems something has changed in this version, or do i miss something on my server? (like a specific windows update?)

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsSetCurrentContext(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass22_0`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<InvokeScript>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass12_0`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<Invoke>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

project packages:

  • React.AspNet 3.0.1
  • JavaScriptEngineSwitcher.ChakraCore 2.4.3
  • JavaScriptEngineSwitcher.ChakraCore.Native.win-x64 2.4.3
  • JavaScriptEngineSwitcher.ChakraCore.Native.win-x86 2.4.3

Trying to get Chakracore engine running in a microsoft/dotnet:2 docker container

Has anyone had any success running the chakracore engine in a Linux docker container (hosted in ECS on AWS) based on the microsoft/dotnet:2-sdk image?

I have installed this package:

JavaScriptEngineSwitcher.ChakraCore.Native.debian-x64 v3.0.0.0-alpha9

However I still get the following error:

"Unable to load DLL 'ChakraCore': The specified module or one of its dependencies could not be found."

Everything working fine running in windows locally.

Is there something i'm missing or something else I need to do? Thanks.

.Net Core 2.0 support

This really isn't a bug but wondering if/when there is a port to support .Net Core 2.0 coming soon.

Thanks!

I'm trying to use React.Net with JavaScriptEngineSwitcher.ChakraCore (osx)

  warning NU1701: Package 'JavaScriptEngineSwitcher.V8 3.0.0-alpha5' was restored using    '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

Control stack size for ChakraCore engine

I have strange random stack overflows from inside JS code in ChakraCore (Win64 version). So I though ok I will increase stack by running JS code from Thread with bigger stack. Just to find out it does not have any difference. Then I find out your ScriptDispatcher class which prevents any such solution from calling code, with hardcode stack size. Would it be possibe to enhance code to optionally bypass this queue by some dummy implementation or be able to define stack size though settings?

Just to add nugets I using:

 <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="3.0.0-alpha9" />
 <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.0.0-alpha9" />
 <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" Version="3.0.0-alpha9" />
 <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="3.0.0-alpha9" />
 <PackageReference Include="JavaScriptEngineSwitcher.Core" Version="3.0.0-alpha9" />

Worker process crash with JavascriptEngineSwitcher.Msie + BundleTransformer.Less on Windows Server 2012 Standard

Starting with the April 2018 security rollup patch, there is a hard crash of the IIS worker process when using JavascriptEngineSwitcher.Msie and BundleTransformer.Less. This crash is observed on Windows Server 2012 Standard. It is unknown at the moment whether the crash occurs on later versions of Windows Server.

It's unknown whether this issue originates in JavascriptEngineSwitcher.Msie (unlikely), or in MsieJavascriptEngine (more likely). It's also unknown whether this issue is .less specific, or if it may be observed with other file types as well. I'm adding it here because a simple repro case does not require a direct dependency to MsieJavascriptEngine.

We've been able to work around this issue both by uninstalling the patch (kb4093123), as well as switching from MSIE to another engine (e.g. ChakraCore.)

A simple repro project is attached.

BundleTransformerMsieTest-src.zip

Requests to any .less file via the LessAssetHandler cause the IIS worker process to crash with the following events written to the Windows Event log:

Log Name: Application
Source: .NET Runtime
Date: 4/24/2018 12:26:36 PM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Description:
Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at MsieJavaScriptEngine.ActiveScript.IActiveScriptParse64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags, System.Object ByRef, System.Runtime.InteropServices.ComTypes.EXCEPINFO ByRef)
at MsieJavaScriptEngine.ActiveScript.IActiveScriptParse64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags, System.Object ByRef, System.Runtime.InteropServices.ComTypes.EXCEPINFO ByRef)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptWrapper64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase.InnerExecute(System.String, System.String, Boolean)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase+<>c__DisplayClass34_0.<Evaluate>b__0()
at MsieJavaScriptEngine.ScriptDispatcher+<>c__DisplayClass12_0`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<Invoke>b__0()
at MsieJavaScriptEngine.ScriptDispatcher.StartThread()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2018-04-24T16:26:36.000000000Z" />
<EventRecordID>19019</EventRecordID>
<Channel>Application</Channel>
<Security />
</System>
<EventData>
<Data>Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at MsieJavaScriptEngine.ActiveScript.IActiveScriptParse64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags, System.Object ByRef, System.Runtime.InteropServices.ComTypes.EXCEPINFO ByRef)
at MsieJavaScriptEngine.ActiveScript.IActiveScriptParse64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags, System.Object ByRef, System.Runtime.InteropServices.ComTypes.EXCEPINFO ByRef)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptWrapper64.ParseScriptText(System.String, System.String, System.Object, System.String, UIntPtr, UInt32, MsieJavaScriptEngine.ActiveScript.ScriptTextFlags)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase.InnerExecute(System.String, System.String, Boolean)
at MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase+<>c__DisplayClass34_0.<Evaluate>b__0()
at MsieJavaScriptEngine.ScriptDispatcher+<>c__DisplayClass12_0`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<Invoke>b__0()
at MsieJavaScriptEngine.ScriptDispatcher.StartThread()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
</Data>
</EventData>
</Event>

Log Name: Application
Source: Application Error
Date: 4/24/2018 12:26:36 PM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Description:
Faulting application name: w3wp.exe, version: 8.0.9200.16384, time stamp: 0x50108835
Faulting module name: jscript9.dll, version: 10.0.9200.22411, time stamp: 0x5ab67156
Exception code: 0xc0000005
Fault offset: 0x000000000009de9b
Faulting process id: 0x18b4
Faulting application start time: 0x01d3dbe902db98e6
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\SYSTEM32\jscript9.dll
Report Id: 41d7c693-47dc-11e8-941b-001422091778
Faulting package full name:
Faulting package-relative application ID:
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Level>2</Level>
<Task>100</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2018-04-24T16:26:36.000000000Z" />
<EventRecordID>19020</EventRecordID>
<Channel>Application</Channel>
<Security />
</System>
<EventData>
<Data>w3wp.exe</Data>
<Data>8.0.9200.16384</Data>
<Data>50108835</Data>
<Data>jscript9.dll</Data>
<Data>10.0.9200.22411</Data>
<Data>5ab67156</Data>
<Data>c0000005</Data>
<Data>000000000009de9b</Data>
<Data>18b4</Data>
<Data>01d3dbe902db98e6</Data>
<Data>c:\windows\system32\inetsrv\w3wp.exe</Data>
<Data>C:\Windows\SYSTEM32\jscript9.dll</Data>
<Data>41d7c693-47dc-11e8-941b-001422091778</Data>
<Data>
</Data>
<Data>
</Data>
</EventData>
</Event>

Allow reinitialization of JSEngineSwitcher

In response to a configuration change on my service I sometimes need to switch engines. Currently there's no way to reinitialize the JSEngineSwitcher so my only solution is to unload my app domain and let IIS create a new app domain (where my code uses the new default engine).

JSEngineSwitcher needs a way to be reinitialized. Just changing JsEngineSwitcher.Instance.DefaultEngineName doesn't actually change the engine being used.

JsEngineSwitcher is not mockable in a unit test

I wanted to write a unit test that tests some code that uses JsEngineSwitcher, but it's not possible to mock this class as it's sealed and there's no interface. Could you please make it extend an IJsEngineSwitcher interface so that code that uses it can be unit tested?

Cannot create object with accented characters (following ECMA 5.1 compliance)

This is using jint, but I suspect it's the same with other engines.
For example, this works:

script._engine.Execute("var À_la_maison = 5;");

but this does not work:

int test= 5;
engine.EmbedHostObject("À_la_maison", test);

it returns error:

"The script item name 'À_la_maison' has incorrect format."

Of course, without accent it works well.

Issue running v1.3.3 and v2.4.13 side-by-side

I have a web application with several child web applications.

All the web applications have v1.1.3 installed.

But if I update to the latest version on one of the child web applications, I get this error:
A procedure imported by 'ClearScriptV8-64.dll' could not be loaded.

It has to do with the native dlls and Visual C++ Redistributable for Visual Studio 2015.

Any help is appreciated.

Thanks

Removing package JavaScriptEngineSwitcher.ChakraCore.Native.win-x64 v2.4.6 doesn't remove Error task in csproj file for checking existence of package props

After removing the previous package, installing the new one, and building, I get the following error in projects where the package was removed:

C:\path\to\project\project.csproj(2001,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.2.4.6\build\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.props.

Removing the following task from the .csproj fixed the problem:

<Error Condition="!Exists('..\packages\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.2.4.6\build\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.2.4.6\build\JavaScriptEngineSwitcher.ChakraCore.Native.win-x64.props'))" />

Issue on deployment

Hi, I have an issue when I'm deploying the files. I always get an "access denied" when trying to delete the ClearScript.V8/ClearScriptV8-32.dll file. What does this file do and why is IIS still holding on to it when I'm trying to deploy files?

Add configuration for each engine

The Clearscript V8 engine allows for V8ScriptEngineFlags that turns on debugging and DisableGlobalMembers. It's constructor also accepts V8RuntimeConstraints.

It would be good if consumers can define a class with the configuration for each engine, so as to pass V8RuntimeConstraints and V8ScriptEngineFlags for the V8 engine, or some other parameters for other engines.

Add support for VroomJs

VroomJs is another wrapper around V8. The main advantage of VroomJs is that it works on Linux and Mac OS. It's useful for people that want to use V8 on those platforms. @pauldotknopf has a fork of VroomJs that runs on .NET Core.

NuGet package: https://www.nuget.org/packages/VroomJs/
GitHub repo: https://github.com/pauldotknopf/vroomjs-core

In ReactJS.NET (currently using JavaScriptEngineSwitcher 1.x) I have a custom IJsEngine for an older version of VroomJs, but it would be good to get support into JavaScriptEngineSwitcher. https://github.com/reactjs/React.NET/blob/release-2.5.0/src/React.Core/VroomJsEngine.cs

System.TypeLoadException for ClearScriptV8

Utilizing JavaScriptEngineSwitcher works locally but causes a System.TypeLoadException for the ClearScriptV8 dll files on my IIS 7.5 Server. This appears to be a common issue with ClearScriptV8 as evidenced from this discussion: http://clearscript.codeplex.com/discussions/438696. Dropping back to an earlier version resolved the issue. Some changes are probably necessary to the that ClearScriptV8 is being included in the NuGet Package. If additional details are needed let me know and I can provide them.

MsieJavaScriptEngine.ActiveScript.ActiveScriptException not wrapped

The MSIE engine catches MsieJavaScriptEngine.JsRuntimeExceptions but does not catch MsieJavaScriptEngine.ActiveScript.ActiveScriptExceptions (which can occur if there's a syntax error). These should be wrapped in an appropriate exception class. This exception type is internal so I can't even catch them to handle them nicely at the moment.

Additionally, why is the MsieJsEngine class sealed? This makes it a lot more difficult to add custom behaviour without forking the project.

Expose Compile in JsEngineBase for better support of V8

V8 supports compilation and reusing the compiled scripts. Supporting a Compile step (returns an object), and having Evaluate (that takes an object) on the compile script would allow consumers to improve performance.

For engines that do not support compilation, Compile could return an object that encapsulates the string to be evaluated. Evaluate would then evaluate the encapsulated string as usual.

JavaScriptEngineSwitcher.Core.JsRuntimeException: Out of memory.

Hi Andrey,
First of, thanks for the awesome libraries. YOU ROCK!

Secondly, I have reactjs.net installed with JavaScriptEngineSwitcher.Core and JavaScriptEngineSwitcher.ChakraCore.
I've tried an stress test and IIS stopped working after 2 hours. saying:

JavaScriptEngineSwitcher.Core.JsRuntimeException: Out of memory.
Line: 0
Column:0
at React.ReactEnvironment.Execute[T](String code)

Unfortunately because of the wrapper around the exception, I cannot say what is causing it.
To investigate more, I tried different scenarios and I've found out when I add a space into web.config which will cause the IIS to restart the application, the IIS thread will start growing little by little and after a while IIS will crash even if the stress test is stopped with error:

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an internal error in the .NET Runtime at IP 5A3A86F1 (5A0F0000) with exit code 80131506.

and

Faulting application name: w3wp.exe, version: 10.0.15063.0, time stamp: 0xacce422f
Faulting module name: clr.dll, version: 4.7.2098.0, time stamp: 0x59028d36
Exception code: 0xc0000005
Fault offset: 0x002b86f1
Faulting process id: 0x50a4
Faulting application start time: 0x01d2ee688f323893
Faulting application path: C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: 4362ddc5-f8d7-4441-8916-3830f9268b3a
Faulting package full name:
Faulting package-relative application ID:

I've also made a post on stack-overflow, but I wasn't sure what is causing this and if it is the EngineSwitcher, or the JSPool that causes the error so I've just described the situation.

https://stackoverflow.com/questions/44759636/finding-memory-leak?noredirect=1#comment76500449_44759636

What switcher would you recommend for azure?

We are deployed on azure websites and am getting an out of memory exception.. Either way I don't think IE is installed on azure and we want to support mono.. V8 one has a dependency on 2012 stuff so Is Jurassic the best choice?

JavaScriptEngineSwitcher crashes in a dockerized .NET Core application

I'm pre-rendering some javascript server side in a current project, using ReactJS.NET which in turn relies heavily on JavaScriptEngineSwitcher.

Running the project from a host OS, I have no problems what so ever. I'm using ChakraCore as the engine to pre-render my React components, and I have NuGet references for the following dependencies:

- JavaScriptEngineSwitcher.ChakraCore
- JavaScriptEngineSwitcher.ChakraCore.Native.debian-x64
- JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64
- JavaScriptEngineSwitcher.ChakraCore.Native.win-x64

Running the project with dotnet run succeeds in Windows, Mac OS X and Ubuntu/Debian. Publishing the application and running it from the publish directory succeeds in all operating systems as well (using dotnet publish -c Release -o <MYPATH> && cd <MYPATH> && dotnet <DLLFILE>).

However, when creating a Docker container from my published files and running the application from a container (using base image microsoft/aspnetcore:1.1.1) I get the following exception (runtime, on first page load):

React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.ReactEnvironment ---> React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.JavaScriptEngineFactory ---> React.Exceptions.VroomJsInitialisationException: Failed to initialise VroomJs. This is most likely caused by the native library (libVroomJsNative.so) being out of date or your system lacking a compatible version of V8.

It seems like ChakraCore isn't registered as my default engine, or .NET Core can't find the library file? I register ChakraCore as my default javascript engine using;

services.AddJsEngineSwitcher(options =>
    options.DefaultEngineName = ChakraCoreJsEngine.EngineName
).AddChakraCore();

I've even tried using a ChakraCore binary (libChakraCore.so) compiled in my Docker image, but without success. Is there anything I'm missing, or is it something I'm missing in my setup?

I realize the problem might lie in ReactJS.NET as well - but since the main problem seems to be that the default engine isn't initialized I'm guessing it has something to do with JavaScriptEngineSwitcher.

Send HostObjects as arguments to CallFunction

It would be nice to be able to send host objects as arguments to CallFunction. So for example I would like to be able to do something like this:

class Program
{
    static void Main(string[] args)
    {
        var settings = new ChakraCoreSettings()
        {
            DisableEval = false,
            DisableBackgroundWork = true,
            DisableNativeCodeGeneration = false,
            EnableExperimentalFeatures = false
        };

        JsEngineSwitcher.Instance.EngineFactories.AddChakraCore(settings);
        JsEngineSwitcher.Instance.DefaultEngineName = ChakraCoreJsEngine.EngineName;
        using (var engine = JsEngineSwitcher.Instance.CreateDefaultEngine())
        {
            engine.EmbedHostType("Person", typeof(PersonEntity));
            engine.Execute(@"
            var myMethod = function(model) { 
                return model.Name;
            };");

            object response = engine.CallFunction("myMethod",
                // currently only types listed in
                // JavaScriptEngineSwitcher.Core.Helpers.ValidationHelpers._supportedTypes 
                // can be sent as parameters to CallFunction. 
                new PersonEntity()
                {
                    Name = new NameEntity()
                    {
                        FirstName = "John",
                        LastName = "Doe"
                    }
                });

            Assert.IsTrue(response.GetType() == typeof(NameEntity));
        }
    }
}

Currently it is possible for a HostObject to be returned as a result of CallFunction.

class Program
{
    static void Main(string[] args)
    {
        var settings = new ChakraCoreSettings()
        {
            DisableEval = false,
            DisableBackgroundWork = true,
            DisableNativeCodeGeneration = false,
            EnableExperimentalFeatures = false
        };

        JsEngineSwitcher.Instance.EngineFactories.AddChakraCore(settings);
        JsEngineSwitcher.Instance.DefaultEngineName = ChakraCoreJsEngine.EngineName;
        using (var engine = JsEngineSwitcher.Instance.CreateDefaultEngine())
        {
            engine.EmbedHostType("Person", typeof(PersonEntity));
            engine.Execute(@"
            var myMethod = function() { 
                var p = new Person();
                return p;
            };");

            object response = engine.CallFunction("myMethod");

            Assert.IsTrue(response.GetType() == typeof(PersonEntity));
        }
    }
}

Finalazier thread is blocked becasue of JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine

Hi, @Taritsyn! First of all thanks for your great work on this project!
We use JavaScriptEngineSwitcher.ChakraCore 2.3.2 with ReactJS.NET. But from time to time we are facing the issue that our azure web app crashes and doesn't response. After looking into memory dump I've found that the reason of that is that finalizer thread is blocked. It becomes blocked after trying to finalize ChakraCoreJsEngine.
According to version history I found that similar issue was fixed in 2.3.2 version but looks like not completely. Could you please help with fixing this issue?
Maybe something is going wrong because of using reference type objects in Finalize method.
I attached a stack trace below.

This thread is waiting in a WaitOne

.NET Call Stack

[[HelperMethodFrame_1OBJ] (System.Threading.WaitHandle.WaitOneNative)] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)
mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21
mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28
mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12
JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1)+54
JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)+52
JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Dispose(Boolean)+48
JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Finalize()+1b
[[DebuggerU2MCatchHandlerFrame]]
[[ContextTransitionFrame]]
[[GCFrame]]
[[DebuggerU2MCatchHandlerFrame]]

Full Call Stack
ntdll!NtWaitForMultipleObjects+c
KERNELBASE!WaitForMultipleObjectsEx+10b
clr!WaitForMultipleObjectsEx_SO_TOLERANT+3c
clr!Thread::DoAppropriateWaitWorker+237
clr!Thread::DoAppropriateWait+64
clr!WaitHandleNative::CorWaitOneNative+163
[[HelperMethodFrame_1OBJ] (System.Threading.WaitHandle.WaitOneNative)] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)
mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21
mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21
mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28
mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28
mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12
mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12
JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1<System.Object>)+54
JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)+52
JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Dispose(Boolean)+48
JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Finalize()+1b
clr!FastCallFinalize+6d
clr!MethodTable::CallFinalizer+139
clr!CallFinalizer+a6
clr!FinalizerThread::FinalizeAllObjects+a6
clr!FinalizerThread::FinalizeAllObjects_Wrapper+14
clr!ManagedThreadBase_DispatchInner+71
clr!ManagedThreadBase_DispatchMiddle+7e
clr!ManagedThreadBase_DispatchOuter+5b
[[DebuggerU2MCatchHandlerFrame]]
clr!ManagedThreadBase_DispatchInCorrectAD+15
clr!Thread::DoADCallBack+30f
[[ContextTransitionFrame]]
clr!ManagedThreadBase_DispatchInner+5f
clr!FinalizerThread::DoOneFinalization+129
[[GCFrame]]
clr!FinalizerThread::FinalizeAllObjects+a6
clr!FinalizerThread::FinalizerThreadWorker+ed
clr!ManagedThreadBase_DispatchInner+71
clr!ManagedThreadBase_DispatchMiddle+7e
clr!ManagedThreadBase_DispatchOuter+5b
[[DebuggerU2MCatchHandlerFrame]]
clr!ManagedThreadBase::FinalizerBase+33
clr!FinalizerThread::FinalizerThreadStart+d4
clr!Thread::intermediateThreadProc+55
kernel32!BaseThreadInitThunk+e
ntdll!__RtlUserThreadStart+72
ntdll!_RtlUserThreadStart+1b

MSIE "Catastrophic failure" when disposing

I'm trying to use the MSIE engine and every so often I'm seeing this exception. It doesn't happen every time.

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in MsieJavaScriptEngine.dll
Additional information: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

MsieJavaScriptEngine.dll!MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase.Dispose(bool disposing)
MsieJavaScriptEngine.dll!MsieJavaScriptEngine.ActiveScript.ActiveScriptJsEngineBase.Finalize()

Any ideas what it could be?

I'm on Windows 8.1 and am doing this in an ASP.NET MVC website (well, a library used by an ASP.NET MVC website), using TinyIoC to register and resolve the JS engine implementation.

Let me know if you need any further information.

Deployment on Azure.

Would it be possible for JavaScript Engine Switcher for .Net: V8 to wrap a release build of ClearScript so that the extra C++ binaries would not be required?

This would make it much easier to deploy on Azure as well as other servers.
https://msdn.microsoft.com/en-us/library/azure/hh694038.aspx?f=255&MSPPError=-2147217396

At present I am having to use JavaScript Engine Switcher for .Net: Jint in my project Cruncher due to the difficulties in deployment which is non optimal as Jint takes an extraordinarily long time to initialise and parser on first run.

[OSX] ChakraCore DLL not found

I'm having an issue where the ChakraCore DLL is not found, even if the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package is installed.

This is using dotnet core 1.1 with Visual Studio for Mac, same results with the dotnet cli tools.

Some minimal code to get the exception:

using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.ChakraCore;

namespace MyNamespace
{
    public class Program
    {
        public static void Main(string[] args)
        {            
            IJsEngine engine = new ChakraCoreJsEngine();
            engine.CollectGarbage();
        }
    }
}

The full exception is:

Unhandled Exception: JavaScriptEngineSwitcher.Core.JsEngineLoadException: During loading of ChakraCoreJsEngine error has occurred.	
See more details:

Unable to load DLL 'ChakraCore': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E) ---> System.DllNotFoundException: Unable to load DLL 'ChakraCore': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, JsRuntime& runtime)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass18_0.<.ctor>b__0()
   --- End of inner exception stack trace ---
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(Func`1 del)
   at PunchOutWebFrontend.Program.Main(String[] args) in /Users/steego/Dropbox/Work/DotNet/PunchOut/PunchOut.App.Web/Program.cs:line 17

The csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="React.Core" Version="3.0.1" />
    <PackageReference Include="React.AspNet" Version="3.0.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Core" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.Msie" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="2.4.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Jint" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="2.4.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Extensions.MsDependencyInjection" Version="2.4.0" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="wwwroot\images\" />
    <Folder Include="wwwroot\js\" />
    <Folder Include="wwwroot\css\" />
  </ItemGroup>
</Project>

I'm running the project on OSX Sierra 10.12.4:

Darwin MacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

The library is installed in:

~/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.1/runtimes/osx-x64/native/libChakraCore.dylib

Add the ClearScript.v8 DLL's to the nuget lib folder

We were investigating why our repo was getting slow and it turns out it wasn't liking the v8-ia32.dll and v8-x64.dll files.

They are included in the project and have to be checked in otherwise they won't be copied to the bin folder.

Is there a reason they are included in the project instead of just put in the lib folder in the nuget package? If they are in the lib folder the DI server would just include them with releases and they wouldn't have to be checked in source control.

RuntimeIdentifiers for JavaScriptEngineSwitcher.ChakraCore.Native.win-x??

I need to use runtimeidentifier (RID) win-x64 for my project, rather than (for example) win7-x64 or win10-x64, otherwise other packages break.

This will not work with JavaScriptEngineSwitcher.ChakraCore.Native.win-x64 nuget package, because the Chakracore.dll is in win7-x64 dirs rather than plainly win-x64. Therefore, targeting win-x64 RID will not copy the Chakracore.dll to the outputdir, and my cross-platform webapp using serverside-rendering does not work.

Is there a reason for this? Could we not simply rename win7-x64 to win-x64 and update references in buildfiles / propsfiles, and it would work? (The answer seems to be yes -- I've tried it by editing the files in my local nuget cache, and the small change does the trick).

I assume there is a similar problem for win-x86 vs win7-x86.

If needs be, I can create a pull request?

Noesis DLLs in root of Web project? + x64 doesn't work

Hi, after setting up the V8 Javascript engine, it places the DLLs in the root folder of the web project, which is probably not where they should be, as they are then accessible from the web.

Also, we can't seem to get x64 version to run properly, only x32.

ru-ru files?

It's weird to have ru-ru files included as part of this project, including the plugins for JavaScriptEngineSwitcher. Is this necessary/intended?

GetResourceAsString does not work as expected

In the .NET framework, from day one on, there has been an overload for Assembly.GetManifestResourceStream() which takes a type and a string (name) as arguments.

So when I started to use JavaScriptEngineSwitcher and saw that there are two overloads of the GetResourceAsString, I of course expected them to mirror the behavior of Assembly.GetManifestResourceStream, that is, when a type is specified it should take the namespace into account. But unfortunately it doesn't...

Of course I can prepend the namespace to the name, but that's not a good solution because it makes the code more susceptible to breaking (change the default namespace in the project properties and bam! its broken at runtime).

Issue deploying application (v8-ia32.dll)

Hello I'm having the following issue with the JS Engine Switcher V8 2.4.2 :
Locally everything works OK, I have installed the latest microsoft visual c++ redistributable package.
When I deploy my asp.net mvc application in the hosting I'm having this error when I run it

Cannot load V8 interface assembly. Load failure information for v8-ia32.dll:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bfadc018\8b46cc3b\assembly\dl3\90b800db\753db974_23e1d201\v8-ia32.dll: The specified module could not be found
D:\InetPub\vhosts\site\httpdocs\v8-ia32.dll: The specified module could not be found
D:\InetPub\vhosts\site\httpdocs\bin\v8-ia32.dll: The specified module could not be found]
BundleTransformer.Core.HttpHandlers.AssetHandlerBase.ProcessRequest(HttpContextBase context) +564
BundleTransformer.Core.HttpHandlers.AssetHandlerBase.ProcessRequest(HttpContext context) +40
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +188
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

I have read online that is because of the microsoft redistributable package is not installed in the hosting, but I can't do that. I read on this issue in #11
that Taritsyn said: "What's stopping you to add the msvcp110.dll and msvcr110.dll assemblies in your application package?"
That's what I want to do, deploy the JavaScriptEngineSwitcher c++ dependency with my application together and to avoid the requirement of have the redistributable installed on the server. Install the redistributable package in the hosting is not an option because is not a private virtual server.
Thank you

ChakraCore does not support c # "object" and "dynamic"

JavaScriptEngineSwitcher.Core.JsRuntimeException:“ReferenceError: Could not find suitable method or not enough arguments to invoke of 'Amethod ' method of the host object.
at Global code (Script Document:1:1)”

void Amethod (object p)
{
    Console.WriteLine(p);
}
engine.Execute("xxx.Amethod (123)");

in other engines will not throw this

Process is terminating due to StackOverflowException.

Hi, I'm referencing the 3.0.0.0-alpha 9 prerelease of the javascript engine switcher library within an application hosted in a Linux container running latest ASP.NET core and it works! - except that the process crashes sometime after a call to the engine's evaluate function :(

Is there anything I can do to resolve this? Do you have any ideas as to why this might be happening?

I should say that I am referencing the "JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" nuget package and directly instantiating the ChakraCoreJsEngine.

My service code is really simple and I'm not executing any complex JS although the string passed may contain a reasonably large json object for the script to work against. Am I cleaning things up correctly?

public class JsService : IJsService
{
        public JsService()
        {
        }

        public T Execute<T>(string script)
        {
            using (var context = CreateContext())
            {
                return context.Execute<T>(script);
            }
        }

        public JsContext CreateContext()
        {
            return new JsContext();
        }
}

public class JsContext : IDisposable
{
        IJsEngine Engine { get; }

        public JsContext()
        {
            Engine = new ChakraCoreJsEngine(new ChakraCoreSettings { DisableEval = true });
        }

        public T Execute<T>(string script)
        {
            return Engine.Evaluate<T>(script);
        }

        public void Dispose()
        {
            Engine.Dispose();
        }
}

Thanks,
Stuart

Migrate to .NET Core

Currently the React.NET library uses your library to manage the JavaScript renderers. This library is fairly incompatible with .NET Core. I realize that there are changes coming but in general this library is a pretty good example of one that should be ready to go.

From looking at the library, I've noticed that the primary change is dealing with how the configuration settings are handled as System.Configuration is not currently being migrated to .NET core and the new Configuration.Extensions package is the preferred method of loading.

V8 script timeout

Hi,

Is there a way to get a script timeout with V8 like it seems to be possible with Jint?
I am trying to code the timeout in C# and that is not so obvious so I thought that must be easier to implement the timeout like it's done for Jint.

Paul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.