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 380 matching lines...) Loading... | |
391 assertTrue(desc.writable); | 391 assertTrue(desc.writable); |
392 | 392 |
393 // Check that exceptions thrown within prepareStackTrace throws an exception. | 393 // Check that exceptions thrown within prepareStackTrace throws an exception. |
394 Error.prepareStackTrace = function(e, frames) { throw 42; } | 394 Error.prepareStackTrace = function(e, frames) { throw 42; } |
395 | 395 |
396 var x = {} | 396 var x = {} |
397 assertThrows(() => Error.captureStackTrace(x)); | 397 assertThrows(() => Error.captureStackTrace(x)); |
398 | 398 |
399 // Check that we don't crash when CaptureSimpleStackTrace returns undefined. | 399 // Check that we don't crash when CaptureSimpleStackTrace returns undefined. |
400 var o = {}; | 400 var o = {}; |
401 var oldStackTraceLimit = Error.stackTraceLimit; | |
401 Error.stackTraceLimit = "not a number"; | 402 Error.stackTraceLimit = "not a number"; |
402 Error.captureStackTrace(o); | 403 Error.captureStackTrace(o); |
404 Error.stackTraceLimit = oldStackTraceLimit; | |
jgruber
2016/08/02 08:21:48
Note: This fixes a few followup tests.
| |
403 | 405 |
404 // Check that we don't crash when a callsite's function's script is empty. | 406 // Check that we don't crash when a callsite's function's script is empty. |
405 Error.prepareStackTrace = function(e, frames) { | 407 Error.prepareStackTrace = function(e, frames) { |
406 assertEquals(undefined, frames[0].getEvalOrigin()); | 408 assertEquals(undefined, frames[0].getEvalOrigin()); |
407 } | 409 } |
408 try { | 410 try { |
409 DataView(); | 411 DataView(); |
410 assertUnreachable(); | 412 assertUnreachable(); |
411 } catch (e) { | 413 } catch (e) { |
412 assertEquals(undefined, e.stack); | 414 assertEquals(undefined, e.stack); |
413 } | 415 } |
414 | 416 |
415 // Check that a tight recursion in prepareStackTrace fails gracefully, i.e. | 417 // Check that a tight recursion in prepareStackTrace throws when accessing |
416 // a range error is thrown and printed (but without showing the actual stack). | 418 // stack. Trying again without a custom formatting function formats correctly. |
417 | 419 var err = new Error("abc"); |
jgruber
2016/08/02 08:21:48
Note: And the prepareStackTrace recursion test.
| |
418 Error.prepareStackTrace = () => Error.prepareStackTrace(); | 420 Error.prepareStackTrace = () => Error.prepareStackTrace(); |
419 try { | 421 try { |
420 new Error().stack; | 422 err.stack; |
423 assertUnreachable(); | |
421 } catch (e) { | 424 } catch (e) { |
422 assertTrue( | 425 err = e; |
423 e.stack.indexOf("RangeError: Maximum call stack size exceeded") != -1); | |
424 assertTrue(e.stack.indexOf("prepareStackTrace") == -1); | |
425 } | 426 } |
427 | |
428 Error.prepareStackTrace = undefined; | |
429 assertTrue( | |
430 err.stack.indexOf("RangeError: Maximum call stack size exceeded") != -1); | |
431 assertTrue(err.stack.indexOf("prepareStackTrace") != -1); | |
432 | |
433 // Check that the callsite constructor throws. | |
434 | |
435 Error.prepareStackTrace = (e,s) => s; | |
436 var constructor = new Error().stack[0].constructor; | |
437 | |
438 assertThrows(() => constructor.call()); | |
439 assertThrows(() => constructor.call( | |
440 null, {}, () => undefined, {valueOf() { return 0 }}, false)); | |
OLD | NEW |