Skip to content

Commit 4991ec3

Browse files
committed
Update to Michael Russell's fork of VroomJs
1 parent 4b2b6c1 commit 4991ec3

File tree

6 files changed

+38
-20
lines changed

6 files changed

+38
-20
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
url = https://github.com/Daniel15/simple-nuget-server.git
44
[submodule "lib/VroomJs"]
55
path = lib/VroomJs
6-
url = https://github.com/fogzot/vroomjs.git
6+
url = https://github.com/Daniel15/vroomjs.git

lib/VroomJs.dll

13.5 KB
Binary file not shown.

src/React.JavaScriptEngine.VroomJs/VroomJsEngine.cs

+32-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using System.Linq;
1212
using JavaScriptEngineSwitcher.Core;
1313
using Newtonsoft.Json;
14-
14+
using VroomJs;
1515
using OriginalJsEngine = VroomJs.JsEngine;
1616
using OriginalJsException = VroomJs.JsException;
1717

@@ -24,9 +24,16 @@ namespace React.JavaScriptEngine.VroomJs
2424
public class VroomJsEngine : JsEngineBase
2525
{
2626
/// <summary>
27-
/// The VroomJs engine
27+
/// The VroomJs engine. One engine is shared for the whole app, and separate contexts are
28+
/// used for each instance of this class.
2829
/// </summary>
29-
private readonly OriginalJsEngine _jsEngine;
30+
private static readonly Lazy<OriginalJsEngine> _jsEngine =
31+
new Lazy<JsEngine>(() => new OriginalJsEngine());
32+
33+
/// <summary>
34+
/// The V8 context
35+
/// </summary>
36+
private readonly JsContext _context;
3037

3138
/// <summary>
3239
/// Name of JavaScript engine
@@ -44,14 +51,24 @@ public override string Version
4451
get { return "86f8558d (Aug 17, 2013)"; }
4552
}
4653

54+
/// <summary>
55+
/// The VroomJs engine. One engine is shared for the whole app, and separate contexts are
56+
/// used for each instance of this class.
57+
/// </summary>
58+
private OriginalJsEngine Engine
59+
{
60+
get { return _jsEngine.Value; }
61+
}
62+
4763
/// <summary>
4864
/// Constructs instance of adapter for VroomJs
4965
/// </summary>
5066
public VroomJsEngine()
5167
{
5268
try
5369
{
54-
_jsEngine = new OriginalJsEngine();
70+
// We use one engine with multiple contexts
71+
_context = Engine.CreateContext();
5572
}
5673
catch (Exception e)
5774
{
@@ -78,10 +95,11 @@ private JsRuntimeException ConvertJavaScriptExceptionToJsRuntimeException(
7895
OriginalJsException jsException
7996
)
8097
{
81-
dynamic nativeEx = jsException.NativeException;
82-
return new JsRuntimeException(nativeEx.stack, Name, Version)
98+
return new JsRuntimeException(jsException.Message, Name, Version)
8399
{
84-
Category = nativeEx.name,
100+
Category = jsException.Type,
101+
LineNumber = jsException.Line,
102+
ColumnNumber = jsException.Column
85103
};
86104
}
87105

@@ -94,7 +112,7 @@ protected override object InnerEvaluate(string expression)
94112
{
95113
try
96114
{
97-
return _jsEngine.Execute(expression);
115+
return _context.Execute(expression);
98116
}
99117
catch (OriginalJsException ex)
100118
{
@@ -121,7 +139,7 @@ protected override void InnerExecute(string code)
121139
{
122140
try
123141
{
124-
_jsEngine.Execute(code);
142+
_context.Execute(code);
125143
}
126144
catch (OriginalJsException ex)
127145
{
@@ -145,7 +163,7 @@ protected override object InnerCallFunction(string functionName, params object[]
145163

146164
try
147165
{
148-
return _jsEngine.Execute(code);
166+
return _context.Execute(code);
149167
}
150168
catch (OriginalJsException ex)
151169
{
@@ -185,7 +203,7 @@ protected override object InnerGetVariableValue(string variableName)
185203
{
186204
try
187205
{
188-
return _jsEngine.GetVariable(variableName);
206+
return _context.GetVariable(variableName);
189207
}
190208
catch (OriginalJsException ex)
191209
{
@@ -214,7 +232,7 @@ protected override void InnerSetVariableValue(string variableName, object value)
214232
{
215233
try
216234
{
217-
_jsEngine.SetVariable(variableName, value);
235+
_context.SetVariable(variableName, value);
218236
}
219237
catch (OriginalJsException ex)
220238
{
@@ -231,7 +249,7 @@ protected override void InnerRemoveVariable(string variableName)
231249
var code = string.Format("{0} = undefined", variableName);
232250
try
233251
{
234-
_jsEngine.Execute(code);
252+
_context.Execute(code);
235253
}
236254
catch (OriginalJsException ex)
237255
{
@@ -246,7 +264,7 @@ public override void Dispose()
246264
{
247265
if (!_disposed)
248266
{
249-
_jsEngine.Dispose();
267+
_context.Dispose();
250268
_disposed = true;
251269
}
252270
}

src/React.JavaScriptEngine.VroomJs/VroomJsInitialisationException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static string GetMessage(string innerMessage)
3838
{
3939
return
4040
"Failed to initialise VroomJs. This is most likely caused by the native library " +
41-
"(libvroomjs.so) being out of date or your system lacking a compatible version of " +
41+
"(libVroomJsNative.so) being out of date or your system lacking a compatible version of " +
4242
"V8. Please run Mono with the `MONO_LOG_LEVEL=debug` environment variable for " +
4343
"more debugging information. \n\n " +
4444
"More details: " + innerMessage;

src/React.JavaScriptEngine.VroomJs/readme.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ accomplished using the following shell commands:
55
cd /usr/local/src/
66
git clone https://github.com/v8/v8.git
77
cd v8
8-
git checkout 3.15
8+
git checkout 3.17
99

1010
# Build V8
1111
make werror=no library=shared x64.release
@@ -18,8 +18,8 @@ git submodule update --init
1818
cd lib/VroomJs/libvroomjs/
1919

2020
# Build libvroomjs
21-
g++ jsengine.cpp managedref.cpp bridge.cpp -o libvroomjs.so -shared -L /usr/local/src/v8/out/x64.release/lib.target/ -I /usr/local/src/v8/include/ -fPIC -Wl,--no-as-needed -lv8 -g
22-
cp libvroomjs.so /usr/local/lib/
21+
g++ jscontext.cpp jsengine.cpp managedref.cpp bridge.cpp jsscript.cpp -o libVroomJsNative.so -shared -L /usr/local/src/v8/out/x64.release/lib.target/ -I /usr/local/src/v8/include/ -fPIC -Wl,--no-as-needed -lv8
22+
cp libVroomJsNative.so /usr/local/lib/
2323
ldconfig
2424

2525
If VroomJs fails to load, run Mono with the `MONO_LOG_LEVEL=debug` environment variable to get

0 commit comments

Comments
 (0)