-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events: don't inherit from Object.prototype
This commit safely allows event names that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Fixes: #728 PR-URL: #6092 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
5 changed files
with
52 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
@mscdex ... fyi... this is causing a compiler warning when building