| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6eb0b6 commit b484732
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -623,7 +623,10 @@ function unwrapListeners(arr) { | |||
| 623 | 623 | ||
| 624 | 624 | function once(emitter, name) { | |
| 625 | 625 | return new Promise((resolve, reject) => { | |
| 626 | - if (typeof emitter.addEventListener === 'function') { | ||
| 626 | + if ( | ||
| 627 | + typeof emitter.addEventListener === 'function' && | ||
| 628 | + typeof emitter.on !== 'function' | ||
| 629 | + ) { | ||
| 627 | 630 | // EventTarget does not have `error` event semantics like Node | |
| 628 | 631 | // EventEmitters, we do not listen to `error` events here. | |
| 629 | 632 | emitter.addEventListener( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,6 +166,27 @@ async function onceWithEventTargetError() { | |||
| 166 | 166 | strictEqual(Reflect.has(et.events, 'error'), false); | |
| 167 | 167 | } | |
| 168 | 168 | ||
| 169 | + async function assumesEventEmitterIfOnIsAFunction() { | ||
| 170 | + const ee = new EventEmitter(); | ||
| 171 | + ee.addEventListener = () => {}; | ||
| 172 | + | ||
| 173 | + const expected = new Error('kaboom'); | ||
| 174 | + let err; | ||
| 175 | + process.nextTick(() => { | ||
| 176 | + ee.emit('error', expected); | ||
| 177 | + }); | ||
| 178 | + | ||
| 179 | + try { | ||
| 180 | + await once(ee, 'myevent'); | ||
| 181 | + } catch (_e) { | ||
| 182 | + err = _e; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + strictEqual(err, expected); | ||
| 186 | + strictEqual(ee.listenerCount('error'), 0); | ||
| 187 | + strictEqual(ee.listenerCount('myevent'), 0); | ||
| 188 | + } | ||
| 189 | + | ||
| 169 | 190 | Promise.all([ | |
| 170 | 191 | onceAnEvent(), | |
| 171 | 192 | onceAnEventWithTwoArgs(), | |
@@ -175,4 +196,5 @@ Promise.all([ | |||
| 175 | 196 | onceWithEventTarget(), | |
| 176 | 197 | onceWithEventTargetTwoArgs(), | |
| 177 | 198 | onceWithEventTargetError(), | |
| 199 | + assumesEventEmitterIfOnIsAFunction(), | ||
| 178 | 200 | ]).then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments