-
Notifications
You must be signed in to change notification settings - Fork 127
fix: use self
instead of this
inside FSWatcher onchange callback
#97
fix: use self
instead of this
inside FSWatcher onchange callback
#97
Conversation
onchange callback sets this to the reported FSEvent rather than the outer FSWatcher
self
instead of this
inside FSWatcher change callbackself
instead of this
inside FSWatcher change callback
self
instead of this
inside FSWatcher change callbackself
instead of this
inside FSWatcher onchange callback
A quick check of later versions of Electron and this code has been moved (with the node/lib/internal/fs/watchers.js Lines 111 to 132 in 8bc5d17
I tested out the same repro on 4.1.1 (Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢 Ah self
, how I don't miss you now we have arrow functions 😀
Fix looks good to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for catching this @shiftkey!
@shiftkey awesome description and PR, looking forward to this landing in Electron 3.x 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice detective work @shiftkey! Thanks for the patch!
To reproduce this behaviour on Electron
3.1.x
, I have a test project setup (on Windows, but I don't think that matters here):Open the dev tools, click the
Click me!
button, see the app break into your code:Browse to the source of
this._handle.onchange` callback (line 1382):
fs.js
and put a break point insideFSWatcher
'sResume the app and it should hit the
fs.js
breakpoint. Check the local scope:Note that
this
inside the callback is theFSEvent
associated with theonchange
event, not the currentFSWatcher
. Further down the code usesself.*
to emit events, and I think this was just a code path that rarely gets exercised.I haven't triggered the specific code path because it requires the underlying filesystem to return a negative
status
value, but I know of these two issues in the wild that can be traced to this:Let me know if this isn't the right branch to target for the PR, and if there's anything else I can do to expedite this fix into the main Electron repository.