forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsErrorHelpers.cs
More file actions
116 lines (88 loc) · 3.59 KB
/
JsErrorHelpers.cs
File metadata and controls
116 lines (88 loc) · 3.59 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
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
{
/// <summary>
/// Error helpers
/// </summary>
internal static class JsErrorHelpers
{
/// <summary>
/// Throws if a native method returns an error code
/// </summary>
/// <param name="error">The error</param>
public static void ThrowIfError(JsErrorCode error)
{
if (error != JsErrorCode.NoError)
{
switch (error)
{
case JsErrorCode.InvalidArgument:
throw new JsUsageException(error, "Invalid argument.");
case JsErrorCode.NullArgument:
throw new JsUsageException(error, "Null argument.");
case JsErrorCode.NoCurrentContext:
throw new JsUsageException(error, "No current context.");
case JsErrorCode.InExceptionState:
throw new JsUsageException(error, "Runtime is in exception state.");
case JsErrorCode.NotImplemented:
throw new JsUsageException(error, "Method is not implemented.");
case JsErrorCode.WrongThread:
throw new JsUsageException(error, "Runtime is active on another thread.");
case JsErrorCode.RuntimeInUse:
throw new JsUsageException(error, "Runtime is in use.");
case JsErrorCode.BadSerializedScript:
throw new JsUsageException(error, "Bad serialized script.");
case JsErrorCode.InDisabledState:
throw new JsUsageException(error, "Runtime is disabled.");
case JsErrorCode.CannotDisableExecution:
throw new JsUsageException(error, "Cannot disable execution.");
case JsErrorCode.AlreadyDebuggingContext:
throw new JsUsageException(error, "Context is already in debug mode.");
case JsErrorCode.HeapEnumInProgress:
throw new JsUsageException(error, "Heap enumeration is in progress.");
case JsErrorCode.ArgumentNotObject:
throw new JsUsageException(error, "Argument is not an object.");
case JsErrorCode.InProfileCallback:
throw new JsUsageException(error, "In a profile callback.");
case JsErrorCode.InThreadServiceCallback:
throw new JsUsageException(error, "In a thread service callback.");
case JsErrorCode.CannotSerializeDebugScript:
throw new JsUsageException(error, "Cannot serialize a debug script.");
case JsErrorCode.AlreadyProfilingContext:
throw new JsUsageException(error, "Already profiling this context.");
case JsErrorCode.IdleNotEnabled:
throw new JsUsageException(error, "Idle is not enabled.");
case JsErrorCode.OutOfMemory:
throw new JsEngineException(error, "Out of memory.");
case JsErrorCode.ScriptException:
{
JsValue errorObject;
JsErrorCode innerError = NativeMethods.JsGetAndClearException(out errorObject);
if (innerError != JsErrorCode.NoError)
{
throw new JsFatalException(innerError);
}
throw new JsScriptException(error, errorObject, "Script threw an exception.");
}
case JsErrorCode.ScriptCompile:
{
JsValue errorObject;
JsErrorCode innerError = NativeMethods.JsGetAndClearException(out errorObject);
if (innerError != JsErrorCode.NoError)
{
throw new JsFatalException(innerError);
}
throw new JsScriptException(error, errorObject, "Compile error.");
}
case JsErrorCode.ScriptTerminated:
throw new JsScriptException(error, JsValue.Invalid, "Script was terminated.");
case JsErrorCode.ScriptEvalDisabled:
throw new JsScriptException(error, JsValue.Invalid, "Eval of strings is disabled in this runtime.");
case JsErrorCode.Fatal:
throw new JsFatalException(error);
default:
throw new JsFatalException(error);
}
}
}
}
}