mirror of https://github.com/lukechilds/node.git
Browse Source
This commit safely allows event names that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Fixes: https://github.com/nodejs/node/issues/728 PR-URL: https://github.com/nodejs/node/pull/6092 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>process-exit-stdio-flushing
Brian White
9 years ago
5 changed files with 52 additions and 21 deletions
@ -1,12 +0,0 @@ |
|||
'use strict'; |
|||
// Refs: https://github.com/nodejs/node/issues/728
|
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const ee = new EventEmitter(); |
|||
|
|||
ee.on('__proto__', common.mustCall((data) => { |
|||
assert.strictEqual(data, 42); |
|||
})); |
|||
|
|||
ee.emit('__proto__', 42); |
@ -0,0 +1,36 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
const EventEmitter = require('events'); |
|||
const assert = require('assert'); |
|||
|
|||
const ee = new EventEmitter(); |
|||
const handler = () => {}; |
|||
|
|||
assert.strictEqual(ee._events.hasOwnProperty, undefined); |
|||
assert.strictEqual(ee._events.toString, undefined); |
|||
|
|||
ee.on('__proto__', handler); |
|||
ee.on('__defineGetter__', handler); |
|||
ee.on('toString', handler); |
|||
|
|||
assert.deepStrictEqual(ee.eventNames(), [ |
|||
'__proto__', |
|||
'__defineGetter__', |
|||
'toString' |
|||
]); |
|||
|
|||
assert.deepStrictEqual(ee.listeners('__proto__'), [handler]); |
|||
assert.deepStrictEqual(ee.listeners('__defineGetter__'), [handler]); |
|||
assert.deepStrictEqual(ee.listeners('toString'), [handler]); |
|||
|
|||
ee.on('__proto__', common.mustCall(function(val) { |
|||
assert.strictEqual(val, 1); |
|||
})); |
|||
ee.emit('__proto__', 1); |
|||
|
|||
process.on('__proto__', common.mustCall(function(val) { |
|||
assert.strictEqual(val, 1); |
|||
})); |
|||
process.emit('__proto__', 1); |
|||
|
Loading…
Reference in new issue