Permalink
Browse files

Use Error.captureStackTrace where available in goog.debug.Error

MOE import of r1696 by Dan Pupius

Revision created by MOE tool push_codebase.

R=chrishenry
DELTA=20  (14 added, 0 deleted, 6 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=4447


git-svn-id: http://closure-library.googlecode.com/svn/trunk@1698 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
nicksantos@google.com
nicksantos@google.com committed Mar 30, 2012
1 parent d3dd0dc commit 1a163cc4f09c5133cc12e9ff2154332de7bb998b
Showing with 20 additions and 6 deletions.
  1. +2 −0 AUTHORS
  2. +5 −1 closure/goog/debug/error.js
  3. +13 −5 closure/goog/debug/error_test.html
View
@@ -13,3 +13,5 @@ Ilia Mirkin <ibmirkin@gmail.com>
Ivan Kozik <ivan.kozik@gmail.com>
Rich Dougherty <rich@rd.gen.nz>
Chad Killingsworth <chadkillingsworth@missouristate.edu>
+Dan Pupius <dan.pupius@gmail.com>
+
@@ -34,7 +34,11 @@ goog.provide('goog.debug.Error');
goog.debug.Error = function(opt_msg) {
// Ensure there is a stack trace.
- this.stack = new Error().stack || '';
+ if (Error.captureStackTrace) {
+ Error.captureStackTrace(this, goog.debug.Error);
+ } else {
+ this.stack = new Error().stack || '';
+ }
if (opt_msg) {
this.message = String(opt_msg);
@@ -62,11 +62,19 @@
stack.splice(0, 0, 'Error');
}
- assertContains('1st line of stack should have "Error"', 'Error', stack[0]);
- // 2nd line is slightly different in firefox/chrome
- assertContains('3rd line of stack should have "zzzzz"', 'zzzzz', stack[2]);
- assertContains('4th line of stack should have "yyyyy"', 'yyyyy', stack[3]);
- assertContains('5th line of stack should have "xxxxx"', 'xxxxx', stack[4]);
+ if (Error.captureStackTrace) {
+ // captureStackTrace removes extra junk.
+ assertContains('1st line of stack should have "Error"', 'Error', stack[0]);
+ assertContains('2nd line of stack should have "zzzzz"', 'zzzzz', stack[1]);
+ assertContains('3rd line of stack should have "yyyyy"', 'yyyyy', stack[2]);
+ assertContains('4th line of stack should have "xxxxx"', 'xxxxx', stack[3]);
+ } else {
+ assertContains('1st line of stack should have "Error"', 'Error', stack[0]);
+ // 2nd line is slightly different in firefox/chrome
+ assertContains('3rd line of stack should have "zzzzz"', 'zzzzz', stack[2]);
+ assertContains('4th line of stack should have "yyyyy"', 'yyyyy', stack[3]);
+ assertContains('5th line of stack should have "xxxxx"', 'xxxxx', stack[4]);
+ }
} catch (e) {
expectedFailures.handleException(e);
}

0 comments on commit 1a163cc

Please sign in to comment.