From a38f9cf48f5d9d942f7fdadc094680a148461d7f Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Wed, 24 Jun 2015 06:20:04 +0900 Subject: [PATCH 1/2] Added new test for prototype bleeding --- .../test-event-emitter-prototype-bleeding.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/parallel/test-event-emitter-prototype-bleeding.js diff --git a/test/parallel/test-event-emitter-prototype-bleeding.js b/test/parallel/test-event-emitter-prototype-bleeding.js new file mode 100644 index 00000000000000..01d64233cfa494 --- /dev/null +++ b/test/parallel/test-event-emitter-prototype-bleeding.js @@ -0,0 +1,19 @@ +'use strict'; +var util = require('util'); +var EventEmitter = require('events').EventEmitter; + +var TestClass = function () {}; +TestClass.prototype = new EventEmitter; + +function listener_n1() { + // This one is okay to be called! +} +function listener_n2() { + throw new Error("This one should not be called!") +} + +var ok = new TestClass(); +var broken = new TestClass(); +broken.on('end', listener_n2); +ok.on('end', listener_n1); +ok.emit('end'); \ No newline at end of file From 21706a7aa26c786a5caea202d059cf38ad3858c0 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Wed, 24 Jun 2015 12:03:09 +0900 Subject: [PATCH 2/2] Correcting style to be lint-conform. --- .../test-event-emitter-prototype-bleeding.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-event-emitter-prototype-bleeding.js b/test/parallel/test-event-emitter-prototype-bleeding.js index 01d64233cfa494..892e9e8d18a36e 100644 --- a/test/parallel/test-event-emitter-prototype-bleeding.js +++ b/test/parallel/test-event-emitter-prototype-bleeding.js @@ -1,19 +1,23 @@ 'use strict'; var util = require('util'); +var assert = require('assert'); var EventEmitter = require('events').EventEmitter; +var called = false; -var TestClass = function () {}; -TestClass.prototype = new EventEmitter; +function TestClass() { +} +TestClass.prototype = new EventEmitter(); -function listener_n1() { - // This one is okay to be called! +function okListener() { + called = true; } -function listener_n2() { - throw new Error("This one should not be called!") +function brokenListener() { + throw new Error('This one should not be called!'); } var ok = new TestClass(); var broken = new TestClass(); -broken.on('end', listener_n2); -ok.on('end', listener_n1); -ok.emit('end'); \ No newline at end of file +broken.on('end', okListener); +ok.on('end', brokenListener); +ok.emit('end'); +assert.ok(called, 'The ok listener should have been called');