Skip to content
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

Closed

Conversation

thefourtheye
Copy link
Contributor

@thefourtheye thefourtheye commented May 30, 2016

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Affected core subsystem(s)

fs

Description of change

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.

cc @nodejs/fs


CI Run: https://ci.nodejs.org/job/node-test-pull-request/2865/

@thefourtheye thefourtheye added the fs Issues and PRs related to the fs subsystem / file system. label May 30, 2016
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.
Copy link
Member

@addaleax addaleax May 30, 2016

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@thefourtheye
Copy link
Contributor Author

Thanks for the review @addaleax :-) I am not a native English speaker, so thanks for correcting my punctuations and grammar :-) Updated. PTAL

@addaleax
Copy link
Member

no problem :) LGTM!

@thefourtheye
Copy link
Contributor Author

Bump!

@@ -1616,7 +1615,7 @@ fs.mkdtemp = function(prefix, options, callback_) {
}

var req = new FSReqWrap();
req.oncomplete = callback;
req.oncomplete = makeCallback(callback);
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@thefourtheye thefourtheye force-pushed the fix-mkdtemp-cb-global-scope branch from d1647f9 to 7ea5025 Compare June 3, 2016 04:45
@cjihrig
Copy link
Contributor

cjihrig commented Jun 3, 2016

LGTM

1 similar comment
@jasnell
Copy link
Member

jasnell commented Jun 3, 2016

LGTM

@thefourtheye
Copy link
Contributor Author

Landed in c4fadbc

@thefourtheye thefourtheye deleted the fix-mkdtemp-cb-global-scope branch June 4, 2016 11:03
thefourtheye added a commit that referenced this pull request Jun 4, 2016
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]>
evanlucas pushed a commit that referenced this pull request Jun 15, 2016
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]>
@evanlucas evanlucas mentioned this pull request Jun 16, 2016
@MylesBorins
Copy link
Contributor

@thefourtheye lts?

@thefourtheye
Copy link
Contributor Author

@thealphanerd I am afraid #6828, #6832, and #6834 are also necessary.

@MylesBorins
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants