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: name anonymous functions #9252

Closed
wants to merge 1 commit into from
Closed

fs: name anonymous functions #9252

wants to merge 1 commit into from

Conversation

fhalde
Copy link
Contributor

@fhalde fhalde commented Oct 24, 2016

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

fs

Description of change

Ref: #8913

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Oct 24, 2016
@fhalde
Copy link
Contributor Author

fhalde commented Oct 24, 2016

cc @thefourtheye

@thefourtheye
Copy link
Contributor

@7coder7 You may have to fix the commit. It says that it was made on May 25th.

@thefourtheye
Copy link
Contributor

@fhalde
Copy link
Contributor Author

fhalde commented Oct 24, 2016

@thefourtheye is it fixed now?

@thefourtheye
Copy link
Contributor

@7coder7 Yes. It looks fine now. But, it looks like there are test failures.

@fhalde
Copy link
Contributor Author

fhalde commented Oct 24, 2016

@thefourtheye had to change the test cases test/parallel/test-sync-io-option.js because the regex condition was failing while searching for the module function-name in the stacktrace

@@ -20,7 +20,7 @@ if (process.argv[2] === 'child') {
execFile(process.execPath, args, function(err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stdout, '');
if (/WARNING[\s\S]*fs\.readFileSync/.test(stderr))
if (/WARNING[\s\S]*readFileSync/.test(stderr))
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming anonymous functions produces a stacktrace with just the function name now. For example, earlier it used to be fs.readFileSync and now it has become just readFileSync in the stacktrace.

Is that okay @nodejs/collaborators ?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's possible to modify Environment::PrintSyncTrace to get it back ?
It's not affecting the stack traces generated by V8 when an error is thrown.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this but @targos' suggestion is good also.

Copy link
Contributor

Choose a reason for hiding this comment

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

@targos I think v8 doesn't provide a way to get the actually bound object name. Is there any APIs which we can leverage? Also, PrintSyncTrace has only references to the Stack Frames. They just give only the debug function names.

Copy link
Member

Choose a reason for hiding this comment

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

@thefourtheye yeah it seems that the API doesn't give us access to more information. I'm fine with the change too.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't the purpose of adding the names to improve stack trace? Maybe we ought to only add names in places where the stack trace can't determine the name? Like, anonymous callback functions, but not functions that are assigned to a property on a variable because the name is inferred from the assignment?

@thefourtheye
Copy link
Contributor

Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

Since the purpose of naming anonymous functions is to improve stack traces, and this seems to have the opposite effect, I'm actually -1 on this and similar changes, I think. I'm OK with this sort of thing in cases where the name cannot be inferred, but the name can be inferred in all the instances in this change, and the name that V8 infers is better than the name we provide in this change.

Copy link
Contributor

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

I too have concerns about this. If fs.func turns to func, it is clearly a regression in my eyes. This can be particularly problematic in net and decendants where many functions are named the same. V8's function name inferring is bound to get better over time, too.

See #8913 (comment) for a suggestion.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I am against this change, as all the named functions will have names inferred by v8.

We should name only the closures.

@@ -1779,7 +1779,7 @@ ReadStream.prototype.open = function() {
});
};

ReadStream.prototype._read = function(n) {
ReadStream.prototype._read = function _read(n) {
if (typeof this.fd !== 'number')
return this.once('open', function() {
Copy link
Member

Choose a reason for hiding this comment

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

this is one that should be named.

Copy link
Contributor

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

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

If for no other reason, it makes grep'ing a lot easier.

@fhalde fhalde closed this Feb 1, 2017
@fhalde
Copy link
Contributor Author

fhalde commented Feb 1, 2017

Closing this since we decided not to pursue with this approach

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.

10 participants