You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

special-event-names.js 1.4KB

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