Skip to content

Commit d4f98cb

Browse files
committed
Now the original exception is added to instance of the JsRuntimeException class as an inner exception
1 parent b73b451 commit d4f98cb

13 files changed

+116
-91
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<description>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet).</description>
1414
<summary>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).</summary>
1515
<releaseNotes>1. In JsRT modes fixed a problems in calculation of error locations;
16-
2. An attempt was made to prevent occurrence of the access violation exception.</releaseNotes>
16+
2. An attempt was made to prevent occurrence of the access violation exception;
17+
3. Now the original exception is added to instance of the `JsRuntimeException` class as an inner exception.</releaseNotes>
1718
<copyright>Copyright (c) 2012-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1819
<language>en-US</language>
1920
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
RELEASE NOTES
2323
=============
2424
1. In JsRT modes fixed a problems in calculation of error locations;
25-
2. An attempt was made to prevent occurrence of the access violation exception.
25+
2. An attempt was made to prevent occurrence of the access violation exception;
26+
3. Now the original exception is added to instance of the `JsRuntimeException`
27+
class as an inner exception.
2628

2729
============
2830
PROJECT SITE

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace MsieJavaScriptEngine.ActiveScript
88
{
99
[Serializable]
10-
internal sealed class ActiveScriptException : Exception
10+
public sealed class ActiveScriptException : Exception
1111
{
1212
/// <summary>
1313
/// Error code

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ private object[] MapToHostType(object[] args)
250250
private JsRuntimeException ConvertActiveScriptExceptionToJsRuntimeException(
251251
ActiveScriptException activeScriptException)
252252
{
253-
var jsEngineException = new JsRuntimeException(activeScriptException.Message, _engineModeName)
253+
var jsEngineException = new JsRuntimeException(activeScriptException.Message, _engineModeName,
254+
activeScriptException)
254255
{
255256
ErrorCode = activeScriptException.ErrorCode.ToString(CultureInfo.InvariantCulture),
256257
Category = activeScriptException.Subcategory,

src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -825,46 +825,49 @@ private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
825825
category = "Script error";
826826
EdgeJsValue errorValue = jsScriptException.Error;
827827

828-
EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId.FromString("stack");
829-
if (errorValue.HasProperty(stackPropertyId))
828+
if (errorValue.IsValid)
830829
{
831-
EdgeJsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
832-
message = stackPropertyValue.ConvertToString().ToString();
833-
}
834-
else
835-
{
836-
EdgeJsValue messagePropertyValue = errorValue.GetProperty("message");
837-
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
838-
if (!string.IsNullOrWhiteSpace(scriptMessage))
830+
EdgeJsPropertyId stackPropertyId = EdgeJsPropertyId.FromString("stack");
831+
if (errorValue.HasProperty(stackPropertyId))
839832
{
840-
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
833+
EdgeJsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
834+
message = stackPropertyValue.ConvertToString().ToString();
835+
}
836+
else
837+
{
838+
EdgeJsValue messagePropertyValue = errorValue.GetProperty("message");
839+
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
840+
if (!string.IsNullOrWhiteSpace(scriptMessage))
841+
{
842+
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
843+
}
841844
}
842-
}
843845

844-
EdgeJsPropertyId linePropertyId = EdgeJsPropertyId.FromString("line");
845-
if (errorValue.HasProperty(linePropertyId))
846-
{
847-
EdgeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
848-
lineNumber = linePropertyValue.ConvertToNumber().ToInt32() + 1;
849-
}
846+
EdgeJsPropertyId linePropertyId = EdgeJsPropertyId.FromString("line");
847+
if (errorValue.HasProperty(linePropertyId))
848+
{
849+
EdgeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
850+
lineNumber = linePropertyValue.ConvertToNumber().ToInt32() + 1;
851+
}
850852

851-
EdgeJsPropertyId columnPropertyId = EdgeJsPropertyId.FromString("column");
852-
if (errorValue.HasProperty(columnPropertyId))
853-
{
854-
EdgeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
855-
columnNumber = columnPropertyValue.ConvertToNumber().ToInt32() + 1;
856-
}
853+
EdgeJsPropertyId columnPropertyId = EdgeJsPropertyId.FromString("column");
854+
if (errorValue.HasProperty(columnPropertyId))
855+
{
856+
EdgeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
857+
columnNumber = columnPropertyValue.ConvertToNumber().ToInt32() + 1;
858+
}
857859

858-
if (lineNumber <= 0 && columnNumber <= 0)
859-
{
860-
GetErrorCoordinatesFromMessage(message, out lineNumber, out columnNumber);
861-
}
860+
if (lineNumber <= 0 && columnNumber <= 0)
861+
{
862+
GetErrorCoordinatesFromMessage(message, out lineNumber, out columnNumber);
863+
}
862864

863-
EdgeJsPropertyId sourcePropertyId = EdgeJsPropertyId.FromString("source");
864-
if (errorValue.HasProperty(sourcePropertyId))
865-
{
866-
EdgeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
867-
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
865+
EdgeJsPropertyId sourcePropertyId = EdgeJsPropertyId.FromString("source");
866+
if (errorValue.HasProperty(sourcePropertyId))
867+
{
868+
EdgeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
869+
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
870+
}
868871
}
869872
}
870873
else if (jsException is JsUsageException)
@@ -880,7 +883,7 @@ private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
880883
category = "Fatal error";
881884
}
882885

883-
var jsEngineException = new JsRuntimeException(message, _engineModeName)
886+
var jsEngineException = new JsRuntimeException(message, _engineModeName, jsException)
884887
{
885888
ErrorCode = ((uint)jsException.ErrorCode).ToString(CultureInfo.InvariantCulture),
886889
Category = category,

src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsScriptException.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MsieJavaScriptEngine.JsRt.Edge
1111
#if !NETSTANDARD1_3
1212
[Serializable]
1313
#endif
14-
internal sealed class EdgeJsScriptException : JsException
14+
public sealed class EdgeJsScriptException : JsException
1515
{
1616
/// <summary>
1717
/// The error
@@ -24,7 +24,7 @@ internal sealed class EdgeJsScriptException : JsException
2424
/// <summary>
2525
/// Gets a JavaScript object representing the script error
2626
/// </summary>
27-
public EdgeJsValue Error
27+
internal EdgeJsValue Error
2828
{
2929
get { return _error; }
3030
}
@@ -34,9 +34,17 @@ public EdgeJsValue Error
3434
/// Initializes a new instance of the <see cref="EdgeJsScriptException"/> class
3535
/// </summary>
3636
/// <param name="errorCode">The error code returned</param>
37-
/// <param name="error">The JavaScript error object</param>
38-
public EdgeJsScriptException(JsErrorCode errorCode, EdgeJsValue error)
39-
: this(errorCode, error, "JavaScript Exception")
37+
public EdgeJsScriptException(JsErrorCode errorCode)
38+
: this(errorCode, "JavaScript Exception")
39+
{ }
40+
41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="EdgeJsScriptException"/> class
43+
/// </summary>
44+
/// <param name="errorCode">The error code returned</param>
45+
/// <param name="message">The error message</param>
46+
public EdgeJsScriptException(JsErrorCode errorCode, string message)
47+
: this(errorCode, EdgeJsValue.Invalid, message)
4048
{ }
4149

4250
/// <summary>
@@ -46,7 +54,7 @@ public EdgeJsScriptException(JsErrorCode errorCode, EdgeJsValue error)
4654
/// <param name="errorCode">The error code returned</param>
4755
/// <param name="error">The JavaScript error object</param>
4856
/// <param name="message">The error message</param>
49-
public EdgeJsScriptException(JsErrorCode errorCode, EdgeJsValue error, string message)
57+
internal EdgeJsScriptException(JsErrorCode errorCode, EdgeJsValue error, string message)
5058
: base(errorCode, message)
5159
{
5260
_error = error;

src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,7 @@ private void ProjectMethods(IeJsValue target, Type type, bool instance)
834834
}
835835
#endif
836836

837-
private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
838-
JsException jsException)
837+
private JsRuntimeException ConvertJsExceptionToJsRuntimeException(JsException jsException)
839838
{
840839
string message = jsException.Message;
841840
string category = string.Empty;
@@ -849,46 +848,49 @@ private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
849848
category = "Script error";
850849
IeJsValue errorValue = jsScriptException.Error;
851850

852-
IeJsPropertyId stackPropertyId = IeJsPropertyId.FromString("stack");
853-
if (errorValue.HasProperty(stackPropertyId))
851+
if (errorValue.IsValid)
854852
{
855-
IeJsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
856-
message = stackPropertyValue.ConvertToString().ToString();
857-
}
858-
else
859-
{
860-
IeJsValue messagePropertyValue = errorValue.GetProperty("message");
861-
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
862-
if (!string.IsNullOrWhiteSpace(scriptMessage))
853+
IeJsPropertyId stackPropertyId = IeJsPropertyId.FromString("stack");
854+
if (errorValue.HasProperty(stackPropertyId))
863855
{
864-
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
856+
IeJsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
857+
message = stackPropertyValue.ConvertToString().ToString();
858+
}
859+
else
860+
{
861+
IeJsValue messagePropertyValue = errorValue.GetProperty("message");
862+
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
863+
if (!string.IsNullOrWhiteSpace(scriptMessage))
864+
{
865+
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
866+
}
865867
}
866-
}
867868

868-
IeJsPropertyId linePropertyId = IeJsPropertyId.FromString("line");
869-
if (errorValue.HasProperty(linePropertyId))
870-
{
871-
IeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
872-
lineNumber = (int)linePropertyValue.ConvertToNumber().ToDouble() + 1;
873-
}
869+
IeJsPropertyId linePropertyId = IeJsPropertyId.FromString("line");
870+
if (errorValue.HasProperty(linePropertyId))
871+
{
872+
IeJsValue linePropertyValue = errorValue.GetProperty(linePropertyId);
873+
lineNumber = (int) linePropertyValue.ConvertToNumber().ToDouble() + 1;
874+
}
874875

875-
IeJsPropertyId columnPropertyId = IeJsPropertyId.FromString("column");
876-
if (errorValue.HasProperty(columnPropertyId))
877-
{
878-
IeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
879-
columnNumber = (int)columnPropertyValue.ConvertToNumber().ToDouble() + 1;
880-
}
876+
IeJsPropertyId columnPropertyId = IeJsPropertyId.FromString("column");
877+
if (errorValue.HasProperty(columnPropertyId))
878+
{
879+
IeJsValue columnPropertyValue = errorValue.GetProperty(columnPropertyId);
880+
columnNumber = (int) columnPropertyValue.ConvertToNumber().ToDouble() + 1;
881+
}
881882

882-
if (lineNumber <= 0 && columnNumber <= 0)
883-
{
884-
GetErrorCoordinatesFromMessage(message, out lineNumber, out columnNumber);
885-
}
883+
if (lineNumber <= 0 && columnNumber <= 0)
884+
{
885+
GetErrorCoordinatesFromMessage(message, out lineNumber, out columnNumber);
886+
}
886887

887-
IeJsPropertyId sourcePropertyId = IeJsPropertyId.FromString("source");
888-
if (errorValue.HasProperty(sourcePropertyId))
889-
{
890-
IeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
891-
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
888+
IeJsPropertyId sourcePropertyId = IeJsPropertyId.FromString("source");
889+
if (errorValue.HasProperty(sourcePropertyId))
890+
{
891+
IeJsValue sourcePropertyValue = errorValue.GetProperty(sourcePropertyId);
892+
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
893+
}
892894
}
893895
}
894896
else if (jsException is JsUsageException)
@@ -904,7 +906,7 @@ private JsRuntimeException ConvertJsExceptionToJsRuntimeException(
904906
category = "Fatal error";
905907
}
906908

907-
var jsEngineException = new JsRuntimeException(message, _engineModeName)
909+
var jsEngineException = new JsRuntimeException(message, _engineModeName, jsException)
908910
{
909911
ErrorCode = ((uint)jsException.ErrorCode).ToString(CultureInfo.InvariantCulture),
910912
Category = category,

src/MsieJavaScriptEngine/JsRt/Ie/IeJsScriptException.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MsieJavaScriptEngine.JsRt.Ie
1111
#if !NETSTANDARD1_3
1212
[Serializable]
1313
#endif
14-
internal sealed class IeJsScriptException : JsException
14+
public sealed class IeJsScriptException : JsException
1515
{
1616
/// <summary>
1717
/// The error
@@ -24,7 +24,7 @@ internal sealed class IeJsScriptException : JsException
2424
/// <summary>
2525
/// Gets a JavaScript object representing the script error
2626
/// </summary>
27-
public IeJsValue Error
27+
internal IeJsValue Error
2828
{
2929
get { return _error; }
3030
}
@@ -34,9 +34,17 @@ public IeJsValue Error
3434
/// Initializes a new instance of the <see cref="IeJsScriptException"/> class
3535
/// </summary>
3636
/// <param name="errorCode">The error code returned</param>
37-
/// <param name="error">The JavaScript error object</param>
38-
public IeJsScriptException(JsErrorCode errorCode, IeJsValue error)
39-
: this(errorCode, error, "JavaScript Exception")
37+
public IeJsScriptException(JsErrorCode errorCode)
38+
: this(errorCode, "JavaScript Exception")
39+
{ }
40+
41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="IeJsScriptException"/> class
43+
/// </summary>
44+
/// <param name="errorCode">The error code returned</param>
45+
/// <param name="message">The error message</param>
46+
public IeJsScriptException(JsErrorCode errorCode, string message)
47+
: this(errorCode, IeJsValue.Invalid, message)
4048
{ }
4149

4250
/// <summary>
@@ -46,7 +54,7 @@ public IeJsScriptException(JsErrorCode errorCode, IeJsValue error)
4654
/// <param name="errorCode">The error code returned</param>
4755
/// <param name="error">The JavaScript error object</param>
4856
/// <param name="message">The error message</param>
49-
public IeJsScriptException(JsErrorCode errorCode, IeJsValue error, string message)
57+
internal IeJsScriptException(JsErrorCode errorCode, IeJsValue error, string message)
5058
: base(errorCode, message)
5159
{
5260
_error = error;

src/MsieJavaScriptEngine/JsRt/JsEngineException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MsieJavaScriptEngine.JsRt
1111
#if !NETSTANDARD1_3
1212
[Serializable]
1313
#endif
14-
internal sealed class JsEngineException : JsException
14+
public sealed class JsEngineException : JsException
1515
{
1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="JsEngineException"/> class

src/MsieJavaScriptEngine/JsRt/JsErrorCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MsieJavaScriptEngine.JsRt
55
/// <summary>
66
/// The error code returned from a Chakra hosting API
77
/// </summary>
8-
internal enum JsErrorCode : uint
8+
public enum JsErrorCode : uint
99
{
1010
/// <summary>
1111
/// Success error code

0 commit comments

Comments
 (0)