fs: make FSWatcher.start private · nodejs/node@7eacb74 · GitHub
Skip to content

Commit 7eacb74

Browse files
lholmquistTrott
authored andcommitted
fs: make FSWatcher.start private
* This is a semver-major change to rename the FSWatcher.start function to FSWatcher._start to make it private The motivation here is that it serves no purpose to the end user. An instance of FSWatcher is returned when a user calls fs.watch, which will call the start method. A user can't create an instance of a FSWatcher directly. If the start method is called by a user it is a noop since the watcher has already started. Calling start after a watcher has closed is also a noop PR-URL: #29905 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 40ef537 commit 7eacb74

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

lib/fs.js

Lines changed: 4 additions & 4 deletions

lib/internal/fs/watchers.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const assert = require('internal/assert');
2525
const kOldStatus = Symbol('kOldStatus');
2626
const kUseBigint = Symbol('kUseBigint');
2727

28+
const kFSWatchStart = Symbol('kFSWatchStart');
29+
2830
function emitStop(self) {
2931
self.emit('stop');
3032
}
@@ -135,18 +137,16 @@ function FSWatcher() {
135137
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
136138
Object.setPrototypeOf(FSWatcher, EventEmitter);
137139

138-
139-
// FIXME(joyeecheung): this method is not documented.
140140
// At the moment if filename is undefined, we
141-
// 1. Throw an Error if it's the first time .start() is called
142-
// 2. Return silently if .start() has already been called
141+
// 1. Throw an Error if it's the first time Symbol('kFSWatchStart') is called
142+
// 2. Return silently if Symbol('kFSWatchStart') has already been called
143143
// on a valid filename and the wrap has been initialized
144144
// 3. Return silently if the watcher has already been closed
145145
// This method is a noop if the watcher has already been started.
146-
FSWatcher.prototype.start = function(filename,
147-
persistent,
148-
recursive,
149-
encoding) {
146+
FSWatcher.prototype[kFSWatchStart] = function(filename,
147+
persistent,
148+
recursive,
149+
encoding) {
150150
if (this._handle === null) { // closed
151151
return;
152152
}
@@ -202,5 +202,6 @@ Object.defineProperty(FSEvent.prototype, 'owner', {
202202

203203
module.exports = {
204204
FSWatcher,
205-
StatWatcher
205+
StatWatcher,
206+
kFSWatchStart
206207
};

test/parallel/test-fs-watch.js

Lines changed: 0 additions & 7 deletions

0 commit comments

Comments
 (0)