@@ -9,7 +9,7 @@ function iframeExecute(iframe, done, execute, assertCallback) {
99 }
1010 }
1111 // use setTimeout so stack trace doesn't go all the way back to mocha test runner
12- iframe . contentWindow . eval ( 'setTimeout (' + execute . toString ( ) + ');' ) ;
12+ iframe . contentWindow . eval ( 'origSetTimeout (' + execute . toString ( ) + ');' ) ;
1313}
1414
1515function createIframe ( done ) {
@@ -136,7 +136,7 @@ describe('integration', function () {
136136 } ,
137137 function ( ) {
138138 var ravenData = iframe . contentWindow . ravenData ;
139- assert . equal ( ravenData . exception . values [ 0 ] . stacktrace . frames . length , eventHandlerStackDepth + 2 ) ;
139+ assert . equal ( ravenData . exception . values [ 0 ] . stacktrace . frames . length , eventHandlerStackDepth + 1 ) ;
140140 }
141141 ) ;
142142 } ) ;
@@ -223,5 +223,27 @@ describe('integration', function () {
223223 }
224224 ) ;
225225 } ) ;
226+
227+ it ( 'should capture exceptions from XMLHttpRequest event handlers (e.g. onreadystatechange)' , function ( done ) {
228+ var iframe = this . iframe ;
229+
230+ iframeExecute ( iframe , done ,
231+ function ( ) {
232+ setTimeout ( done ) ;
233+ var xhr = new XMLHttpRequest ( ) ;
234+ xhr . onreadystatechange = function ( ) {
235+ foo ( ) ;
236+ }
237+ xhr . open ( 'GET' , 'example.json' ) ;
238+ xhr . send ( ) ;
239+ } ,
240+ function ( ) {
241+ var ravenData = iframe . contentWindow . ravenData ;
242+ console . log ( ravenData ) ;
243+ // # of frames alter significantly between chrome/firefox & safari
244+ assert . isTrue ( ravenData . exception . values [ 0 ] . stacktrace . frames . length >= 4 ) ;
245+ }
246+ ) ;
247+ } ) ;
226248 } ) ;
227249} ) ;
0 commit comments