Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / stack-trace.js
blobbb1b3ff853583303fb99565720c11ca7bba3567d
1 if (!this.alert) {
2 debug = print;
3 description = print;
6 description(
7 'This test checks stack trace corectness in special cases.'
8 );
10 function printStack(stackTrace) {
11 debug("--> Stack Trace:")
12 stackTrace = stackTrace.split("\n");
13 var length = Math.min(stackTrace.length, 100);
14 for (var i = 0; i < length; i++) {
15 var indexOfAt = stackTrace[i].indexOf('@')
16 var indexOfLastSlash = stackTrace[i].lastIndexOf('/');
17 if (indexOfLastSlash == -1)
18 indexOfLastSlash = indexOfAt
19 var functionName = stackTrace[i].substring(0, indexOfAt);
20 var fileName = stackTrace[i].substring(indexOfLastSlash + 1);
21 debug(" " + i + " " + functionName + " at " + fileName);
23 debug('');
25 function hostThrower() { Element.prototype.appendChild.call({ }, [{ }]); }
26 function callbacker(f) { [0].map(f); }
27 function outer(errorName) { inner(errorName); }
28 function inner(errorName) { throw new Error("Error in " + errorName); }
29 function evaler(code) { eval(code); }
30 function normalOuter() { normalInner(); }
31 function normalInner() { if(thisVarDoesntExist) failIfTrue("shouldFailBeforeThis") };
32 function scripterInner() { htmlInner(); }
33 function scripterOuter() { htmlOuter(); }
34 // Expected functions in stack trace
35 // Normal Case
36 try { normalOuter() } catch (e) { printStack(e.stack) } // normalOuter -> normalInner
38 // Eval Case
39 try { evaler("inner('inner eval');"); } catch (e) { printStack(e.stack) } // evaler -> eval -> inner
40 try { evaler("outer('outer eval');"); } catch (e) { printStack(e.stack) } // evaler -> eval -> outer -> inner
42 // Function Callback Case
43 try { callbacker(inner('inner map')); } catch (e) { printStack(e.stack); } // callbacker -> map -> inner
44 try { callbacker(outer('outer map')); } catch (e) { printStack(e.stack); } // callbacker -> map -> outer -> inner
46 // Host Code Case
47 try { hostThrower(); } catch (e) { printStack(e.stack); } // hostThrower
49 try { scripterInner(); } catch (e) { printStack(e.stack) } // program -> scripter -> inner
50 try { scripterOuter(); } catch (e) { printStack(e.stack) } // program -> scripter -> outer -> inner
52 function selfRecursive1() { selfRecursive1();
56 try { selfRecursive1(); } catch (e) { printStack(e.stack) } // selfRecursive1 -> selfRecursive1 -> selfRecursive1 -> selfRecursive1 ...
58 function selfRecursive2() {
59 // A little work to make the DFG kick in
60 for (var i = 0; i < 10; i++) {
61 if (i == 9)
62 selfRecursive2();
66 try { selfRecursive2(); } catch (e) { printStack(e.stack) } // selfRecursive2 -> selfRecursive2 -> selfRecursive2 -> selfRecursive2 ...
68 function selfRecursive3() {
69 eval("selfRecursive3()");
72 try { selfRecursive3(); } catch (e) { printStack(e.stack) } // selfRecursive3 -> eval -> selfRecursive3 -> eval ...
74 var callCount = 0;
76 function throwError() {
77 throw {};
80 var object = {
81 get getter1() {
82 var o = {
83 valueOf: function() {
84 throwError()
87 +o;
89 get getter2() {
90 var o = {
91 valueOf: throwError
93 +o;
95 get getter3() {
96 var o1 = {
97 valueOf: throwError
99 var o2 = {
100 valueOf: function () {
101 throwError();
104 if (callCount == 9998)
105 +o1;
106 if (callCount == 9999)
107 +o2;
109 nonInlineable : function () {
110 if (0) return [arguments, function(){}];
111 ++callCount;
112 if (callCount == 1) {
113 this.getter1;
114 } else if (callCount == 2) {
115 this.getter2;
116 } else {
117 this.getter3;
120 inlineable : function () {
121 this.nonInlineable();
125 function yetAnotherInlinedCall(o) {
126 o.inlineable();
129 function makeInlinableCall(o) {
130 for (var i = 0; i < 10000; i++) {
131 new yetAnotherInlinedCall(o);
134 for (var k = 0; k < 4; k++) {
135 try {
136 function g() {
137 var j = 0;
138 for (var i = 0; i < 1000; i++) {
139 j++;
140 makeInlinableCall(object);
143 [1].map(g);
144 } catch (e) {
145 printStack(e.stack);
149 function h() {
150 if (callCount++ == 1000)
151 throw {};
152 if (callCount > 1000) {
153 [].map.apply(undefined, throwError);
157 function mapTest(a) {
158 a.map(h);
161 function mapTestDriver() {
162 var a = [1,2,3];
163 for (var i = 0; i < 2000; i++)
164 mapTest(a);
167 try {
168 callCount = 0;
169 mapTestDriver()
170 } catch(e) {
171 printStack(e.stack);
174 try {
175 mapTestDriver()
176 } catch(e) {
177 printStack(e.stack);
180 var dfgFunctionShouldThrow = false;
181 function dfgFunction() {
182 if (dfgFunctionShouldThrow) {
183 dfgFunctionShouldThrow = false;
184 throwError();
188 for (var k = 0; k < 1000; k++)
189 dfgFunction();
191 try {
192 dfgFunctionShouldThrow = true;
193 [1,2,3,4].map(dfgFunction);
194 } catch (e) {
195 printStack(e.stack);
198 try {
199 var o = { };
200 o.__defineGetter__("g", dfgFunction);
201 function f(o) {
202 o.g;
204 for (var k = 0; k < 1000; k++)
205 f(o);
207 dfgFunctionShouldThrow = true;
208 f(o);
210 } catch (e) {
211 printStack(e.stack);
214 var someValue = null;
216 function callNonCallable() {
217 someValue();
220 for (var i = 0; i < 100; i++) {
221 try {
222 callNonCallable();
223 } catch (e) {
227 successfullyParsed = true;