11using System ;
2+ #if ! NETSTANDARD1_3
3+ using System . Runtime . Serialization ;
4+ using System . Security . Permissions ;
5+ #endif
26
37namespace JavaScriptEngineSwitcher . ChakraCore . JsRt
48{
59 /// <summary>
610 /// The exception returned from the Chakra engine
711 /// </summary>
12+ #if ! NETSTANDARD1_3
13+ [ Serializable ]
14+ #endif
815 internal class JsException : Exception
916 {
1017 /// <summary>
1118 /// The error code
1219 /// </summary>
13- private readonly JsErrorCode _code ;
20+ private readonly JsErrorCode _errorCode ;
1421
1522 /// <summary>
1623 /// Gets a error code
1724 /// </summary>
1825 public JsErrorCode ErrorCode
1926 {
20- get { return _code ; }
27+ get { return _errorCode ; }
2128 }
2229
2330
2431 /// <summary>
2532 /// Initializes a new instance of the <see cref="JsException"/> class
2633 /// </summary>
27- /// <param name="code ">The error code returned</param>
28- public JsException ( JsErrorCode code )
29- : this ( code , "A fatal exception has occurred in a JavaScript runtime" )
34+ /// <param name="errorCode ">The error code returned</param>
35+ public JsException ( JsErrorCode errorCode )
36+ : this ( errorCode , "A fatal exception has occurred in a JavaScript runtime" )
3037 { }
3138
3239 /// <summary>
3340 /// Initializes a new instance of the <see cref="JsException"/> class
41+ /// with a specified error message
3442 /// </summary>
35- /// <param name="code ">The error code returned</param>
43+ /// <param name="errorCode ">The error code returned</param>
3644 /// <param name="message">The error message</param>
37- public JsException ( JsErrorCode code , string message )
45+ public JsException ( JsErrorCode errorCode , string message )
3846 : base ( message )
3947 {
40- _code = code ;
48+ _errorCode = errorCode ;
4149 }
50+ #if ! NETSTANDARD1_3
4251
4352 /// <summary>
44- /// Initializes a new instance of the <see cref="JsException"/> class
53+ /// Initializes a new instance of the <see cref="JsException"/> class with serialized data
4554 /// </summary>
46- /// <param name="message ">The error message </param>
47- /// <param name="innerException ">The exception that is the cause of the current exception </param>
48- protected JsException ( string message , Exception innerException )
49- : base ( message , innerException )
55+ /// <param name="info ">The object that holds the serialized data </param>
56+ /// <param name="context ">The contextual information about the source or destination </param>
57+ protected JsException ( SerializationInfo info , StreamingContext context )
58+ : base ( info , context )
5059 {
51- if ( message != null )
60+ if ( info != null )
5261 {
53- _code = ( JsErrorCode ) HResult ;
62+ _errorCode = ( JsErrorCode ) info . GetUInt32 ( "ErrorCode" ) ;
5463 }
5564 }
65+
66+
67+ #region Exception overrides
68+
69+ /// <summary>
70+ /// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object
71+ /// </summary>
72+ /// <param name="info">The <see cref="SerializationInfo"/> to populate with data</param>
73+ /// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization</param>
74+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
75+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
76+ {
77+ if ( info == null )
78+ {
79+ throw new ArgumentNullException ( "info" ) ;
80+ }
81+
82+ base . GetObjectData ( info , context ) ;
83+ info . AddValue ( "ErrorCode" , ( uint ) _errorCode ) ;
84+ }
85+
86+ #endregion
87+ #endif
5688 }
5789}
0 commit comments