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 14
Expand file tree
/
Copy pathDefaultErrorReporter.cs
More file actions
74 lines (65 loc) · 2.69 KB
/
DefaultErrorReporter.cs
File metadata and controls
74 lines (65 loc) · 2.69 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
//------------------------------------------------------------------------------
// <license file="DefaultErrorReporter.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;
namespace EcmaScript.NET
{
/// <summary> This is the default error reporter for JavaScript.
///
/// </summary>
class DefaultErrorReporter : ErrorReporter
{
internal static readonly DefaultErrorReporter instance = new DefaultErrorReporter ();
private bool forEval;
private ErrorReporter chainedReporter;
private DefaultErrorReporter ()
{
}
internal static ErrorReporter ForEval (ErrorReporter reporter)
{
DefaultErrorReporter r = new DefaultErrorReporter ();
r.forEval = true;
r.chainedReporter = reporter;
return r;
}
public virtual void Warning (string message, string sourceURI, int line, string lineText, int lineOffset)
{
if (chainedReporter != null) {
chainedReporter.Warning (message, sourceURI, line, lineText, lineOffset);
}
else {
Console.Error.WriteLine ("strict warning: " + message);
}
}
public virtual void Error (string message, string sourceURI, int line, string lineText, int lineOffset)
{
if (forEval) {
throw ScriptRuntime.ConstructError ("SyntaxError", message, sourceURI, line, lineText, lineOffset);
}
if (chainedReporter != null) {
chainedReporter.Error (message, sourceURI, line, lineText, lineOffset);
}
else {
throw RuntimeError (message, sourceURI, line, lineText, lineOffset);
}
}
public virtual EcmaScriptRuntimeException RuntimeError (string message, string sourceURI, int line, string lineText, int lineOffset)
{
if (chainedReporter != null) {
return chainedReporter.RuntimeError (message, sourceURI, line, lineText, lineOffset);
}
else {
return new EcmaScriptRuntimeException (message, sourceURI, line, lineText, lineOffset);
}
}
}
}