Skip to content

Commit 88bf133

Browse files
committed
All exceptions made serializable
1 parent d6c8992 commit 88bf133

31 files changed

+401
-182
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
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>
15-
<releaseNotes>1. Added support of .NET Core 1.0.1 (only supported `ChakraIeJsRt` and `ChakraEdgeJsRt` modes) and .NET Framework 4.5.1;
16-
2. Added the `CollectGarbage` method.</releaseNotes>
15+
<releaseNotes>All exceptions made serializable.</releaseNotes>
1716
<copyright>Copyright (c) 2012-2016 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1817
<language>en-US</language>
1918
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
1. Added support of .NET Core 1.0.1 (only supported `ChakraIeJsRt` and
25-
`ChakraEdgeJsRt` modes) and .NET Framework 4.5.1;
26-
2. Added the `CollectGarbage` method.
24+
All exceptions made serializable.
2725

2826
============
2927
PROJECT SITE

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set local_nuget_package_manager=.nuget\NuGet.exe
1111
set package_dir=packages
1212

1313
if not exist %package_dir%\NUnit.Runners (
14-
%local_nuget_package_manager% install NUnit.Runners -Version 3.5.0 -O %package_dir% -ExcludeVersion -NoCache
14+
%local_nuget_package_manager% install NUnit.Runners -Version 3.4.1 -O %package_dir% -ExcludeVersion -NoCache
1515
)
1616

1717
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ localNugetPackageManager=.nuget/NuGet.exe
1010
packageDir=packages
1111

1212
if test ! -d $packageDir/NUnit.Runners; then
13-
mono $localNugetPackageManager install NUnit.Runners -Version 3.5.0 -O $packageDir% -ExcludeVersion -NoCache
13+
mono $localNugetPackageManager install NUnit.Runners -Version 3.4.1 -O $packageDir% -ExcludeVersion -NoCache
1414
fi
1515

1616
koreBuildZip="https://github.com/aspnet/KoreBuild/archive/1.0.0.zip"

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs

Lines changed: 96 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,116 @@
11
#if !NETSTANDARD1_3
22
using System;
3-
using System.Runtime.Serialization;
43
using System.Runtime.InteropServices.ComTypes;
4+
using System.Runtime.Serialization;
5+
using System.Security.Permissions;
56

67
namespace MsieJavaScriptEngine.ActiveScript
78
{
89
[Serializable]
910
internal sealed class ActiveScriptException : Exception
1011
{
12+
/// <summary>
13+
/// Error code
14+
/// </summary>
15+
private int _errorCode;
16+
17+
/// <summary>
18+
/// WCode
19+
/// </summary>
20+
private short _errorWCode;
21+
22+
/// <summary>
23+
/// Application specific source context
24+
/// </summary>
25+
private uint _sourceContext;
26+
27+
/// <summary>
28+
/// Subcategory of error
29+
/// </summary>
30+
private string _subcategory = string.Empty;
31+
32+
/// <summary>
33+
/// Line number on which the error occurred
34+
/// </summary>
35+
private uint _lineNumber;
36+
37+
/// <summary>
38+
/// Column number on which the error occurred
39+
/// </summary>
40+
private int _columnNumber;
41+
42+
/// <summary>
43+
/// Content of the line on which the error occurred
44+
/// </summary>
45+
private string _sourceError = string.Empty;
46+
1147
/// <summary>
1248
/// Gets or sets a error code
1349
/// </summary>
1450
public int ErrorCode
1551
{
16-
get;
17-
set;
52+
get { return _errorCode; }
53+
set { _errorCode = value; }
1854
}
1955

2056
/// <summary>
2157
/// Gets or sets a WCode
2258
/// </summary>
2359
public short ErrorWCode
2460
{
25-
get;
26-
set;
61+
get { return _errorWCode; }
62+
set { _errorWCode = value; }
2763
}
2864

2965
/// <summary>
3066
/// Gets or sets a application specific source context
3167
/// </summary>
3268
public uint SourceContext
3369
{
34-
get;
35-
set;
70+
get { return _sourceContext; }
71+
set { _sourceContext = value; }
3672
}
3773

3874
/// <summary>
3975
/// Gets or sets a subcategory of error
4076
/// </summary>
4177
public string Subcategory
4278
{
43-
get;
44-
set;
79+
get { return _subcategory; }
80+
set { _subcategory = value; }
4581
}
4682

4783
/// <summary>
4884
/// Gets or sets a line number on which the error occurred
4985
/// </summary>
5086
public uint LineNumber
5187
{
52-
get;
53-
set;
88+
get { return _lineNumber; }
89+
set { _lineNumber = value; }
5490
}
5591

5692
/// <summary>
5793
/// Gets or sets a column number on which the error occurred
5894
/// </summary>
5995
public int ColumnNumber
6096
{
61-
get;
62-
set;
97+
get { return _columnNumber; }
98+
set { _columnNumber = value; }
6399
}
64100

65101
/// <summary>
66102
/// Gets or sets a content of the line on which the error occurred
67103
/// </summary>
68104
public string SourceError
69105
{
70-
get;
71-
set;
106+
get { return _sourceError; }
107+
set { _sourceError = value; }
72108
}
73109

74110

75111
/// <summary>
76112
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class
77-
/// </summary>
78-
public ActiveScriptException()
79-
{ }
80-
81-
/// <summary>
82-
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class
113+
/// with a specified error message
83114
/// </summary>
84115
/// <param name="message">The message</param>
85116
public ActiveScriptException(string message)
@@ -88,14 +119,8 @@ public ActiveScriptException(string message)
88119

89120
/// <summary>
90121
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class
91-
/// </summary>
92-
/// <param name="innerException">The inner exception</param>
93-
public ActiveScriptException(Exception innerException)
94-
: base(null, innerException)
95-
{ }
96-
97-
/// <summary>
98-
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class
122+
/// with a specified error message and a reference to the inner exception
123+
/// that is the cause of this exception
99124
/// </summary>
100125
/// <param name="message">The message</param>
101126
/// <param name="innerException">The inner exception</param>
@@ -104,21 +129,24 @@ public ActiveScriptException(string message, Exception innerException)
104129
{ }
105130

106131
/// <summary>
107-
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class
132+
/// Initializes a new instance of the <see cref="ActiveScriptException"/> class with serialized data
108133
/// </summary>
109-
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
110-
/// that holds the serialized object data about the exception being thrown</param>
111-
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/>
112-
/// that contains contextual information about the source or destination</param>
113-
/// <exception cref="T:System.ArgumentNullException">
114-
/// The <paramref name="info"/> parameter is null
115-
/// </exception>
116-
/// <exception cref="T:System.Runtime.Serialization.SerializationException">
117-
/// The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0)
118-
/// </exception>
134+
/// <param name="info">The object that holds the serialized data</param>
135+
/// <param name="context">The contextual information about the source or destination</param>
119136
private ActiveScriptException(SerializationInfo info, StreamingContext context)
120137
: base(info, context)
121-
{ }
138+
{
139+
if (info != null)
140+
{
141+
_errorCode = info.GetInt32("ErrorCode");
142+
_errorWCode = info.GetInt16("ErrorWCode");
143+
_sourceContext = info.GetUInt32("SourceContext");
144+
_subcategory = info.GetString("Subcategory");
145+
_lineNumber = info.GetUInt32("LineNumber");
146+
_columnNumber = info.GetInt32("ColumnNumber");
147+
_sourceError = info.GetString("SourceError");
148+
}
149+
}
122150

123151

124152
internal static ActiveScriptException Create(IActiveScriptError error)
@@ -191,6 +219,33 @@ internal static ActiveScriptException Create(IActiveScriptError error)
191219

192220
return activeScriptException;
193221
}
222+
223+
#region Exception overrides
224+
225+
/// <summary>
226+
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object
227+
/// </summary>
228+
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data</param>
229+
/// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization</param>
230+
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
231+
public override void GetObjectData(SerializationInfo info, StreamingContext context)
232+
{
233+
if (info == null)
234+
{
235+
throw new ArgumentNullException("info");
236+
}
237+
238+
base.GetObjectData(info, context);
239+
info.AddValue("ErrorCode", _errorCode);
240+
info.AddValue("ErrorWCode", _errorWCode);
241+
info.AddValue("SourceContext", _sourceContext);
242+
info.AddValue("Subcategory", _subcategory);
243+
info.AddValue("LineNumber", _lineNumber);
244+
info.AddValue("ColumnNumber", _columnNumber);
245+
info.AddValue("SourceError", _sourceError);
246+
}
247+
248+
#endregion
194249
}
195250
}
196251
#endif

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ private JsRuntimeException ConvertActiveScriptExceptionToJsRuntimeException(
267267
LineNumber = (int)activeScriptException.LineNumber,
268268
ColumnNumber = activeScriptException.ColumnNumber,
269269
SourceFragment = activeScriptException.SourceError,
270-
Source = activeScriptException.Source,
271270
HelpLink = activeScriptException.HelpLink
272271
};
273272

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
using System;
2+
#if !NETSTANDARD1_3
3+
using System.Runtime.Serialization;
4+
#endif
25

36
namespace MsieJavaScriptEngine
47
{
58
/// <summary>
6-
/// The exception that is thrown when a loading of JavaScript engine is failed
9+
/// The exception that is thrown when a loading of JS engine is failed
710
/// </summary>
11+
#if !NETSTANDARD1_3
12+
[Serializable]
13+
#endif
814
public sealed class JsEngineLoadException : JsException
915
{
1016
/// <summary>
@@ -13,38 +19,48 @@ public sealed class JsEngineLoadException : JsException
1319
/// </summary>
1420
/// <param name="message">The message that describes the error</param>
1521
public JsEngineLoadException(string message)
16-
: this(message, string.Empty)
22+
: base(message)
1723
{ }
1824

1925
/// <summary>
2026
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
21-
/// with a specified error message and a reference to the inner exception that is the cause of this exception
27+
/// with a specified error message and a reference to the inner exception
28+
/// that is the cause of this exception
2229
/// </summary>
2330
/// <param name="message">The error message that explains the reason for the exception</param>
2431
/// <param name="innerException">The exception that is the cause of the current exception</param>
2532
public JsEngineLoadException(string message, Exception innerException)
26-
: this(message, string.Empty, innerException)
33+
: base(message, innerException)
2734
{ }
2835

2936
/// <summary>
3037
/// 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
3238
/// </summary>
3339
/// <param name="message">The error message that explains the reason for the exception</param>
34-
/// <param name="engineMode">Name of JavaScript engine mode</param>
40+
/// <param name="engineMode">Name of JS engine mode</param>
3541
public JsEngineLoadException(string message, string engineMode)
36-
: this(message, engineMode, null)
42+
: base(message, engineMode)
3743
{ }
3844

3945
/// <summary>
4046
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class
41-
/// with a specified error message and a reference to the inner exception that is the cause of this exception
4247
/// </summary>
4348
/// <param name="message">The error message that explains the reason for the exception</param>
44-
/// <param name="engineMode">Name of JavaScript engine mode</param>
49+
/// <param name="engineMode">Name of JS engine mode</param>
4550
/// <param name="innerException">The exception that is the cause of the current exception</param>
4651
public JsEngineLoadException(string message, string engineMode, Exception innerException)
4752
: base(message, engineMode, innerException)
4853
{ }
54+
#if !NETSTANDARD1_3
55+
56+
/// <summary>
57+
/// Initializes a new instance of the <see cref="JsEngineLoadException"/> class with serialized data
58+
/// </summary>
59+
/// <param name="info">The object that holds the serialized data</param>
60+
/// <param name="context">The contextual information about the source or destination</param>
61+
private JsEngineLoadException(SerializationInfo info, StreamingContext context)
62+
: base(info, context)
63+
{ }
64+
#endif
4965
}
5066
}

0 commit comments

Comments
 (0)