-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathNativeErrors.js
75 lines (70 loc) · 1.99 KB
/
NativeErrors.js
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// TrimStackTracePath is needed because same file is run in version 1/2 where LoadScriptFile is not defined
function TrimStackTracePath(obj)
{
return obj;
}
if (this.WScript && typeof this.WScript.LoadScriptFile === "function")
{
this.WScript.LoadScriptFile("../UnitTestFramework/TrimStackTracePath.js");
}
function PadString(s, l)
{
while (s.length < l)
{
s += ' ';
}
return s;
}
function DumpObject(o)
{
var a = new Array();
for (var i in o)
{
a[a.length] = i;
}
a[a.length] = "description"; // Explicitly adding the known non-enumerable members
a[a.length] = "number";
a[a.length] = "stack";
a.sort();
for (var i = 0; i < a.length; i++)
{
if (a[i] === "stack")
{
o[a[i]] = TrimStackTracePath(o[a[i]]);
}
WScript.Echo(PadString(a[i], 15) + "= " + PadString("(" + typeof(o[a[i]]) + ")", 10) + o[a[i]]);
}
WScript.Echo(PadString("toString()", 15) + "= " + o.toString());
}
function Test(s)
{
WScript.Echo(s);
DumpObject(eval("new " + s));
WScript.Echo();
}
function safeCall(f)
{
var args = [];
for (var a = 1; a < arguments.length; ++a)
args.push(arguments[a]);
try
{
return f.apply(this, args);
}
catch (ex)
{
WScript.Echo(ex.name + ": " + ex.message);
}
}
Test("EvalError");
Test("RangeError('This is a range error')");
Test("ReferenceError");
Test("SyntaxError");
Test("TypeError('This is a type error')");
Test("URIError");
safeCall(Test, "RegExpError");
safeCall(Test, "ConversionError");