OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 function a$b$c$d() { return FAIL; } | 77 function a$b$c$d() { return FAIL; } |
78 function Wookie() { } | 78 function Wookie() { } |
79 Wookie.prototype.d = a$b$c$d; | 79 Wookie.prototype.d = a$b$c$d; |
80 (new Wookie).d(); | 80 (new Wookie).d(); |
81 } | 81 } |
82 | 82 |
83 function testAnonymousMethod() { | 83 function testAnonymousMethod() { |
84 (function () { FAIL }).call([1, 2, 3]); | 84 (function () { FAIL }).call([1, 2, 3]); |
85 } | 85 } |
86 | 86 |
| 87 function CustomError(message, stripPoint) { |
| 88 this.message = message; |
| 89 Error.captureStackTrace(this, stripPoint); |
| 90 } |
| 91 |
| 92 CustomError.prototype.toString = function () { |
| 93 return "CustomError: " + this.message; |
| 94 }; |
| 95 |
| 96 function testDefaultCustomError() { |
| 97 throw new CustomError("hep-hey", undefined); |
| 98 } |
| 99 |
| 100 function testStrippedCustomError() { |
| 101 throw new CustomError("hep-hey", CustomError); |
| 102 } |
| 103 |
87 // Utility function for testing that the expected strings occur | 104 // Utility function for testing that the expected strings occur |
88 // in the stack trace produced when running the given function. | 105 // in the stack trace produced when running the given function. |
89 function testTrace(fun, expected) { | 106 function testTrace(fun, expected, unexpected) { |
90 var threw = false; | 107 var threw = false; |
91 try { | 108 try { |
92 fun(); | 109 fun(); |
93 } catch (e) { | 110 } catch (e) { |
94 for (var i = 0; i < expected.length; i++) { | 111 for (var i = 0; i < expected.length; i++) { |
95 assertTrue(e.stack.indexOf(expected[i]) != -1); | 112 assertTrue(e.stack.indexOf(expected[i]) != -1); |
96 } | 113 } |
| 114 if (unexpected) { |
| 115 for (var i = 0; i < unexpected.length; i++) { |
| 116 assertEquals(e.stack.indexOf(unexpected[i]), -1); |
| 117 } |
| 118 } |
97 threw = true; | 119 threw = true; |
98 } | 120 } |
99 assertTrue(threw); | 121 assertTrue(threw); |
100 } | 122 } |
101 | 123 |
102 // Test that the error constructor is not shown in the trace | 124 // Test that the error constructor is not shown in the trace |
103 function testCallerCensorship() { | 125 function testCallerCensorship() { |
104 var threw = false; | 126 var threw = false; |
105 try { | 127 try { |
106 FAIL; | 128 FAIL; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 testTrace(testArrayNative, ["Array.map (native)"]); | 180 testTrace(testArrayNative, ["Array.map (native)"]); |
159 testTrace(testNested, ["at one", "at two", "at three"]); | 181 testTrace(testNested, ["at one", "at two", "at three"]); |
160 testTrace(testMethodNameInference, ["at Foo.bar"]); | 182 testTrace(testMethodNameInference, ["at Foo.bar"]); |
161 testTrace(testImplicitConversion, ["at Nirk.valueOf"]); | 183 testTrace(testImplicitConversion, ["at Nirk.valueOf"]); |
162 testTrace(testEval, ["at Doo (eval at testEval"]); | 184 testTrace(testEval, ["at Doo (eval at testEval"]); |
163 testTrace(testNestedEval, ["eval at Inner (eval at Outer"]); | 185 testTrace(testNestedEval, ["eval at Inner (eval at Outer"]); |
164 testTrace(testValue, ["at Number.causeError"]); | 186 testTrace(testValue, ["at Number.causeError"]); |
165 testTrace(testConstructor, ["new Plonk"]); | 187 testTrace(testConstructor, ["new Plonk"]); |
166 testTrace(testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); | 188 testTrace(testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); |
167 testTrace(testAnonymousMethod, ["Array.<anonymous>"]); | 189 testTrace(testAnonymousMethod, ["Array.<anonymous>"]); |
| 190 testTrace(testDefaultCustomError, ["hep-hey", "new CustomError"], |
| 191 ["collectStackTrace"]); |
| 192 testTrace(testStrippedCustomError, ["hep-hey"], ["new CustomError", |
| 193 "collectStackTrace"]); |
168 | 194 |
169 testCallerCensorship(); | 195 testCallerCensorship(); |
170 testUnintendedCallerCensorship(); | 196 testUnintendedCallerCensorship(); |
171 testErrorsDuringFormatting(); | 197 testErrorsDuringFormatting(); |
OLD | NEW |