forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackTraceLimit.js
More file actions
129 lines (115 loc) · 3.73 KB
/
StackTraceLimit.js
File metadata and controls
129 lines (115 loc) · 3.73 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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
if (this.WScript && this.WScript.LoadScriptFile) {
this.WScript.LoadScriptFile("LongCallStackThrow.js");
}
Dump("-- Error.stackTraceLimit property descriptor");
var desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
for(var p in desc) {
Dump(p + ": " + desc[p]);
}
Dump("");
function testLongCallStack(limit, noHeader) {
if (limit !== undefined) {
Error.stackTraceLimit = 7; // if next assignment is rejected
Error.stackTraceLimit = limit;
}
if (!noHeader) { Dump("-- Error.stackTraceLimit: " + String(Error.stackTraceLimit)); }
runtest(30);
Dump("");
}
testLongCallStack();
testLongCallStack(4);
testLongCallStack(Infinity);
testLongCallStack(1);
testLongCallStack(20);
testLongCallStack(5.1);
testLongCallStack(-1);
testLongCallStack(-3.2);
testLongCallStack(-Infinity);
testLongCallStack(0);
testLongCallStack(+0);
testLongCallStack(-0);
testLongCallStack(Number.NaN);
testLongCallStack("not a number");
testLongCallStack(new Object());
Error.stackTraceLimit = 8;
Dump("-- preset Error.stackTraceLimit: " + Error.stackTraceLimit);
Dump("");
Dump("--Reconfigure to a getter");
Object.defineProperty(Error, "stackTraceLimit", {
get: function () {
Dump("** Custom stackTraceLimit getter Called, return 3");
return 3;
},
configurable: true
});
testLongCallStack(undefined, true);
Dump("--Delete it");
delete Error.stackTraceLimit;
testLongCallStack();
Dump("--Available on prototype");
Function.prototype.stackTraceLimit = 2;
testLongCallStack();
Dump("--Set to data property again");
Error.stackTraceLimit = 5;
testLongCallStack();
Dump("--Throw in getter");
Object.defineProperty(Error, "stackTraceLimit", {
get: function () {
Dump("** Custom stackTraceLimit getter Called, throw");
throw "My error in custom stackTraceLimit getter";
},
configurable: true
});
testLongCallStack(undefined, true);
Dump("--Throw new Error() in getter");
Object.defineProperty(Error, "stackTraceLimit", {
get: function () {
throw new Error("My error in custom stackTraceLimit getter");
},
configurable: true
});
testLongCallStack(undefined, true);
Dump("--Throw new Error() in getter for a number of times");
var throwErrorCount = 4;
Object.defineProperty(Error, "stackTraceLimit", {
get: function () {
if (throwErrorCount-- > 0) {
throw new Error("My error in custom stackTraceLimit getter");
} else {
return -1;
}
},
configurable: true
});
testLongCallStack(undefined, true);
// Some more tests of different types (appending here to avoid affecting above tests' baseline)
delete Error.stackTraceLimit;
var moreTests = [
null,
undefined,
true,
false,
new Boolean(true),
new Boolean(false),
"4",
new String("5"),
new Number(6),
new Number(Number.NaN),
new Number(Number.Infinity),
new Number(-2),
[],
[1, 2, 3],
{},
{ valueOf: function () { return 2; }, toString: function () { return "valueOf override"; } },
{ valueOf: function () { throw new Error("evil"); }, toString: function () { return "valueOf override throw"; } },
];
moreTests.forEach(function (x) {
if (x === undefined) {
Error.stackTraceLimit = undefined;
}
testLongCallStack(x);
});