File tree Expand file tree Collapse file tree 3 files changed +58
-5
lines changed
Expand file tree Collapse file tree 3 files changed +58
-5
lines changed Original file line number Diff line number Diff line change @@ -155,10 +155,7 @@ Raven.prototype = {
155155 var self = this ;
156156 if ( this . isSetup ( ) && ! this . _isRavenInstalled ) {
157157 TraceKit . report . subscribe ( function ( ) {
158- // maintain 'self'
159- if ( ! self . _ignoreOnError ) {
160- self . _handleStackInfo . apply ( self , arguments ) ;
161- }
158+ self . _handleOnErrorStackInfo . apply ( self , arguments ) ;
162159 } ) ;
163160 this . _wrapBuiltIns ( ) ;
164161
@@ -661,6 +658,13 @@ Raven.prototype = {
661658 return dsn ;
662659 } ,
663660
661+ _handleOnErrorStackInfo : function ( stackInfo , options ) {
662+ // if we are intentionally ignoring errors via onerror, bail out
663+ if ( ! this . _ignoreOnError ) {
664+ this . _handleStackInfo . apply ( this , arguments ) ;
665+ }
666+ } ,
667+
664668 _handleStackInfo : function ( stackInfo , options ) {
665669 var self = this ;
666670 var frames = [ ] ;
Original file line number Diff line number Diff line change @@ -68,7 +68,26 @@ describe('integration', function () {
6868 ) ;
6969 } ) ;
7070 } ) ;
71- describe ( 'native' , function ( ) {
71+
72+ describe ( 'window.onerror' , function ( ) {
73+ it ( 'should catch syntax errors' , function ( done ) {
74+ var iframe = this . iframe ;
75+
76+ iframeExecute ( iframe , done ,
77+ function ( ) {
78+ setTimeout ( done ) ;
79+ eval ( 'foo{};' ) ;
80+ } ,
81+ function ( ) {
82+ var ravenData = iframe . contentWindow . ravenData ;
83+ assert . isTrue ( / S y n t a x E r r o r / . test ( ravenData . message ) ) ; // full message differs per-browser
84+ assert . equal ( ravenData . exception . values [ 0 ] . stacktrace . frames . length , 1 ) ; // just one frame
85+ }
86+ ) ;
87+ } ) ;
88+ } ) ;
89+
90+ describe ( 'wrapped built-ins' , function ( ) {
7291 it ( 'should capture exceptions from event listeners' , function ( done ) {
7392 var iframe = this . iframe ;
7493
Original file line number Diff line number Diff line change @@ -1264,6 +1264,36 @@ describe('globals', function() {
12641264 } ) ;
12651265 } ) ;
12661266
1267+ describe ( 'handleOnErrorStackInfo' , function ( ) {
1268+ it ( 'should call handleStackInfo if ignoreOnError is falsy' , function ( ) {
1269+ var frame = { url : 'http://example.com' } ;
1270+ this . sinon . stub ( Raven , '_handleStackInfo' ) ;
1271+
1272+ var stackInfo = {
1273+ name : 'Matt' ,
1274+ message : 'hey' ,
1275+ url : 'http://example.com' ,
1276+ lineno : 10 ,
1277+ stack : [
1278+ frame , frame
1279+ ]
1280+ } ;
1281+
1282+ Raven . _ignoreOnError = 1 ;
1283+ Raven . _handleOnErrorStackInfo ( stackInfo , { foo : 'bar' } ) ;
1284+
1285+ assert . equal ( Raven . _handleStackInfo . callCount , 0 ) ;
1286+
1287+ Raven . _ignoreOnError = 0 ;
1288+ Raven . _handleOnErrorStackInfo ( stackInfo , { foo : 'bar' } ) ;
1289+
1290+ assert . equal ( Raven . _handleStackInfo . callCount , 1 ) ;
1291+ assert . deepEqual ( Raven . _handleStackInfo . lastCall . args , [
1292+ stackInfo , { foo : 'bar' }
1293+ ] ) ;
1294+ } ) ;
1295+ } ) ;
1296+
12671297 describe ( 'handleStackInfo' , function ( ) {
12681298 it ( 'should work as advertised' , function ( ) {
12691299 var frame = { url : 'http://example.com' } ;
You can’t perform that action at this time.
0 commit comments