| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,7 +203,7 @@ EventEmitter.init = function(opts) { | |||
| 203 | 203 | this._maxListeners = this._maxListeners || undefined; | |
| 204 | 204 | ||
| 205 | 205 | ||
| 206 | - if (opts && opts.captureRejections) { | ||
| 206 | + if (opts?.captureRejections) { | ||
| 207 | 207 | if (typeof opts.captureRejections !== 'boolean') { | |
| 208 | 208 | throw new ERR_INVALID_ARG_TYPE('options.captureRejections', | |
| 209 | 209 | 'boolean', opts.captureRejections); | |
@@ -709,9 +709,9 @@ function getEventListeners(emitterOrTarget, type) { | |||
| 709 | 709 | } | |
| 710 | 710 | ||
| 711 | 711 | async function once(emitter, name, options = {}) { | |
| 712 | - const signal = options ? options.signal : undefined; | ||
| 712 | + const signal = options?.signal; | ||
| 713 | 713 | validateAbortSignal(signal, 'options.signal'); | |
| 714 | - if (signal && signal.aborted) | ||
| 714 | + if (signal?.aborted) | ||
| 715 | 715 | throw lazyDOMException('The operation was aborted', 'AbortError'); | |
| 716 | 716 | return new Promise((resolve, reject) => { | |
| 717 | 717 | const errorListener = (err) => { | |
@@ -765,7 +765,7 @@ function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) { | |||
| 765 | 765 | ||
| 766 | 766 | function eventTargetAgnosticAddListener(emitter, name, listener, flags) { | |
| 767 | 767 | if (typeof emitter.on === 'function') { | |
| 768 | - if (flags && flags.once) { | ||
| 768 | + if (flags?.once) { | ||
| 769 | 769 | emitter.once(name, listener); | |
| 770 | 770 | } else { | |
| 771 | 771 | emitter.on(name, listener); | |
@@ -780,9 +780,9 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) { | |||
| 780 | 780 | } | |
| 781 | 781 | ||
| 782 | 782 | function on(emitter, event, options) { | |
| 783 | - const { signal } = { ...options }; | ||
| 783 | + const signal = options?.signal; | ||
| 784 | 784 | validateAbortSignal(signal, 'options.signal'); | |
| 785 | - if (signal && signal.aborted) { | ||
| 785 | + if (signal?.aborted) { | ||
| 786 | 786 | throw lazyDOMException('The operation was aborted', 'AbortError'); | |
| 787 | 787 | } | |
| 788 | 788 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,7 +95,7 @@ class Event { | |||
| 95 | 95 | this[kDefaultPrevented] = false; | |
| 96 | 96 | this[kTimestamp] = lazyNow(); | |
| 97 | 97 | this[kPropagationStopped] = false; | |
| 98 | - if (options != null && options[kTrustEvent]) { | ||
| 98 | + if (options?.[kTrustEvent]) { | ||
| 99 | 99 | isTrustedSet.add(this); | |
| 100 | 100 | } | |
| 101 | 101 | ||
@@ -185,7 +185,7 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, { | |||
| 185 | 185 | class NodeCustomEvent extends Event { | |
| 186 | 186 | constructor(type, options) { | |
| 187 | 187 | super(type, options); | |
| 188 | - if (options && options.detail) { | ||
| 188 | + if (options?.detail) { | ||
| 189 | 189 | this.detail = options.detail; | |
| 190 | 190 | } | |
| 191 | 191 | } | |
@@ -340,10 +340,7 @@ class EventTarget { | |||
| 340 | 340 | return; | |
| 341 | 341 | ||
| 342 | 342 | type = String(type); | |
| 343 | - // TODO(@jasnell): If it's determined this cannot be backported | ||
| 344 | - // to 12.x, then this can be simplified to: | ||
| 345 | - // const capture = Boolean(options?.capture); | ||
| 346 | - const capture = options != null && options.capture === true; | ||
| 343 | + const capture = options?.capture === true; | ||
| 347 | 344 | ||
| 348 | 345 | const root = this[kEvents].get(type); | |
| 349 | 346 | if (root === undefined || root.next === undefined) | |
@@ -555,9 +552,7 @@ ObjectDefineProperties(NodeEventTarget.prototype, { | |||
| 555 | 552 | ||
| 556 | 553 | function shouldAddListener(listener) { | |
| 557 | 554 | if (typeof listener === 'function' || | |
| 558 | - (listener != null && | ||
| 559 | - typeof listener === 'object' && | ||
| 560 | - typeof listener.handleEvent === 'function')) { | ||
| 555 | + typeof listener?.handleEvent === 'function') { | ||
| 561 | 556 | return true; | |
| 562 | 557 | } | |
| 563 | 558 | ||
@@ -586,7 +581,7 @@ function validateEventListenerOptions(options) { | |||
| 586 | 581 | // It stands in its current implementation as a compromise. | |
| 587 | 582 | // Ref: https://github.com/nodejs/node/pull/33661 | |
| 588 | 583 | function isEventTarget(obj) { | |
| 589 | - return obj && obj.constructor && obj.constructor[kIsEventTarget]; | ||
| 584 | + return obj?.constructor?.[kIsEventTarget]; | ||
| 590 | 585 | } | |
| 591 | 586 | ||
| 592 | 587 | function addCatch(that, promise, event) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments