• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const EventEmitter = require('events');
5const assert = require('assert');
6
7const myEE = new EventEmitter();
8let m = 0;
9// This one comes last.
10myEE.on('foo', common.mustCall(() => assert.strictEqual(m, 2)));
11
12// This one comes second.
13myEE.prependListener('foo', common.mustCall(() => assert.strictEqual(m++, 1)));
14
15// This one comes first.
16myEE.prependOnceListener('foo',
17                         common.mustCall(() => assert.strictEqual(m++, 0)));
18
19myEE.emit('foo');
20
21// Test fallback if prependListener is undefined.
22const stream = require('stream');
23
24delete EventEmitter.prototype.prependListener;
25
26function Writable() {
27  this.writable = true;
28  stream.Stream.call(this);
29}
30Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
31Object.setPrototypeOf(Writable, stream.Stream);
32
33function Readable() {
34  this.readable = true;
35  stream.Stream.call(this);
36}
37Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
38Object.setPrototypeOf(Readable, stream.Stream);
39
40const w = new Writable();
41const r = new Readable();
42r.pipe(w);
43