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: use safe methods from primordials #27096

Closed
wants to merge 3 commits into from

Conversation

targos
Copy link
Member

@targos targos commented Apr 5, 2019

This changes the primordials to expose built-in prototypes with their
methods already uncurried.
The uncurryThis function is therefore moved to the primordials.
All uses of uncurryThis on built-ins are changed to import the relevant
prototypes from primordials.
All uses of Function.call.bind are also changed to use primordials.

This changes the primordials to expose built-in prototypes with their
methods already uncurried.
The uncurryThis function is therefore moved to the primordials.
All uses of uncurryThis on built-ins are changed to import the relevant
prototypes from primordials.
All uses of Function.call.bind are also changed to use primordials.
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Apr 5, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 5, 2019
@targos targos requested a review from joyeecheung April 6, 2019 08:12
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

I borrowed the term primordials from the realms proposal, I believe it makes sense to have your own primordials other than the JS builtins? But anyway that's just academic..

@joyeecheung
Copy link
Member

Does this affect performance at all? From what I can tell this does not seem to be on any path that's performance-sensitive, though.

@targos
Copy link
Member Author

targos commented Apr 7, 2019

Does this affect performance at all?

I don't know which one is faster between Function.call.bind(method) and uncurryThis(method). I used uncurryThis because the comment that's with it is about performance.

Or are you talking about the property access (Array.isArray vs ArrayIsArray)? Again I don't know, but I hope that optimized code doesn't suffer from that.

if (!Reflect.getOwnPropertyDescriptor(dest, key)) {
const desc = Reflect.getOwnPropertyDescriptor(src, key);
if (typeof desc.value === 'function') {
desc.value = uncurryThis(desc.value);
Copy link
Member

Choose a reason for hiding this comment

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

I was talking about this, as this affect all prototype methods, not just the Function ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is already what was done manually in all the files I changed (either with call.bind or uncurryThis). This is centralizing the uncurrying to this file. If we want to use the methods safely, we have to call them without going through the prototype.

@targos
Copy link
Member Author

targos commented Apr 8, 2019

Landed in 112cc7c

@targos targos closed this Apr 8, 2019
@targos targos deleted the primordial-prototypes branch April 8, 2019 09:23
targos added a commit that referenced this pull request Apr 8, 2019
This changes the primordials to expose built-in prototypes with their
methods already uncurried.
The uncurryThis function is therefore moved to the primordials.
All uses of uncurryThis on built-ins are changed to import the relevant
prototypes from primordials.
All uses of Function.call.bind are also changed to use primordials.

PR-URL: #27096
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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.

6 participants