Skip to content

Commit 94b4f17

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore now the original exception is added to instance of the JsRuntimeException class as an internal exception
1 parent 4ac2a61 commit 94b4f17

File tree

9 files changed

+58
-47
lines changed

9 files changed

+58
-47
lines changed

NuGet/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This package does not contain the native implementations of ChakraCore. Therefor
2020
* JavaScriptEngineSwitcher.ChakraCore.Native.debian-x64
2121
* JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64</description>
2222
<summary>JavaScriptEngineSwitcher.ChakraCore contains adapter `ChakraCoreJsEngine` (wrapper for the ChakraCore).</summary>
23-
<releaseNotes>ChakraCore was updated to version 1.5.2.</releaseNotes>
23+
<releaseNotes>Now the original exception is added to instance of the `JsRuntimeException` class as an internal exception.</releaseNotes>
2424
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2525
<language>en-US</language>
2626
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript ChakraCore</tags>

NuGet/JavaScriptEngineSwitcher.ChakraCore/readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
=============
3131
RELEASE NOTES
3232
=============
33-
ChakraCore was updated to version 1.5.2.
33+
Now the original exception is added to instance of the `JsRuntimeException`
34+
class as an internal exception.
3435

3536
=============
3637
DOCUMENTATION

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -887,43 +887,47 @@ private static JsRuntimeException ConvertJsExceptionToJsRuntimeException(
887887
{
888888
category = "Script error";
889889
JsValue metadataValue = jsScriptException.Metadata;
890-
JsValue errorValue = metadataValue.GetProperty("exception");
891890

892-
JsPropertyId stackPropertyId = JsPropertyId.FromString("stack");
893-
if (errorValue.HasProperty(stackPropertyId))
891+
if (metadataValue.IsValid)
894892
{
895-
JsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
896-
message = stackPropertyValue.ConvertToString().ToString();
897-
}
898-
else
899-
{
900-
JsValue messagePropertyValue = errorValue.GetProperty("message");
901-
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
902-
if (!string.IsNullOrWhiteSpace(scriptMessage))
893+
JsValue errorValue = metadataValue.GetProperty("exception");
894+
895+
JsPropertyId stackPropertyId = JsPropertyId.FromString("stack");
896+
if (errorValue.HasProperty(stackPropertyId))
903897
{
904-
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
898+
JsValue stackPropertyValue = errorValue.GetProperty(stackPropertyId);
899+
message = stackPropertyValue.ConvertToString().ToString();
900+
}
901+
else
902+
{
903+
JsValue messagePropertyValue = errorValue.GetProperty("message");
904+
string scriptMessage = messagePropertyValue.ConvertToString().ToString();
905+
if (!string.IsNullOrWhiteSpace(scriptMessage))
906+
{
907+
message = string.Format("{0}: {1}", message.TrimEnd('.'), scriptMessage);
908+
}
905909
}
906-
}
907910

908-
JsPropertyId linePropertyId = JsPropertyId.FromString("line");
909-
if (metadataValue.HasProperty(linePropertyId))
910-
{
911-
JsValue linePropertyValue = metadataValue.GetProperty(linePropertyId);
912-
lineNumber = linePropertyValue.ConvertToNumber().ToInt32() + 1;
913-
}
911+
JsPropertyId linePropertyId = JsPropertyId.FromString("line");
912+
if (metadataValue.HasProperty(linePropertyId))
913+
{
914+
JsValue linePropertyValue = metadataValue.GetProperty(linePropertyId);
915+
lineNumber = linePropertyValue.ConvertToNumber().ToInt32() + 1;
916+
}
914917

915-
JsPropertyId columnPropertyId = JsPropertyId.FromString("column");
916-
if (metadataValue.HasProperty(columnPropertyId))
917-
{
918-
JsValue columnPropertyValue = metadataValue.GetProperty(columnPropertyId);
919-
columnNumber = columnPropertyValue.ConvertToNumber().ToInt32() + 1;
920-
}
918+
JsPropertyId columnPropertyId = JsPropertyId.FromString("column");
919+
if (metadataValue.HasProperty(columnPropertyId))
920+
{
921+
JsValue columnPropertyValue = metadataValue.GetProperty(columnPropertyId);
922+
columnNumber = columnPropertyValue.ConvertToNumber().ToInt32() + 1;
923+
}
921924

922-
JsPropertyId sourcePropertyId = JsPropertyId.FromString("source");
923-
if (metadataValue.HasProperty(sourcePropertyId))
924-
{
925-
JsValue sourcePropertyValue = metadataValue.GetProperty(sourcePropertyId);
926-
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
925+
JsPropertyId sourcePropertyId = JsPropertyId.FromString("source");
926+
if (metadataValue.HasProperty(sourcePropertyId))
927+
{
928+
JsValue sourcePropertyValue = metadataValue.GetProperty(sourcePropertyId);
929+
sourceFragment = sourcePropertyValue.ConvertToString().ToString();
930+
}
927931
}
928932
}
929933
else if (jsException is JsUsageException)
@@ -939,7 +943,7 @@ private static JsRuntimeException ConvertJsExceptionToJsRuntimeException(
939943
category = "Fatal error";
940944
}
941945

942-
var jsEngineException = new JsRuntimeException(message, EngineName, EngineVersion)
946+
var jsEngineException = new JsRuntimeException(message, EngineName, EngineVersion, jsException)
943947
{
944948
ErrorCode = ((uint)jsException.ErrorCode).ToString(CultureInfo.InvariantCulture),
945949
Category = category,

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsEngineException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JavaScriptEngineSwitcher.ChakraCore.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/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsErrorCode.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
3-
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
1+
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
42
{
53
/// <summary>
64
/// The error code returned from a Chakra hosting API
75
/// </summary>
8-
internal enum JsErrorCode : uint
6+
public enum JsErrorCode : uint
97
{
108
/// <summary>
119
/// Success error code

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
1212
#if !NETSTANDARD1_3
1313
[Serializable]
1414
#endif
15-
internal class JsException : Exception
15+
public class JsException : Exception
1616
{
1717
/// <summary>
1818
/// The error code

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsFatalException.cs

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

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsScriptException.cs

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

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

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsUsageException.cs

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

0 commit comments

Comments
 (0)