Skip to content

Commit

Permalink
lib: use kResistStopPropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
atlowChemi committed Jun 25, 2023
1 parent 0741f5a commit fc1e0ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
kTrustEvent,
kNewListener,
kRemoveListener,
kResistStopPropagation,
kWeakHandler,
} = require('internal/event_target');
const {
Expand Down Expand Up @@ -435,7 +436,8 @@ async function aborted(signal, resource) {
if (signal.aborted)
return PromiseResolve();
const abortPromise = createDeferredPromise();
signal.addEventListener('abort', abortPromise.resolve, { [kWeakHandler]: resource, once: true });
const opts = { __proto__: null, [kWeakHandler]: resource, once: true, [kResistStopPropagation]: true };
signal.addEventListener('abort', abortPromise.resolve, opts);
return abortPromise.promise;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/internal/watch_mode/files_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { fileURLToPath } = require('url');
const { resolve, dirname } = require('path');
const { setTimeout } = require('timers');

let kResistStopPropagation;

const supportsRecursiveWatching = process.platform === 'win32' ||
process.platform === 'darwin';
Expand All @@ -41,7 +42,11 @@ class FilesWatcher extends EventEmitter {
this.#mode = mode;
this.#signal = signal;

signal?.addEventListener('abort', () => this.clear(), { __proto__: null, once: true });
if (signal) {
kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
const opts = { __proto__: null, once: true, [kResistStopPropagation]: true };
signal?.addEventListener('abort', () => this.clear(), opts);
}
}

#isPathWatched(path) {
Expand Down

0 comments on commit fc1e0ad

Please sign in to comment.