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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 n.foo(); | 187 n.foo(); |
188 } catch (e) { | 188 } catch (e) { |
189 threw = true; | 189 threw = true; |
190 assertTrue(e.stack.indexOf('<error>') != -1, | 190 assertTrue(e.stack.indexOf('<error>') != -1, |
191 "ErrorsDuringFormatting didn't contain <error>"); | 191 "ErrorsDuringFormatting didn't contain <error>"); |
192 } | 192 } |
193 assertTrue(threw, "ErrorsDuringFormatting didnt' throw (2)"); | 193 assertTrue(threw, "ErrorsDuringFormatting didnt' throw (2)"); |
194 } | 194 } |
195 | 195 |
196 | 196 |
| 197 // Poisonous object that throws a reference error if attempted converted to |
| 198 // a primitive values. |
| 199 var thrower = { valueOf: function() { FAIL; }, |
| 200 toString: function() { FAIL; } }; |
| 201 |
| 202 // Tests that a native constructor function is included in the |
| 203 // stack trace. |
| 204 function testTraceNativeConstructor(nativeFunc) { |
| 205 var nativeFuncName = nativeFunc.name; |
| 206 try { |
| 207 new nativeFunc(thrower); |
| 208 assertUnreachable(nativeFuncName); |
| 209 } catch (e) { |
| 210 assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); |
| 211 } |
| 212 } |
| 213 |
| 214 // Tests that a native conversion function is included in the |
| 215 // stack trace. |
| 216 function testTraceNativeConversion(nativeFunc) { |
| 217 var nativeFuncName = nativeFunc.name; |
| 218 try { |
| 219 nativeFunc(thrower); |
| 220 assertUnreachable(nativeFuncName); |
| 221 } catch (e) { |
| 222 assertTrue(e.stack.indexOf(nativeFuncName) >= 0, nativeFuncName); |
| 223 } |
| 224 } |
| 225 |
| 226 |
| 227 function testOmittedBuiltin(throwing, omitted) { |
| 228 try { |
| 229 throwing(); |
| 230 assertUnreachable(omitted); |
| 231 } catch (e) { |
| 232 assertTrue(e.stack.indexOf(omitted) < 0, omitted); |
| 233 } |
| 234 } |
| 235 |
| 236 |
197 testTrace("testArrayNative", testArrayNative, ["Array.map (native)"]); | 237 testTrace("testArrayNative", testArrayNative, ["Array.map (native)"]); |
198 testTrace("testNested", testNested, ["at one", "at two", "at three"]); | 238 testTrace("testNested", testNested, ["at one", "at two", "at three"]); |
199 testTrace("testMethodNameInference", testMethodNameInference, ["at Foo.bar"]); | 239 testTrace("testMethodNameInference", testMethodNameInference, ["at Foo.bar"]); |
200 testTrace("testImplicitConversion", testImplicitConversion, ["at Nirk.valueOf"])
; | 240 testTrace("testImplicitConversion", testImplicitConversion, ["at Nirk.valueOf"])
; |
201 testTrace("testEval", testEval, ["at Doo (eval at testEval"]); | 241 testTrace("testEval", testEval, ["at Doo (eval at testEval"]); |
202 testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at Outer"]); | 242 testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at Outer"]); |
203 testTrace("testEvalWithSourceURL", testEvalWithSourceURL, | 243 testTrace("testEvalWithSourceURL", testEvalWithSourceURL, |
204 [ "at Doo (res://name:1:18)" ]); | 244 [ "at Doo (res://name:1:18)" ]); |
205 testTrace("testNestedEvalWithSourceURL", testNestedEvalWithSourceURL, | 245 testTrace("testNestedEvalWithSourceURL", testNestedEvalWithSourceURL, |
206 [" at Inner (res://inner-eval:1:20)", | 246 [" at Inner (res://inner-eval:1:20)", |
207 " at Outer (res://outer-eval:1:37)"]); | 247 " at Outer (res://outer-eval:1:37)"]); |
208 testTrace("testValue", testValue, ["at Number.causeError"]); | 248 testTrace("testValue", testValue, ["at Number.causeError"]); |
209 testTrace("testConstructor", testConstructor, ["new Plonk"]); | 249 testTrace("testConstructor", testConstructor, ["new Plonk"]); |
210 testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); | 250 testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); |
211 testTrace("testAnonymousMethod", testAnonymousMethod, ["Array.<anonymous>"]); | 251 testTrace("testAnonymousMethod", testAnonymousMethod, ["Array.<anonymous>"]); |
212 testTrace("testDefaultCustomError", testDefaultCustomError, | 252 testTrace("testDefaultCustomError", testDefaultCustomError, |
213 ["hep-hey", "new CustomError"], | 253 ["hep-hey", "new CustomError"], |
214 ["collectStackTrace"]); | 254 ["collectStackTrace"]); |
215 testTrace("testStrippedCustomError", testStrippedCustomError, ["hep-hey"], | 255 testTrace("testStrippedCustomError", testStrippedCustomError, ["hep-hey"], |
216 ["new CustomError", "collectStackTrace"]); | 256 ["new CustomError", "collectStackTrace"]); |
217 testCallerCensorship(); | 257 testCallerCensorship(); |
218 testUnintendedCallerCensorship(); | 258 testUnintendedCallerCensorship(); |
219 testErrorsDuringFormatting(); | 259 testErrorsDuringFormatting(); |
| 260 |
| 261 testTraceNativeConversion(String); // Does ToString on argument. |
| 262 testTraceNativeConversion(Number); // Does ToNumber on argument. |
| 263 testTraceNativeConversion(RegExp); // Does ToString on argument. |
| 264 |
| 265 testTraceNativeConstructor(String); // Does ToString on argument. |
| 266 testTraceNativeConstructor(Number); // Does ToNumber on argument. |
| 267 testTraceNativeConstructor(RegExp); // Does ToString on argument. |
| 268 testTraceNativeConstructor(Date); // Does ToNumber on argument. |
| 269 |
| 270 // Omitted because QuickSort has builtins object as receiver, and is non-native |
| 271 // builtin. |
| 272 testOmittedBuiltin(function(){ [thrower, 2].sort(function (a,b) { |
| 273 (b < a) - (a < b); }); |
| 274 }, "QuickSort"); |
| 275 |
| 276 // Omitted because ADD from runtime.js is non-native builtin. |
| 277 testOmittedBuiltin(function(){ thrower + 2; }, "ADD"); |
OLD | NEW |