diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-07-27 14:35:39 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-08-05 13:46:13 +0200 |
commit | af7164ebccd21d9fc5b0782e0427257f7637a4db (patch) | |
tree | 589f506811cb65293b88fcd8984ae7ac0e5a80be /lib/internal/fs/watchers.js | |
parent | a196aa2e24ef7069289fa4a9aa8c6862d82e6b5f (diff) | |
download | android-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.tar.gz android-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.tar.bz2 android-node-v8-af7164ebccd21d9fc5b0782e0427257f7637a4db.zip |
lib,src: standardize `owner_symbol` for handles
Instead of somtimes using an `owner` string to link from a
native handle object to the corresponding JS object, standardize
on a single symbol that fulfills this role.
PR-URL: https://github.com/nodejs/node/pull/22002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'lib/internal/fs/watchers.js')
-rw-r--r-- | lib/internal/fs/watchers.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index e7edc1c5ac..90ea3971aa 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -11,7 +11,10 @@ const { getStatsFromBinding, validatePath } = require('internal/fs/utils'); -const { defaultTriggerAsyncIdScope } = require('internal/async_hooks'); +const { + defaultTriggerAsyncIdScope, + symbols: { owner_symbol } +} = require('internal/async_hooks'); const { toNamespacedPath } = require('path'); const { validateUint32 } = require('internal/validators'); const { getPathFromURL } = require('internal/url'); @@ -20,7 +23,6 @@ const assert = require('assert'); const kOldStatus = Symbol('kOldStatus'); const kUseBigint = Symbol('kUseBigint'); -const kOwner = Symbol('kOwner'); function emitStop(self) { self.emit('stop'); @@ -36,7 +38,7 @@ function StatWatcher(bigint) { util.inherits(StatWatcher, EventEmitter); function onchange(newStatus, stats) { - const self = this[kOwner]; + const self = this[owner_symbol]; if (self[kOldStatus] === -1 && newStatus === -1 && stats[2/* new nlink */] === stats[16/* old nlink */]) { @@ -59,7 +61,7 @@ StatWatcher.prototype.start = function(filename, persistent, interval) { return; this._handle = new _StatWatcher(this[kUseBigint]); - this._handle[kOwner] = this; + this._handle[owner_symbol] = this; this._handle.onchange = onchange; if (!persistent) this._handle.unref(); @@ -104,7 +106,7 @@ function FSWatcher() { EventEmitter.call(this); this._handle = new FSEvent(); - this._handle.owner = this; + this._handle[owner_symbol] = this; this._handle.onchange = (status, eventType, filename) => { // TODO(joyeecheung): we may check self._handle.initialized here @@ -131,6 +133,7 @@ function FSWatcher() { } util.inherits(FSWatcher, EventEmitter); + // FIXME(joyeecheung): this method is not documented. // At the moment if filename is undefined, we // 1. Throw an Error if it's the first time .start() is called @@ -187,6 +190,13 @@ function emitCloseNT(self) { self.emit('close'); } +// Legacy alias on the C++ wrapper object. This is not public API, so we may +// want to runtime-deprecate it at some point. There's no hurry, though. +Object.defineProperty(FSEvent.prototype, 'owner', { + get() { return this[owner_symbol]; }, + set(v) { return this[owner_symbol] = v; } +}); + module.exports = { FSWatcher, StatWatcher |