-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: execute mkdtemp's callback with no context #7068
fs: execute mkdtemp's callback with no context #7068
Conversation
fs.mkdtemp(path.join(common.tmpDir, 'bar.'), common.mustCall(handler)); | ||
|
||
// Same test as above, but making sure that passing an options object doesn't | ||
// affect the way callback function is handled. |
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.
nit: affect the way the callback
?
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.
Ack
Thanks for the review @addaleax :-) I am not a native English speaker, so thanks for correcting my punctuations and grammar :-) Updated. PTAL |
no problem :) LGTM! |
Bump! |
@@ -1616,7 +1615,7 @@ fs.mkdtemp = function(prefix, options, callback_) { | |||
} | |||
|
|||
var req = new FSReqWrap(); | |||
req.oncomplete = callback; | |||
req.oncomplete = makeCallback(callback); |
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.
Does makeCallback()
need to be called earlier? What if callback
is invoked via nullCheck()
a few lines up?
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.
Oh yes. Fixed it now. PTAL.
All the callback functions in `fs` module are supposed to be executed with no context (`this` value should not be a valid object). But `mkdtemp`'s callback will have the `FSReqWrap` object as the context. Sample code to reproduce the problem 'use strict'; const fs = require('fs'); fs.mkdtemp('/tmp/abcd', null, function() { console.log(this); }); This would print FSReqWrap { oncomplete: [Function] } But that should have printed `null` and this patch fixes that.
d1647f9
to
7ea5025
Compare
LGTM |
1 similar comment
LGTM |
Landed in c4fadbc |
All the callback functions in `fs` module are supposed to be executed with no context (`this` value should not be a valid object). But `mkdtemp`'s callback will have the `FSReqWrap` object as the context. Sample code to reproduce the problem 'use strict'; const fs = require('fs'); fs.mkdtemp('/tmp/abcd', null, function() { console.log(this); }); This would print FSReqWrap { oncomplete: [Function] } But that should have printed `null` and this patch fixes that. PR-URL: #7068 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
All the callback functions in `fs` module are supposed to be executed with no context (`this` value should not be a valid object). But `mkdtemp`'s callback will have the `FSReqWrap` object as the context. Sample code to reproduce the problem 'use strict'; const fs = require('fs'); fs.mkdtemp('/tmp/abcd', null, function() { console.log(this); }); This would print FSReqWrap { oncomplete: [Function] } But that should have printed `null` and this patch fixes that. PR-URL: #7068 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
@thefourtheye lts? |
@thealphanerd I am afraid #6828, #6832, and #6834 are also necessary. |
marking as don't land as the other mentioned pr's are as well. Please feel free to revisit as a backport PR if you think it is necessary for LTS stability |
Checklist
Affected core subsystem(s)
fs
Description of change
All the callback functions in
fs
module are supposed to be executedwith no context (
this
value should not be a valid object). Butmkdtemp
's callback will have theFSReqWrap
object as the context.Sample code to reproduce the problem
This would print
But that should have printed
null
and this patch fixes that.cc @nodejs/fs
CI Run: https://ci.nodejs.org/job/node-test-pull-request/2865/