From dca103877f290b1f731fe04498f79e487e249aad Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Tue, 9 Feb 2016 03:33:19 +0530 Subject: [PATCH] debugger: assert test before accessing this.binding PR-URL: https://github.com/nodejs/node/pull/5145 Reviewed-By: Myles Borins Reviewed-By: Fedor Indutny Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Rich Trott Reviewed-By: James M Snell --- lib/_debug_agent.js | 2 +- test/parallel/test-debug-agent.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-debug-agent.js diff --git a/lib/_debug_agent.js b/lib/_debug_agent.js index 63c5035789..152a7c65a6 100644 --- a/lib/_debug_agent.js +++ b/lib/_debug_agent.js @@ -48,6 +48,7 @@ function Agent() { this.first = true; this.binding = process._debugAPI; + assert(this.binding, 'Debugger agent running without bindings!'); var self = this; this.binding.onmessage = function(msg) { @@ -57,7 +58,6 @@ function Agent() { }; this.clients = []; - assert(this.binding, 'Debugger agent running without bindings!'); } util.inherits(Agent, net.Server); diff --git a/test/parallel/test-debug-agent.js b/test/parallel/test-debug-agent.js new file mode 100644 index 0000000000..0bb5d7f9be --- /dev/null +++ b/test/parallel/test-debug-agent.js @@ -0,0 +1,6 @@ +'use strict'; +require('../common'); +const assert = require('assert'); + +assert.throws(() => { require('_debug_agent').start(); }, + assert.AssertionError);