Skip to content

Commit c08473e

Browse files
committed
Version 1.0.0:
1. Added support of JavaScript `undefined` type; 2. In JavaScriptEngineSwitcher.Msie added support of MSIE JavaScript Engine version 1.2.0; 3. Added unit tests, that checking support of ECMAScript 5 features.
1 parent f0e3700 commit c08473e

File tree

61 files changed

+8088
-7553
lines changed

Some content is hidden

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

61 files changed

+8088
-7553
lines changed

CHANGELOG.md

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

4+
## December 30, 2013 - v1.0.0
5+
6+
* Added support of JavaScript `undefined` type
7+
* In JavaScriptEngineSwitcher.Msie added support of [MSIE JavaScript Engine](http://github.com/Taritsyn/MsieJavaScriptEngine) version 1.2.0
8+
49
## December 7, 2013 - v0.9.5
510

611
* In JavaScriptEngineSwitcher.V8 the [Noesis Javascript .NET](http://javascriptdotnet.codeplex.com/) was replaced by the [Microsoft ClearScript.V8](http://clearscript.codeplex.com/) library (solves a problem of `V8JsEngine` stable work on 64-bit version of IIS 8.X)

JavaScriptEngineSwitcher.Core/Helpers/JsRuntimeErrorHelpers.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace JavaScriptEngineSwitcher.Core.Helpers
22
{
33
using System;
4+
using System.Globalization;
45
using System.Text;
56

67
using Resources;
@@ -23,6 +24,11 @@ public static string Format(JsRuntimeException jsRuntimeException)
2324
jsRuntimeException.Message);
2425
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineName,
2526
jsRuntimeException.EngineName);
27+
if (!string.IsNullOrWhiteSpace(jsRuntimeException.EngineVersion))
28+
{
29+
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_EngineVersion,
30+
jsRuntimeException.EngineVersion);
31+
}
2632
if (!string.IsNullOrWhiteSpace(jsRuntimeException.ErrorCode))
2733
{
2834
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorCode,
@@ -36,12 +42,12 @@ public static string Format(JsRuntimeException jsRuntimeException)
3642
if (jsRuntimeException.LineNumber > 0)
3743
{
3844
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber,
39-
jsRuntimeException.LineNumber.ToString());
45+
jsRuntimeException.LineNumber.ToString(CultureInfo.InvariantCulture));
4046
}
4147
if (jsRuntimeException.ColumnNumber > 0)
4248
{
4349
errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber,
44-
jsRuntimeException.ColumnNumber.ToString());
50+
jsRuntimeException.ColumnNumber.ToString(CultureInfo.InvariantCulture));
4551
}
4652
if (!string.IsNullOrWhiteSpace(jsRuntimeException.SourceFragment))
4753
{

JavaScriptEngineSwitcher.Core/Helpers/ValidationHelpers.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,16 @@ public static class ValidationHelpers
1212
/// <summary>
1313
/// List of supported types
1414
/// </summary>
15-
private static readonly Type[] _supportedTypes = new[]
15+
private static readonly Type[] _supportedTypes =
1616
{
17-
typeof(Boolean), typeof(Int32), typeof(Double), typeof(String)
17+
typeof(Undefined), typeof(Boolean), typeof(Int32), typeof(Double), typeof(String)
1818
};
1919

2020
/// <summary>
2121
/// Regular expression for working with JS-names
2222
/// </summary>
2323
private static readonly Regex _jsNameRegex = new Regex(@"^[A-Za-z_\$]+[0-9A-Za-z_\$]*$",
2424
RegexOptions.Compiled);
25-
26-
/// <summary>
27-
/// List of reserved words of JavaScript language
28-
/// </summary>
29-
private static readonly string[] _jsReservedWords = new[]
30-
{
31-
"abstract",
32-
"boolean", "break", "byte",
33-
"case", "catch", "char", "class", "const", "continue",
34-
"debugger", "default", "delete", "do", "double",
35-
"else", "enum", "export", "extends",
36-
"false", "final", "finally", "float", "for", "function",
37-
"goto",
38-
"if", "implements", "import", "in", "instanceof", "int",
39-
"interface",
40-
"long",
41-
"native", "new", "null",
42-
"package", "private", "protected", "public",
43-
"return",
44-
"short", "static", "super", "switch", "synchronized",
45-
"this", "throw", "throws", "transient", "true", "try", "typeof",
46-
"var", "volatile", "void",
47-
"while", "with"
48-
};
4925

5026

5127
/// <summary>
@@ -69,16 +45,5 @@ public static bool CheckNameFormat(string name)
6945
{
7046
return _jsNameRegex.IsMatch(name);
7147
}
72-
73-
/// <summary>
74-
/// Checks a allowability of the name (compares with the list of
75-
/// reserved words of JavaScript language)
76-
/// </summary>
77-
/// <param name="name">The name</param>
78-
/// <returns>Result of check (true - allowed; false - forbidden)</returns>
79-
public static bool CheckNameAllowability(string name)
80-
{
81-
return !_jsReservedWords.Contains(name);
82-
}
8348
}
8449
}

JavaScriptEngineSwitcher.Core/IJsEngine.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
/// </summary>
1010
public interface IJsEngine : IDisposable
1111
{
12+
/// <summary>
13+
/// Gets a name of JavaScript engine
14+
/// </summary>
15+
string Name
16+
{
17+
get;
18+
}
19+
20+
/// <summary>
21+
/// Gets a version of original JavaScript engine
22+
/// </summary>
23+
string Version
24+
{
25+
get;
26+
}
27+
28+
1229
/// <summary>
1330
/// Evaluates an expression
1431
/// </summary>

JavaScriptEngineSwitcher.Core/JavaScriptEngineSwitcher.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,20 @@
6666
<DesignTime>True</DesignTime>
6767
<DependentUpon>Strings.ru-ru.resx</DependentUpon>
6868
</Compile>
69+
<Compile Include="Undefined.cs" />
6970
<Compile Include="Utilities\StringBuilderExtensions.cs" />
7071
<Compile Include="Utilities\Utils.cs" />
7172
</ItemGroup>
7273
<ItemGroup>
7374
<EmbeddedResource Include="Resources\Strings.resx">
7475
<Generator>PublicResXFileCodeGenerator</Generator>
7576
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
77+
<SubType>Designer</SubType>
7678
</EmbeddedResource>
7779
<EmbeddedResource Include="Resources\Strings.ru-ru.resx">
7880
<Generator>PublicResXFileCodeGenerator</Generator>
7981
<LastGenOutput>Strings.ru-ru.Designer.cs</LastGenOutput>
82+
<SubType>Designer</SubType>
8083
</EmbeddedResource>
8184
</ItemGroup>
8285
<ItemGroup>

JavaScriptEngineSwitcher.Core/JsEngineBase.cs

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
/// </summary>
1414
public abstract class JsEngineBase : IJsEngine
1515
{
16+
public abstract string Name
17+
{
18+
get;
19+
}
20+
21+
public abstract string Version
22+
{
23+
get;
24+
}
25+
26+
1627
public object Evaluate(string expression)
1728
{
1829
if (string.IsNullOrWhiteSpace(expression))
@@ -109,23 +120,12 @@ public object CallFunction(string functionName, params object[] args)
109120
string.Format(Strings.Common_ArgumentIsEmpty, "functionName"), "functionName");
110121
}
111122

112-
if (args == null)
113-
{
114-
throw new ArgumentNullException("args", Strings.Common_ValueIsNull);
115-
}
116-
117123
if (!ValidationHelpers.CheckNameFormat(functionName))
118124
{
119125
throw new FormatException(
120126
string.Format(Strings.Runtime_InvalidFunctionNameFormat, functionName));
121127
}
122128

123-
if (!ValidationHelpers.CheckNameAllowability(functionName))
124-
{
125-
throw new FormatException(
126-
string.Format(Strings.Runtime_FunctionNameIsForbidden, functionName));
127-
}
128-
129129
int argumentCount = args.Length;
130130
if (argumentCount > 0)
131131
{
@@ -158,11 +158,6 @@ public T CallFunction<T>(string functionName, params object[] args)
158158
string.Format(Strings.Common_ArgumentIsEmpty, "functionName"), "functionName");
159159
}
160160

161-
if (args == null)
162-
{
163-
throw new ArgumentNullException("args", Strings.Common_ValueIsNull);
164-
}
165-
166161
Type returnValueType = typeof(T);
167162
if (!ValidationHelpers.IsSupportedType(returnValueType))
168163
{
@@ -176,12 +171,6 @@ public T CallFunction<T>(string functionName, params object[] args)
176171
string.Format(Strings.Runtime_InvalidFunctionNameFormat, functionName));
177172
}
178173

179-
if (!ValidationHelpers.CheckNameAllowability(functionName))
180-
{
181-
throw new FormatException(
182-
string.Format(Strings.Runtime_FunctionNameIsForbidden, functionName));
183-
}
184-
185174
int argumentCount = args.Length;
186175
if (argumentCount > 0)
187176
{
@@ -220,12 +209,6 @@ public bool HasVariable(string variableName)
220209
string.Format(Strings.Runtime_InvalidVariableNameFormat, variableName));
221210
}
222211

223-
if (!ValidationHelpers.CheckNameAllowability(variableName))
224-
{
225-
throw new FormatException(
226-
string.Format(Strings.Runtime_VariableNameIsForbidden, variableName));
227-
}
228-
229212
return InnerHasVariable(variableName);
230213
}
231214

@@ -243,12 +226,6 @@ public object GetVariableValue(string variableName)
243226
string.Format(Strings.Runtime_InvalidVariableNameFormat, variableName));
244227
}
245228

246-
if (!ValidationHelpers.CheckNameAllowability(variableName))
247-
{
248-
throw new FormatException(
249-
string.Format(Strings.Runtime_VariableNameIsForbidden, variableName));
250-
}
251-
252229
return InnerGetVariableValue(variableName);
253230
}
254231

@@ -273,12 +250,6 @@ public T GetVariableValue<T>(string variableName)
273250
string.Format(Strings.Runtime_InvalidVariableNameFormat, variableName));
274251
}
275252

276-
if (!ValidationHelpers.CheckNameAllowability(variableName))
277-
{
278-
throw new FormatException(
279-
string.Format(Strings.Runtime_VariableNameIsForbidden, variableName));
280-
}
281-
282253
return InnerGetVariableValue<T>(variableName);
283254
}
284255

@@ -296,12 +267,6 @@ public void SetVariableValue(string variableName, object value)
296267
string.Format(Strings.Runtime_InvalidVariableNameFormat, variableName));
297268
}
298269

299-
if (!ValidationHelpers.CheckNameAllowability(variableName))
300-
{
301-
throw new FormatException(
302-
string.Format(Strings.Runtime_VariableNameIsForbidden, variableName));
303-
}
304-
305270
if (value != null)
306271
{
307272
Type variableType = value.GetType();
@@ -331,12 +296,6 @@ public void RemoveVariable(string variableName)
331296
string.Format(Strings.Runtime_InvalidVariableNameFormat, variableName));
332297
}
333298

334-
if (!ValidationHelpers.CheckNameAllowability(variableName))
335-
{
336-
throw new FormatException(
337-
string.Format(Strings.Runtime_VariableNameIsForbidden, variableName));
338-
}
339-
340299
InnerRemoveVariable(variableName);
341300
}
342301

JavaScriptEngineSwitcher.Core/JsRuntimeException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ public string EngineName
1616
set;
1717
}
1818

19+
/// <summary>
20+
/// Gets or sets a version of original JavaScript engine
21+
/// </summary>
22+
public string EngineVersion
23+
{
24+
get;
25+
set;
26+
}
27+
1928
/// <summary>
2029
/// Gets or sets a error code
2130
/// </summary>

JavaScriptEngineSwitcher.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
[assembly: ComVisible(false)]
1414
[assembly: Guid("9f7e9fff-da85-4609-8bee-bdead5a3afe2")]
1515

16-
[assembly: AssemblyVersion("0.9.5.0")]
17-
[assembly: AssemblyFileVersion("0.9.5.0")]
16+
[assembly: AssemblyVersion("1.0.0.0")]
17+
[assembly: AssemblyFileVersion("1.0.0.0")]

JavaScriptEngineSwitcher.Core/Resources/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaScriptEngineSwitcher.Core/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<data name="ErrorDetails_EngineName" xml:space="preserve">
157157
<value>Engine name</value>
158158
</data>
159+
<data name="ErrorDetails_EngineVersion" xml:space="preserve">
160+
<value>Engine version</value>
161+
</data>
159162
<data name="ErrorDetails_ErrorCode" xml:space="preserve">
160163
<value>Error code</value>
161164
</data>

0 commit comments

Comments
 (0)