[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var common = require('./common');
|
---|
| 4 | var EventEmitter = require('../');
|
---|
| 5 | var assert = require('assert');
|
---|
| 6 |
|
---|
| 7 | var ee = new EventEmitter();
|
---|
| 8 | var handler = function() {};
|
---|
| 9 |
|
---|
| 10 | assert.strictEqual(ee.eventNames().length, 0);
|
---|
| 11 |
|
---|
| 12 | assert.strictEqual(ee._events.hasOwnProperty, undefined);
|
---|
| 13 | assert.strictEqual(ee._events.toString, undefined);
|
---|
| 14 |
|
---|
| 15 | ee.on('__defineGetter__', handler);
|
---|
| 16 | ee.on('toString', handler);
|
---|
| 17 | ee.on('__proto__', handler);
|
---|
| 18 |
|
---|
| 19 | assert.strictEqual(ee.eventNames()[0], '__defineGetter__');
|
---|
| 20 | assert.strictEqual(ee.eventNames()[1], 'toString');
|
---|
| 21 |
|
---|
| 22 | assert.strictEqual(ee.listeners('__defineGetter__').length, 1);
|
---|
| 23 | assert.strictEqual(ee.listeners('__defineGetter__')[0], handler);
|
---|
| 24 | assert.strictEqual(ee.listeners('toString').length, 1);
|
---|
| 25 | assert.strictEqual(ee.listeners('toString')[0], handler);
|
---|
| 26 |
|
---|
| 27 | // Only run __proto__ tests if that property can actually be set
|
---|
| 28 | if ({ __proto__: 'ok' }.__proto__ === 'ok') {
|
---|
| 29 | assert.strictEqual(ee.eventNames().length, 3);
|
---|
| 30 | assert.strictEqual(ee.eventNames()[2], '__proto__');
|
---|
| 31 | assert.strictEqual(ee.listeners('__proto__').length, 1);
|
---|
| 32 | assert.strictEqual(ee.listeners('__proto__')[0], handler);
|
---|
| 33 |
|
---|
| 34 | ee.on('__proto__', common.mustCall(function(val) {
|
---|
| 35 | assert.strictEqual(val, 1);
|
---|
| 36 | }));
|
---|
| 37 | ee.emit('__proto__', 1);
|
---|
| 38 |
|
---|
| 39 | process.on('__proto__', common.mustCall(function(val) {
|
---|
| 40 | assert.strictEqual(val, 1);
|
---|
| 41 | }));
|
---|
| 42 | process.emit('__proto__', 1);
|
---|
| 43 | } else {
|
---|
| 44 | console.log('# skipped __proto__')
|
---|
| 45 | }
|
---|