11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst EventEmitter = require('events'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst myEE = new EventEmitter(); 81cb0ef41Sopenharmony_cilet m = 0; 91cb0ef41Sopenharmony_ci// This one comes last. 101cb0ef41Sopenharmony_cimyEE.on('foo', common.mustCall(() => assert.strictEqual(m, 2))); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// This one comes second. 131cb0ef41Sopenharmony_cimyEE.prependListener('foo', common.mustCall(() => assert.strictEqual(m++, 1))); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// This one comes first. 161cb0ef41Sopenharmony_cimyEE.prependOnceListener('foo', 171cb0ef41Sopenharmony_ci common.mustCall(() => assert.strictEqual(m++, 0))); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_cimyEE.emit('foo'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci// Test fallback if prependListener is undefined. 221cb0ef41Sopenharmony_ciconst stream = require('stream'); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_cidelete EventEmitter.prototype.prependListener; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cifunction Writable() { 271cb0ef41Sopenharmony_ci this.writable = true; 281cb0ef41Sopenharmony_ci stream.Stream.call(this); 291cb0ef41Sopenharmony_ci} 301cb0ef41Sopenharmony_ciObject.setPrototypeOf(Writable.prototype, stream.Stream.prototype); 311cb0ef41Sopenharmony_ciObject.setPrototypeOf(Writable, stream.Stream); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_cifunction Readable() { 341cb0ef41Sopenharmony_ci this.readable = true; 351cb0ef41Sopenharmony_ci stream.Stream.call(this); 361cb0ef41Sopenharmony_ci} 371cb0ef41Sopenharmony_ciObject.setPrototypeOf(Readable.prototype, stream.Stream.prototype); 381cb0ef41Sopenharmony_ciObject.setPrototypeOf(Readable, stream.Stream); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciconst w = new Writable(); 411cb0ef41Sopenharmony_ciconst r = new Readable(); 421cb0ef41Sopenharmony_cir.pipe(w); 43