diff --git a/benchmark/events/ee-listeners.js b/benchmark/events/ee-listeners.js index 08631e95e2165a..9de8d04a175b4b 100644 --- a/benchmark/events/ee-listeners.js +++ b/benchmark/events/ee-listeners.js @@ -14,7 +14,7 @@ function main({ n, listeners, raw }) { for (let k = 0; k < listeners; k += 1) { ee.on('dummy0', () => {}); - ee.on('dummy1', () => {}); + ee.once('dummy1', () => {}); } if (raw === 'true') { diff --git a/lib/events.js b/lib/events.js index 6717363acbff96..92f968a2b54a43 100644 --- a/lib/events.js +++ b/lib/events.js @@ -22,7 +22,6 @@ 'use strict'; const { - Array, Boolean, Error, MathMin, @@ -616,9 +615,11 @@ function arrayClone(arr) { } function unwrapListeners(arr) { - const ret = new Array(arr.length); + const ret = arrayClone(arr); for (let i = 0; i < ret.length; ++i) { - ret[i] = arr[i].listener || arr[i]; + const orig = ret[i].listener; + if (typeof orig === 'function') + ret[i] = orig; } return ret; }