Skip to content

Commit c9e2c80

Browse files
committed
Version 1.0.1
1 parent db2bf00 commit c9e2c80

File tree

9 files changed

+74
-34
lines changed

9 files changed

+74
-34
lines changed

MsieJavaScriptEngine/ActiveScript/ActiveScriptSite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public ActiveScriptSite(string documentVersion)
103103

104104
if (_jsEngine == null)
105105
{
106-
throw new NullReferenceException(Strings.Runtime_JsEngineInitializationFailed);
106+
throw new JsEngineLoadException(Strings.Runtime_JsEngineNotLoaded);
107107
}
108108
}
109109

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace MsieJavaScriptEngine
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// The exception that is thrown when a loading of JavaScript engine is failed
7+
/// </summary>
8+
internal sealed class JsEngineLoadException : Exception
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the MsieJavaScriptEngine.JsEngineLoadException class
12+
/// with a specified error message
13+
/// </summary>
14+
/// <param name="message">The message that describes the error</param>
15+
public JsEngineLoadException(string message)
16+
: base(message)
17+
{ }
18+
19+
/// <summary>
20+
/// Initializes a new instance of the MsieJavaScriptEngine.JsEngineLoadException class
21+
/// with a specified error message and a reference to the inner exception that is the cause of this exception
22+
/// </summary>
23+
/// <param name="message">The error message that explains the reason for the exception</param>
24+
/// <param name="innerException">The exception that is the cause of the current exception</param>
25+
public JsEngineLoadException(string message, Exception innerException)
26+
: base(message, innerException)
27+
{ }
28+
}
29+
}

MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="ActiveScript\ScriptTextFlags.cs" />
5858
<Compile Include="ActiveScript\ScriptThreadState.cs" />
5959
<Compile Include="ActiveScript\ScriptTypeLibFlags.cs" />
60+
<Compile Include="JsEngineLoadException.cs" />
6061
<Compile Include="JsEngines\ChakraJsEngine.cs" />
6162
<Compile Include="JsEngines\JsEngine.cs" />
6263
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -71,6 +72,7 @@
7172
<DependentUpon>Strings.resx</DependentUpon>
7273
</Compile>
7374
<Compile Include="MsieJsEngine.cs" />
75+
<Compile Include="UndefinedValueException.cs" />
7476
<Compile Include="Utils.cs" />
7577
</ItemGroup>
7678
<ItemGroup>

MsieJavaScriptEngine/MsieJsEngine.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public sealed class MsieJsEngine : IDisposable
2626
/// </summary>
2727
const string MSIE_JAVASCRIPT_LIBRARY_RESOURCE_NAME = "MsieJavaScriptEngine.Resources.msieJavaScriptEngine.min.js";
2828

29-
/// <summary>
30-
/// The error code is encountered in accessing to the undefined value
31-
/// </summary>
32-
const int VALUE_UNDEFINED_ERROR_CODE = -2146823279;
33-
3429
/// <summary>
3530
/// Regular expression for working with JS-names
3631
/// </summary>
@@ -247,26 +242,11 @@ public T Evaluate<T>(string expression)
247242

248243
private object EvaluateInner(string expression)
249244
{
250-
object result;
251-
try
252-
{
253-
result = _activeScriptSite.ExecuteScriptText(expression, true);
254-
}
255-
catch (ActiveScriptException e)
256-
{
257-
if (e.ErrorCode == VALUE_UNDEFINED_ERROR_CODE)
258-
{
259-
result = null;
260-
}
261-
else
262-
{
263-
throw;
264-
}
265-
}
245+
object result = _activeScriptSite.ExecuteScriptText(expression, true);
266246

267247
if (result == null)
268248
{
269-
throw new NullReferenceException(
249+
throw new UndefinedValueException(
270250
string.Format(Strings.Runtime_ExpressionResultIsUndefined, expression));
271251
}
272252

@@ -515,7 +495,7 @@ public bool HasProperty(string variableName, string propertyName)
515495

516496
if (!HasVariableInner(variableName))
517497
{
518-
throw new NullReferenceException(
498+
throw new UndefinedValueException(
519499
string.Format(Strings.Runtime_VariableNotExist, variableName));
520500
}
521501

@@ -550,7 +530,7 @@ public object GetPropertyValue(string variableName, string propertyName)
550530

551531
if (!HasVariableInner(variableName))
552532
{
553-
throw new NullReferenceException(
533+
throw new UndefinedValueException(
554534
string.Format(Strings.Runtime_VariableNotExist, variableName));
555535
}
556536

@@ -583,7 +563,7 @@ public T GetPropertyValue<T>(string variableName, string propertyName)
583563

584564
if (!HasVariableInner(variableName))
585565
{
586-
throw new NullReferenceException(
566+
throw new UndefinedValueException(
587567
string.Format(Strings.Runtime_VariableNotExist, variableName));
588568
}
589569

MsieJavaScriptEngine/Resources/Strings.Designer.cs

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

MsieJavaScriptEngine/Resources/Strings.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156
<data name="Runtime_ItemNotFound" xml:space="preserve">
157157
<value>Item with name '{0}' not found.</value>
158158
</data>
159-
<data name="Runtime_JsEngineInitializationFailed" xml:space="preserve">
160-
<value>During initialization of JavaScript engine error has occurred.</value>
159+
<data name="Runtime_JsEngineNotLoaded" xml:space="preserve">
160+
<value>Could not load none of the JavaScript engines. Perhaps you have not installed the Internet Explorer browser.</value>
161161
</data>
162162
<data name="Runtime_PropertyNameIsForbidden" xml:space="preserve">
163163
<value>Property name '{0}' is forbidden, as one of its parts matches with the reserved word of JavaScript language.</value>

MsieJavaScriptEngine/Resources/Strings.ru-ru.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156
<data name="Runtime_ItemNotFound" xml:space="preserve">
157157
<value>Элемент с именем "{0}" не найден!</value>
158158
</data>
159-
<data name="Runtime_JsEngineInitializationFailed" xml:space="preserve">
160-
<value>При инициализации JavaScript-движка произошла ошибка!</value>
159+
<data name="Runtime_JsEngineNotLoaded" xml:space="preserve">
160+
<value>Не удалось загрузить ни один из JavaScript-движков! Возможно, на вашем компьютере не установлен браузер Internet Explorer.</value>
161161
</data>
162162
<data name="Runtime_PropertyNameIsForbidden" xml:space="preserve">
163163
<value>Имя свойства "{0}" запрещено, т.к. одна из его частей совпадает с зарезервированным словом JavaScript!</value>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace MsieJavaScriptEngine
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// The exception that is thrown when a specified value is undefined
7+
/// </summary>
8+
public sealed class UndefinedValueException : Exception
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the MsieJavaScriptEngine.UndefinedValueException class
12+
/// with a specified error message
13+
/// </summary>
14+
/// <param name="message">The message that describes the error</param>
15+
public UndefinedValueException(string message)
16+
: base(message)
17+
{ }
18+
19+
/// <summary>
20+
/// Initializes a new instance of the MsieJavaScriptEngine.UndefinedValueException class
21+
/// with a specified error message and a reference to the inner exception that is the cause of this exception
22+
/// </summary>
23+
/// <param name="message">The error message that explains the reason for the exception</param>
24+
/// <param name="innerException">The exception that is the cause of the current exception</param>
25+
public UndefinedValueException(string message, Exception innerException)
26+
: base(message, innerException)
27+
{ }
28+
}
29+
}

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>MsieJavaScriptEngine</id>
5-
<version>1.0.0</version>
5+
<version>1.0.1</version>
66
<title>MSIE JavaScript Engine for .NET</title>
77
<authors>Andrey Taritsyn</authors>
88
<owners>Andrey Taritsyn</owners>

0 commit comments

Comments
 (0)