Skip to content

Commit 09b0a88

Browse files
committed
Version 1.1.0:
1. In JavaScriptEngineSwitcher.Msie added support of the MSIE JavaScript Engine version 1.3.0; 2. In JavaScriptEngineSwitcher.V8 improved performance of the `CallFunction` method; 3. In JavaScriptEngineSwitcher.Jurassic added support of the Jurassic version of January 11 2014.
1 parent c08473e commit 09b0a88

File tree

63 files changed

+1601
-377
lines changed

Some content is hidden

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

63 files changed

+1601
-377
lines changed

Binaries/Jurassic/Jurassic.dll

0 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Change log
22
==========
33

4+
## January 16, 2014 - v1.1.0
5+
6+
* In JavaScriptEngineSwitcher.Msie added support of [MSIE JavaScript Engine](http://github.com/Taritsyn/MsieJavaScriptEngine) version 1.3.0
7+
* In JavaScriptEngineSwitcher.V8 improved performance of `CallFunction` method
8+
* In JavaScriptEngineSwitcher.Jurassic added support of [Jurassic](http://jurassic.codeplex.com/) version of January 11 2014
9+
410
## December 30, 2013 - v1.0.0
511

612
* Added support of JavaScript `undefined` type

JavaScriptEngineSwitcher.Core/Constants/EngineName.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

JavaScriptEngineSwitcher.Core/Helpers/JsRuntimeErrorHelpers.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,34 @@
88
using Utilities;
99

1010
/// <summary>
11-
/// JavaScript runtime error helpers
11+
/// JavaScript error helpers
1212
/// </summary>
1313
public static class JsRuntimeErrorHelpers
1414
{
15+
/// <summary>
16+
/// Generates a detailed error message
17+
/// </summary>
18+
/// <param name="jsEngineLoadException">JavaScript engine load exception</param>
19+
/// <returns>Detailed error message</returns>
20+
public static string Format(JsEngineLoadException jsEngineLoadException)
21+
{
22+
var errorMessage = new StringBuilder();
23+
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
24+
jsEngineLoadException.Message);
25+
if (!string.IsNullOrWhiteSpace(jsEngineLoadException.EngineName))
26+
{
27+
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
28+
jsEngineLoadException.EngineName);
29+
}
30+
if (!string.IsNullOrWhiteSpace(jsEngineLoadException.EngineVersion))
31+
{
32+
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineVersion,
33+
jsEngineLoadException.EngineVersion);
34+
}
35+
36+
return errorMessage.ToString();
37+
}
38+
1539
/// <summary>
1640
/// Generates a detailed error message
1741
/// </summary>
@@ -22,8 +46,11 @@ public static string Format(JsRuntimeException jsRuntimeException)
2246
var errorMessage = new StringBuilder();
2347
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
2448
jsRuntimeException.Message);
25-
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
26-
jsRuntimeException.EngineName);
49+
if (!string.IsNullOrWhiteSpace(jsRuntimeException.EngineName))
50+
{
51+
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
52+
jsRuntimeException.EngineName);
53+
}
2754
if (!string.IsNullOrWhiteSpace(jsRuntimeException.EngineVersion))
2855
{
2956
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineVersion,

JavaScriptEngineSwitcher.Core/JavaScriptEngineSwitcher.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
<Compile Include="Configuration\CoreConfiguration.cs" />
4545
<Compile Include="Configuration\JsEngineRegistration.cs" />
4646
<Compile Include="Configuration\JsEngineRegistrationList.cs" />
47-
<Compile Include="Constants\EngineName.cs" />
4847
<Compile Include="EmptyValueException.cs" />
4948
<Compile Include="Helpers\JsRuntimeErrorHelpers.cs" />
5049
<Compile Include="Helpers\ValidationHelpers.cs" />
@@ -53,6 +52,7 @@
5352
<Compile Include="JsEngineLoadException.cs" />
5453
<Compile Include="JsEngineNotFoundException.cs" />
5554
<Compile Include="JsEngineSwitcher.cs" />
55+
<Compile Include="JsException.cs" />
5656
<Compile Include="JsRuntimeException.cs" />
5757
<Compile Include="NotSupportedTypeException.cs" />
5858
<Compile Include="Properties\AssemblyInfo.cs" />

JavaScriptEngineSwitcher.Core/JsEngineBase.cs

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@
1313
/// </summary>
1414
public abstract class JsEngineBase : IJsEngine
1515
{
16+
/// <summary>
17+
/// Flag that object is destroyed
18+
/// </summary>
19+
protected bool _disposed;
20+
21+
22+
private void VerifyNotDisposed()
23+
{
24+
if (_disposed)
25+
{
26+
throw new ObjectDisposedException(ToString());
27+
}
28+
}
29+
30+
protected abstract object InnerEvaluate(string expression);
31+
32+
protected abstract T InnerEvaluate<T>(string expression);
33+
34+
protected abstract void InnerExecute(string code);
35+
36+
protected abstract object InnerCallFunction(string functionName, params object[] args);
37+
38+
protected abstract T InnerCallFunction<T>(string functionName, params object[] args);
39+
40+
protected abstract bool InnerHasVariable(string variableName);
41+
42+
protected abstract object InnerGetVariableValue(string variableName);
43+
44+
protected abstract T InnerGetVariableValue<T>(string variableName);
45+
46+
protected abstract void InnerSetVariableValue(string variableName, object value);
47+
48+
protected abstract void InnerRemoveVariable(string variableName);
49+
50+
#region IJsEngine implementation
51+
1652
public abstract string Name
1753
{
1854
get;
@@ -26,6 +62,8 @@ public abstract string Version
2662

2763
public object Evaluate(string expression)
2864
{
65+
VerifyNotDisposed();
66+
2967
if (string.IsNullOrWhiteSpace(expression))
3068
{
3169
throw new ArgumentException(
@@ -37,6 +75,8 @@ public object Evaluate(string expression)
3775

3876
public T Evaluate<T>(string expression)
3977
{
78+
VerifyNotDisposed();
79+
4080
if (string.IsNullOrWhiteSpace(expression))
4181
{
4282
throw new ArgumentException(
@@ -55,6 +95,8 @@ public T Evaluate<T>(string expression)
5595

5696
public void Execute(string code)
5797
{
98+
VerifyNotDisposed();
99+
58100
if (string.IsNullOrWhiteSpace(code))
59101
{
60102
throw new ArgumentException(
@@ -66,6 +108,8 @@ public void Execute(string code)
66108

67109
public void ExecuteFile(string path, Encoding encoding = null)
68110
{
111+
VerifyNotDisposed();
112+
69113
if (string.IsNullOrWhiteSpace(path))
70114
{
71115
throw new ArgumentException(
@@ -78,6 +122,8 @@ public void ExecuteFile(string path, Encoding encoding = null)
78122

79123
public void ExecuteResource(string resourceName, Type type)
80124
{
125+
VerifyNotDisposed();
126+
81127
if (string.IsNullOrWhiteSpace(resourceName))
82128
{
83129
throw new ArgumentException(
@@ -96,6 +142,8 @@ public void ExecuteResource(string resourceName, Type type)
96142

97143
public void ExecuteResource(string resourceName, Assembly assembly)
98144
{
145+
VerifyNotDisposed();
146+
99147
if (string.IsNullOrWhiteSpace(resourceName))
100148
{
101149
throw new ArgumentException(
@@ -114,6 +162,8 @@ public void ExecuteResource(string resourceName, Assembly assembly)
114162

115163
public object CallFunction(string functionName, params object[] args)
116164
{
165+
VerifyNotDisposed();
166+
117167
if (string.IsNullOrWhiteSpace(functionName))
118168
{
119169
throw new ArgumentException(
@@ -152,6 +202,8 @@ public object CallFunction(string functionName, params object[] args)
152202

153203
public T CallFunction<T>(string functionName, params object[] args)
154204
{
205+
VerifyNotDisposed();
206+
155207
if (string.IsNullOrWhiteSpace(functionName))
156208
{
157209
throw new ArgumentException(
@@ -197,6 +249,8 @@ public T CallFunction<T>(string functionName, params object[] args)
197249

198250
public bool HasVariable(string variableName)
199251
{
252+
VerifyNotDisposed();
253+
200254
if (string.IsNullOrWhiteSpace(variableName))
201255
{
202256
throw new ArgumentException(
@@ -214,6 +268,8 @@ public bool HasVariable(string variableName)
214268

215269
public object GetVariableValue(string variableName)
216270
{
271+
VerifyNotDisposed();
272+
217273
if (string.IsNullOrWhiteSpace(variableName))
218274
{
219275
throw new ArgumentException(
@@ -231,6 +287,8 @@ public object GetVariableValue(string variableName)
231287

232288
public T GetVariableValue<T>(string variableName)
233289
{
290+
VerifyNotDisposed();
291+
234292
if (string.IsNullOrWhiteSpace(variableName))
235293
{
236294
throw new ArgumentException(
@@ -255,6 +313,8 @@ public T GetVariableValue<T>(string variableName)
255313

256314
public void SetVariableValue(string variableName, object value)
257315
{
316+
VerifyNotDisposed();
317+
258318
if (string.IsNullOrWhiteSpace(variableName))
259319
{
260320
throw new ArgumentException(
@@ -284,6 +344,8 @@ public void SetVariableValue(string variableName, object value)
284344

285345
public void RemoveVariable(string variableName)
286346
{
347+
VerifyNotDisposed();
348+
287349
if (string.IsNullOrWhiteSpace(variableName))
288350
{
289351
throw new ArgumentException(
@@ -299,26 +361,12 @@ public void RemoveVariable(string variableName)
299361
InnerRemoveVariable(variableName);
300362
}
301363

302-
public abstract void Dispose();
303-
304-
protected abstract object InnerEvaluate(string expression);
305-
306-
protected abstract T InnerEvaluate<T>(string expression);
307-
308-
protected abstract void InnerExecute(string code);
309-
310-
protected abstract object InnerCallFunction(string functionName, params object[] args);
311-
312-
protected abstract T InnerCallFunction<T>(string functionName, params object[] args);
364+
#endregion
313365

314-
protected abstract bool InnerHasVariable(string variableName);
366+
#region IDisposable implementation
315367

316-
protected abstract object InnerGetVariableValue(string variableName);
317-
318-
protected abstract T InnerGetVariableValue<T>(string variableName);
319-
320-
protected abstract void InnerSetVariableValue(string variableName, object value);
368+
public abstract void Dispose();
321369

322-
protected abstract void InnerRemoveVariable(string variableName);
370+
#endregion
323371
}
324372
}

JavaScriptEngineSwitcher.Core/JsEngineLoadException.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,49 @@
55
/// <summary>
66
/// The exception that is thrown when a loading of JavaScript engine is failed
77
/// </summary>
8-
public sealed class JsEngineLoadException : Exception
8+
public sealed class JsEngineLoadException : JsException
99
{
1010
/// <summary>
11-
/// Initializes a new instance of the JavaScriptEngineSwitcher.Core.JsEngineLoadException class
11+
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
1212
/// with a specified error message
1313
/// </summary>
1414
/// <param name="message">The message that describes the error</param>
1515
public JsEngineLoadException(string message)
16-
: base(message)
16+
: this(message, null)
1717
{ }
1818

1919
/// <summary>
20-
/// Initializes a new instance of the JavaScriptEngineSwitcher.Core.JsEngineLoadException class
20+
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
2121
/// with a specified error message and a reference to the inner exception that is the cause of this exception
2222
/// </summary>
2323
/// <param name="message">The error message that explains the reason for the exception</param>
2424
/// <param name="innerException">The exception that is the cause of the current exception</param>
2525
public JsEngineLoadException(string message, Exception innerException)
26-
: base(message, innerException)
26+
: this(message, string.Empty, string.Empty, innerException)
27+
{ }
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
31+
/// with a specified error message and a reference to the inner exception that is the cause of this exception
32+
/// </summary>
33+
/// <param name="message">The error message that explains the reason for the exception</param>
34+
/// <param name="engineName">Name of JavaScript engine</param>
35+
/// <param name="engineVersion">Version of original JavaScript engine</param>
36+
public JsEngineLoadException(string message, string engineName, string engineVersion)
37+
: this(message, engineName, engineVersion, null)
38+
{ }
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
42+
/// with a specified error message and a reference to the inner exception that is the cause of this exception
43+
/// </summary>
44+
/// <param name="message">The error message that explains the reason for the exception</param>
45+
/// <param name="engineName">Name of JavaScript engine</param>
46+
/// <param name="engineVersion">Version of original JavaScript engine</param>
47+
/// <param name="innerException">The exception that is the cause of the current exception</param>
48+
public JsEngineLoadException(string message, string engineName, string engineVersion,
49+
Exception innerException)
50+
: base(message, engineName, engineVersion, innerException)
2751
{ }
2852
}
2953
}

JavaScriptEngineSwitcher.Core/JsEngineNotFoundException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public sealed class JsEngineNotFoundException : Exception
99
{
1010
/// <summary>
11-
/// Initializes a new instance of the JavaScriptEngineSwitcher.Core.JsEngineNotFoundException class
11+
/// Initializes a new instance of the <see cref="JsEngineNotFoundException"/> class
1212
/// with a specified error message
1313
/// </summary>
1414
/// <param name="message">The message that describes the error</param>
@@ -17,7 +17,7 @@ public JsEngineNotFoundException(string message)
1717
{ }
1818

1919
/// <summary>
20-
/// Initializes a new instance of the JavaScriptEngineSwitcher.Core.JsEngineNotFoundException class
20+
/// Initializes a new instance of the <see cref="JsEngineNotFoundException"/> class
2121
/// with a specified error message and a reference to the inner exception that is the cause of this exception
2222
/// </summary>
2323
/// <param name="message">The error message that explains the reason for the exception</param>

0 commit comments

Comments
 (0)