Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
defer breakpoint callback
Browse files Browse the repository at this point in the history
Make sure the breakpoint hit callback isn't called back from the debug
listener, which swallows user exceptions thrown from the callback.
  • Loading branch information
ofrobots committed Apr 21, 2016
1 parent 27692c1 commit 0dbf25c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/v8debugapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ module.exports.create = function(logger_, config_, fileStats_) {
var listener = onBreakpointHit.bind(
null, breakpoint, function(err) {
delete listeners[num];
callback(err);
// This method is called from the debug event listener, which
// swallows all exception. We defer the callback to make sure the
// user errors aren't silenced.
setImmediate(function() {
callback(err);
});
});

listeners[num] = listener;
Expand Down
27 changes: 27 additions & 0 deletions test/test-v8debugapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,33 @@ describe('v8debugapi', function() {
process.nextTick(function() {foo();});
});
});

it('should not silence errors thrown in the wait callback', function(done) {
var message = 'This exception should not be silenced';
// Remove the mocha listener.
var listeners = process.listeners('uncaughtException');
assert.equal(listeners.length, 1);
var originalListener = listeners[0];
process.removeListener('uncaughtException', originalListener);
process.once('uncaughtException', function(err) {
assert.ok(err);
assert.equal(err.message, message);
// Restore the mocha listener.
process.on('uncaughtException', originalListener);
done();
});

// clone a clean breakpointInFoo
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
api.set(bp, function(err) {
assert.ifError(err);
api.wait(bp, function(err) {
api.clear(bp);
throw new Error(message);
});
process.nextTick(function() {foo(1);});
});
});
});

it('should be possible to set deferred breakpoints');
Expand Down

0 comments on commit 0dbf25c

Please sign in to comment.