★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/27096Nouvelle recherche | Portail wanayoo
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
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 5, 2019

@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 5, 2019

@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 5, 2019

lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
Co-Authored-By: targos <targos@protonmail.com>
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 5, 2019

@targos targos requested a review from joyeecheung Apr 6, 2019
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 6, 2019

jasnell
jasnell approved these changes Apr 6, 2019
Copy link
Member

@joyeecheung joyeecheung left a comment

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

@joyeecheung joyeecheung commented Apr 7, 2019

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 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

@joyeecheung joyeecheung Apr 7, 2019

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

@targos targos Apr 7, 2019

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 targos commented Apr 8, 2019

Landed in 112cc7c

@targos targos closed this Apr 8, 2019
@targos targos deleted the primordial-prototypes branch Apr 8, 2019
targos added a commit that referenced this issue 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 <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants