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

lib,doc: enable no-prototype-builtins #18750

Closed
wants to merge 4 commits into from

Conversation

BridgeAR
Copy link
Member

This enables the no-prototype-builtins eslint rule for /lib and
for /doc.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

lib,doc

This enables the `no-prototype-builtins` eslint rule for /lib and
for /doc.
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. async_hooks Issues and PRs related to the async hooks subsystem. crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. labels Feb 13, 2018
doc/api/util.md Outdated
@@ -65,7 +65,7 @@ is wrapped in an `Error` with the original value stored in a field named
callbackFunction((err, ret) => {
// When the Promise was rejected with `null` it is wrapped with an Error and
// the original value is stored in `reason`.
err && err.hasOwnProperty('reason') && err.reason === null; // true
err && Object.prototype.call(err, 'reason') && err.reason === null; // true
Copy link
Contributor

Choose a reason for hiding this comment

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

Object.prototype.hasOwnProperty.call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Solved.

@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 13, 2018

doc/api/util.md Outdated
@@ -65,7 +65,9 @@ is wrapped in an `Error` with the original value stored in a field named
callbackFunction((err, ret) => {
// When the Promise was rejected with `null` it is wrapped with an Error and
// the original value is stored in `reason`.
err && err.hasOwnProperty('reason') && err.reason === null; // true
console.log(err && Object.prototype.hasOwnProperty.call(err, 'reason') &&
Copy link
Member

@devsnek devsnek Feb 13, 2018

Choose a reason for hiding this comment

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

as long as this is being refactored can you pull hasOwnProperty off at the top like you did with the other files

Copy link
Member Author

Choose a reason for hiding this comment

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

I went for removing as it is not necessary in the example. It is strictly testing for null and that has to be explicitly set.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 13, 2018
@apapirovski
Copy link
Member

Worth noting this now relies on Function.prototype.call... but it's by far not the only code of that nature.

@devsnek
Copy link
Member

devsnek commented Feb 13, 2018

@apapirovski i'm making a pr based on discussions in #17434 which will (among other things) take care of that

@apapirovski
Copy link
Member

@devsnek Did we have a good conclusion out of that? I'm still not convinced I love any of the options... 😞 Having huge require blocks at the top for ObjectKeys, ReflectApply, ReflectKeys, etc. is not really where I want to be. But I mean, that's just all my opinion and it's fair enough if others feel differently.

@devsnek
Copy link
Member

devsnek commented Feb 13, 2018

@apapirovski i'm opening the pr to hopefully heat things up a little bit and come to a final decision 😄

@@ -400,7 +401,7 @@ function expectedException(actual, expected, msg) {
if (expected.prototype !== undefined && actual instanceof expected) {
return true;
}
if (Error.isPrototypeOf(expected)) {
if (isPrototypeOf.call(Error, expected)) {
Copy link
Member

Choose a reason for hiding this comment

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

Reflect.apply is preferred over Function.prototype.call/apply. Ditto everywhere else.

Copy link
Member

Choose a reason for hiding this comment

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

I have one concern about using that in getOrSetAsyncId since it's somewhat hot path code... means creating an array for the arguments each time.

Copy link
Member

Choose a reason for hiding this comment

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

in getOrSetAsyncId shouldn't we really be using an undefined check since it appears to be a lot faster

Copy link
Member

Choose a reason for hiding this comment

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

@devsnek it still has the problem of potentially inheriting through prototype. I don't know how likely it is though... I'll ping @AndreasMadsen

Copy link
Member

Choose a reason for hiding this comment

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

Reflect.has also seems significantly faster at this point, just as another option

@BridgeAR
Copy link
Member Author

I am feeling somewhat reluctant to merge this due to the discussion in #18773. What do others think? Shall I just close this?

@BridgeAR BridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 18, 2018
@BridgeAR
Copy link
Member Author

I am closing this for now as I feel the main discussion should be done first.

@BridgeAR BridgeAR closed this Feb 28, 2018
@BridgeAR BridgeAR deleted the no-prototype-builtins branch April 1, 2019 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. async_hooks Issues and PRs related to the async hooks subsystem. crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants