Permalink
Browse files

fix uncaught error support for the browser

  • Loading branch information...
1 parent d40df7a commit eb58761bb3346d2597e8365e60273417127b72c4 @tj tj committed Nov 30, 2012
Showing with 18 additions and 10 deletions.
  1. +5 −8 mocha.js
  2. +3 −1 support/tail.js
  3. +10 −1 test/browser/large.js
View
@@ -4215,15 +4215,10 @@ Runner.prototype.run = function(fn){
debug('start');
- // uncaught callback
- function uncaught(err, url, line) {
- self.uncaught(new Error(err + ' (' + url + ':' + line + ')'));
- }
-
// callback
this.on('end', function(){
debug('end');
- process.removeListener('uncaughtException', uncaught);
+ process.removeListener('uncaughtException', self.uncaught.bind(self));
fn(self.failures);
});
@@ -4235,7 +4230,7 @@ Runner.prototype.run = function(fn){
});
// uncaught exception
- process.on('uncaughtException', uncaught);
+ process.on('uncaughtException', this.uncaught.bind(this));
return this;
};
@@ -4946,7 +4941,9 @@ process.removeListener = function(e){
process.on = function(e, fn){
if ('uncaughtException' == e) {
- window.onerror = fn;
+ window.onerror = function(err, url, line){
+ fn(new Error(err + ' (' + url + ':' + line + ')'));
+ };
}
};
View
@@ -56,7 +56,9 @@ process.removeListener = function(e){
process.on = function(e, fn){
if ('uncaughtException' == e) {
- window.onerror = fn;
+ window.onerror = function(err, url, line){
+ fn(new Error(err + ' (' + url + ':' + line + ')'));
+ };
}
};
View
@@ -20,4 +20,13 @@ while (n--) {
})
})
})
-}
+}
+
+describe('something', function(){
+ it('should provide a useful error', function(done){
+ setTimeout(function(){
+ throw new Error('boom');
+ done();
+ }, 1);
+ })
+})

0 comments on commit eb58761

Please sign in to comment.