This repository was archived by the owner on Apr 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathEcmaScriptException.cs
More file actions
220 lines (197 loc) · 7.19 KB
/
Copy pathEcmaScriptException.cs
File metadata and controls
220 lines (197 loc) · 7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//------------------------------------------------------------------------------
// <license file="EcmaScriptException.cs">
//
// The use and distribution terms for this software are contained in the file
// named 'LICENSE', which can be found in the resources directory of this
// distribution.
//
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
//
// </license>
//------------------------------------------------------------------------------
using System;
using System.Text;
namespace EcmaScript.NET
{
/// <summary>
/// The class of exceptions thrown by the JavaScript engine.
/// </summary>
public abstract class EcmaScriptException : Exception
{
public override string Message
{
get
{
string details = base.Message;
if (m_SourceName == null || m_LineNumber <= 0) {
return details;
}
StringBuilder buf = new StringBuilder (details);
buf.Append (" (");
if (m_SourceName != null) {
buf.Append (m_SourceName);
}
if (m_LineNumber > 0) {
buf.Append ('#');
buf.Append (m_LineNumber);
}
buf.Append (')');
return buf.ToString ();
}
}
internal EcmaScriptException ()
{
Interpreter.captureInterpreterStackInfo (this);
}
internal EcmaScriptException (string details)
: base (details)
{
Interpreter.captureInterpreterStackInfo (this);
}
internal EcmaScriptException (string details, Exception innerException)
: base (details, innerException)
{
Interpreter.captureInterpreterStackInfo (this);
}
/// <summary> Get the uri of the script source containing the error, or null
/// if that information is not available.
/// </summary>
public virtual string SourceName
{
get
{
return m_SourceName;
}
}
/// <summary> Initialize the uri of the script source containing the error.
///
/// </summary>
/// <param name="sourceName">the uri of the script source reponsible for the error.
/// It should not be <tt>null</tt>.
///
/// </param>
/// <throws> IllegalStateException if the method is called more then once. </throws>
public void InitSourceName (string sourceName)
{
if (sourceName == null)
throw new ArgumentException ();
if (this.m_SourceName != null)
throw new Exception ();
this.m_SourceName = sourceName;
}
/// <summary> Returns the line number of the statement causing the error,
/// or zero if not available.
/// </summary>
public int LineNumber
{
get
{
return m_LineNumber;
}
}
/// <summary> Initialize the line number of the script statement causing the error.
///
/// </summary>
/// <param name="lineNumber">the line number in the script source.
/// It should be positive number.
///
/// </param>
/// <throws> IllegalStateException if the method is called more then once. </throws>
public void InitLineNumber (int lineNumber)
{
if (lineNumber <= 0)
throw new ArgumentException (Convert.ToString (lineNumber));
if (this.m_LineNumber > 0)
throw new Exception ();
this.m_LineNumber = lineNumber;
}
/// <summary> The column number of the location of the error, or zero if unknown.</summary>
public int ColumnNumber
{
get
{
return m_ColumnNumber;
}
}
/// <summary> Initialize the column number of the script statement causing the error.
///
/// </summary>
/// <param name="columnNumber">the column number in the script source.
/// It should be positive number.
///
/// </param>
/// <throws> IllegalStateException if the method is called more then once. </throws>
public void InitColumnNumber (int columnNumber)
{
if (columnNumber <= 0)
throw new ArgumentException (Convert.ToString (columnNumber));
if (this.m_ColumnNumber > 0)
throw new Exception ();
this.m_ColumnNumber = columnNumber;
}
/// <summary> The source text of the line causing the error, or null if unknown.</summary>
public string LineSource
{
get
{
return m_LineSource;
}
}
/// <summary> Initialize the text of the source line containing the error.
///
/// </summary>
/// <param name="lineSource">the text of the source line reponsible for the error.
/// It should not be <tt>null</tt>.
///
/// </param>
/// <throws> IllegalStateException if the method is called more then once. </throws>
public void InitLineSource (string lineSource)
{
if (lineSource == null)
throw new ArgumentException ();
if (this.m_LineSource != null)
throw new Exception ();
this.m_LineSource = lineSource;
}
internal void RecordErrorOrigin (string sourceName, int lineNumber, string lineSource, int columnNumber)
{
if (sourceName != null) {
InitSourceName (sourceName);
}
if (lineNumber != 0) {
InitLineNumber (lineNumber);
}
if (lineSource != null) {
InitLineSource (lineSource);
}
if (columnNumber != 0) {
InitColumnNumber (columnNumber);
}
InitScriptStackTrace ();
}
private string m_SourceName;
private int m_LineNumber;
private string m_LineSource;
private int m_ColumnNumber;
internal object m_InterpreterStackInfo;
internal int [] m_InterpreterLineData;
private void InitScriptStackTrace () {
m_ScriptStackTrace = Interpreter.GetStack (this);
}
private string m_ScriptStackTrace = null;
public string ScriptStackTrace
{
get
{
return m_ScriptStackTrace;
}
}
public override string ToString ()
{
if (this.StackTrace != null)
return Interpreter.getPatchedStack (this, this.StackTrace.ToString ());
return ScriptStackTrace;
}
}
}