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

Commit 0dbf25c

Browse files
committed
defer breakpoint callback
Make sure the breakpoint hit callback isn't called back from the debug listener, which swallows user exceptions thrown from the callback.
1 parent 27692c1 commit 0dbf25c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/v8debugapi.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ module.exports.create = function(logger_, config_, fileStats_) {
196196
var listener = onBreakpointHit.bind(
197197
null, breakpoint, function(err) {
198198
delete listeners[num];
199-
callback(err);
199+
// This method is called from the debug event listener, which
200+
// swallows all exception. We defer the callback to make sure the
201+
// user errors aren't silenced.
202+
setImmediate(function() {
203+
callback(err);
204+
});
200205
});
201206

202207
listeners[num] = listener;

test/test-v8debugapi.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,33 @@ describe('v8debugapi', function() {
700700
process.nextTick(function() {foo();});
701701
});
702702
});
703+
704+
it('should not silence errors thrown in the wait callback', function(done) {
705+
var message = 'This exception should not be silenced';
706+
// Remove the mocha listener.
707+
var listeners = process.listeners('uncaughtException');
708+
assert.equal(listeners.length, 1);
709+
var originalListener = listeners[0];
710+
process.removeListener('uncaughtException', originalListener);
711+
process.once('uncaughtException', function(err) {
712+
assert.ok(err);
713+
assert.equal(err.message, message);
714+
// Restore the mocha listener.
715+
process.on('uncaughtException', originalListener);
716+
done();
717+
});
718+
719+
// clone a clean breakpointInFoo
720+
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
721+
api.set(bp, function(err) {
722+
assert.ifError(err);
723+
api.wait(bp, function(err) {
724+
api.clear(bp);
725+
throw new Error(message);
726+
});
727+
process.nextTick(function() {foo(1);});
728+
});
729+
});
703730
});
704731

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

0 commit comments

Comments
 (0)