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: replace a bind() with a top-level function #13474

Closed
wants to merge 1 commit into from

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Jun 5, 2017

#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

edit: updated according to @refack suggestion.

@mcollina mcollina requested a review from mscdex June 5, 2017 14:48
@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Jun 5, 2017
@mcollina
Copy link
Member Author

mcollina commented Jun 5, 2017

cc @mscdex

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

So it's not a "useless" bind (it was a Currying null). I'd say you just replaced it with something better.

lib/fs.js Outdated
@@ -2034,6 +2034,11 @@ ReadStream.prototype.close = function(cb) {
this.fd = null;
};

// needed because as it will be called with arguments
// that does not match this.close() signature
function closeOnOpen() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can make it more evident by adding an fd parameter here? Plus I'm sure V8 would prefer it.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated.

lib/fs.js Outdated
// needed because as it will be called with arguments
// that does not match this.close() signature
function closeOnOpen() {
this.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be correct here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that's the exact meaning. this  will be the stream object. I'll add a comment to note that.

Copy link
Contributor

Choose a reason for hiding this comment

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

EventEmitter instances always call their event handlers within the context of the EventEmitter. I'm not sure we need to explicitly document that in this one particular place when we do this same thing throughout core.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @mscdex. I looked at the code too quickly earlier.

@mcollina
Copy link
Member Author

mcollina commented Jun 6, 2017

@mscdex
Copy link
Contributor

mscdex commented Jun 6, 2017

LGTM

@mcollina
Copy link
Member Author

mcollina commented Jun 7, 2017

@refack I've amended the commit message, check if it is ok and I'll merge.

@mcollina mcollina changed the title fs: remove useless bind() fs: replace a bind() with a top-level function Jun 7, 2017
Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

✔️

nodejs#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: nodejs#13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
@mcollina
Copy link
Member Author

mcollina commented Jun 7, 2017

Landed as 07ca288.

@mcollina mcollina closed this Jun 7, 2017
@mcollina mcollina deleted the remove-bind branch June 7, 2017 12:04
mcollina added a commit to mcollina/node that referenced this pull request Jun 7, 2017
nodejs#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: nodejs#13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
jasnell pushed a commit that referenced this pull request Jun 7, 2017
#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: #13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Please feel free to manually backport. Please also feel free to replace the backport request label with do-not-land if it shouldn't land

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.

9 participants