| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2c0d88e commit 0116ae7
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,7 @@ const { | |||
| 87 | 87 | ||
| 88 | 88 | const kCapture = Symbol('kCapture'); | |
| 89 | 89 | const kErrorMonitor = Symbol('events.errorMonitor'); | |
| 90 | + const kShapeMode = Symbol('shapeMode'); | ||
| 90 | 91 | const kMaxEventTargetListeners = Symbol('events.maxEventTargetListeners'); | |
| 91 | 92 | const kMaxEventTargetListenersWarned = | |
| 92 | 93 | Symbol('events.maxEventTargetListenersWarned'); | |
@@ -344,6 +345,9 @@ EventEmitter.init = function(opts) { | |||
| 344 | 345 | this._events === ObjectGetPrototypeOf(this)._events) { | |
| 345 | 346 | this._events = { __proto__: null }; | |
| 346 | 347 | this._eventsCount = 0; | |
| 348 | + this[kShapeMode] = false; | ||
| 349 | + } else { | ||
| 350 | + this[kShapeMode] = true; | ||
| 347 | 351 | } | |
| 348 | 352 | ||
| 349 | 353 | this._maxListeners = this._maxListeners || undefined; | |
@@ -686,9 +690,13 @@ EventEmitter.prototype.removeListener = | |||
| 686 | 690 | return this; | |
| 687 | 691 | ||
| 688 | 692 | if (list === listener || list.listener === listener) { | |
| 689 | - if (--this._eventsCount === 0) | ||
| 693 | + this._eventsCount -= 1; | ||
| 694 | + | ||
| 695 | + if (this[kShapeMode]) { | ||
| 696 | + events[type] = undefined; | ||
| 697 | + } else if (this._eventsCount === 0) { | ||
| 690 | 698 | this._events = { __proto__: null }; | |
| 691 | - else { | ||
| 699 | + } else { | ||
| 692 | 700 | delete events[type]; | |
| 693 | 701 | if (events.removeListener) | |
| 694 | 702 | this.emit('removeListener', type, list.listener || listener); | |
@@ -750,6 +758,7 @@ EventEmitter.prototype.removeAllListeners = | |||
| 750 | 758 | else | |
| 751 | 759 | delete events[type]; | |
| 752 | 760 | } | |
| 761 | + this[kShapeMode] = false; | ||
| 753 | 762 | return this; | |
| 754 | 763 | } | |
| 755 | 764 | ||
@@ -762,6 +771,7 @@ EventEmitter.prototype.removeAllListeners = | |||
| 762 | 771 | this.removeAllListeners('removeListener'); | |
| 763 | 772 | this._events = { __proto__: null }; | |
| 764 | 773 | this._eventsCount = 0; | |
| 774 | + this[kShapeMode] = false; | ||
| 765 | 775 | return this; | |
| 766 | 776 | } | |
| 767 | 777 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,24 @@ function Duplex(options) { | |||
| 63 | 63 | if (!(this instanceof Duplex)) | |
| 64 | 64 | return new Duplex(options); | |
| 65 | 65 | ||
| 66 | + this._events ??= { | ||
| 67 | + close: undefined, | ||
| 68 | + error: undefined, | ||
| 69 | + prefinish: undefined, | ||
| 70 | + finish: undefined, | ||
| 71 | + drain: undefined, | ||
| 72 | + data: undefined, | ||
| 73 | + end: undefined, | ||
| 74 | + readable: undefined, | ||
| 75 | + // Skip uncommon events... | ||
| 76 | + // pause: undefined, | ||
| 77 | + // resume: undefined, | ||
| 78 | + // pipe: undefined, | ||
| 79 | + // unpipe: undefined, | ||
| 80 | + // [destroyImpl.kConstruct]: undefined, | ||
| 81 | + // [destroyImpl.kDestroy]: undefined, | ||
| 82 | + }; | ||
| 83 | + | ||
| 66 | 84 | this._readableState = new Readable.ReadableState(options, this, true); | |
| 67 | 85 | this._writableState = new Writable.WritableState(options, this, true); | |
| 68 | 86 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,6 +319,21 @@ function Readable(options) { | |||
| 319 | 319 | if (!(this instanceof Readable)) | |
| 320 | 320 | return new Readable(options); | |
| 321 | 321 | ||
| 322 | + this._events ??= { | ||
| 323 | + close: undefined, | ||
| 324 | + error: undefined, | ||
| 325 | + data: undefined, | ||
| 326 | + end: undefined, | ||
| 327 | + readable: undefined, | ||
| 328 | + // Skip uncommon events... | ||
| 329 | + // pause: undefined, | ||
| 330 | + // resume: undefined, | ||
| 331 | + // pipe: undefined, | ||
| 332 | + // unpipe: undefined, | ||
| 333 | + // [destroyImpl.kConstruct]: undefined, | ||
| 334 | + // [destroyImpl.kDestroy]: undefined, | ||
| 335 | + }; | ||
| 336 | + | ||
| 322 | 337 | this._readableState = new ReadableState(options, this, false); | |
| 323 | 338 | ||
| 324 | 339 | if (options) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -385,6 +385,17 @@ function Writable(options) { | |||
| 385 | 385 | if (!(this instanceof Writable)) | |
| 386 | 386 | return new Writable(options); | |
| 387 | 387 | ||
| 388 | + this._events ??= { | ||
| 389 | + close: undefined, | ||
| 390 | + error: undefined, | ||
| 391 | + prefinish: undefined, | ||
| 392 | + finish: undefined, | ||
| 393 | + drain: undefined, | ||
| 394 | + // Skip uncommon events... | ||
| 395 | + // [destroyImpl.kConstruct]: undefined, | ||
| 396 | + // [destroyImpl.kDestroy]: undefined, | ||
| 397 | + }; | ||
| 398 | + | ||
| 388 | 399 | this._writableState = new WritableState(options, this, false); | |
| 389 | 400 | ||
| 390 | 401 | if (options) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ class FakeInput extends EventEmitter { | |||
| 44 | 44 | function isWarned(emitter) { | |
| 45 | 45 | for (const name in emitter) { | |
| 46 | 46 | const listeners = emitter[name]; | |
| 47 | - if (listeners.warned) return true; | ||
| 47 | + if (listeners && listeners.warned) return true; | ||
| 48 | 48 | } | |
| 49 | 49 | return false; | |
| 50 | 50 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ class FakeInput extends EventEmitter { | |||
| 22 | 22 | function isWarned(emitter) { | |
| 23 | 23 | for (const name in emitter) { | |
| 24 | 24 | const listeners = emitter[name]; | |
| 25 | - if (listeners.warned) return true; | ||
| 25 | + if (listeners && listeners.warned) return true; | ||
| 26 | 26 | } | |
| 27 | 27 | return false; | |
| 28 | 28 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments