-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
src: avoid prototype access in binding templates #47913
Conversation
Review requested:
|
Commit Queue failed- Loading data for nodejs/node/pull/47913 ✔ Done loading data for nodejs/node/pull/47913 ----------------------------------- PR info ------------------------------------ Title src: avoid prototype access in binding templates (#47913) Author Joyee Cheung (@joyeecheung) Branch joyeecheung:binding -> nodejs:main Labels c++, lib / src, needs-ci Commits 1 - src: avoid prototype access in binding templates Committers 1 - Joyee Cheung PR-URL: https://github.com/nodejs/node/pull/47913 Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/47913 Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell -------------------------------------------------------------------------------- ℹ This PR was created on Mon, 08 May 2023 03:16:57 GMT ✔ Approvals: 2 ✔ - Chengzhong Wu (@legendecas) (TSC): https://github.com/nodejs/node/pull/47913#pullrequestreview-1418106668 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/47913#pullrequestreview-1419744904 ✘ Last GitHub CI failed ℹ Last Full PR CI on 2023-05-10T11:42:30Z: https://ci.nodejs.org/job/node-test-pull-request/51743/ - Querying data for job/node-test-pull-request/51743/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/4948851579 |
I think what would be nice for the PR description/commit message is a motivation for why this change is right, not just what it does. |
Do you have any suggestions? I am not sure how to formulate the motivation (because falling back to prototype lookup for these is unnecessary and a bit awkward?). It's like when you define a module.exports you don't do this weird dance:
and just do
|
Ping @addaleax Do you have any specific suggestions about the commit message? Or should I just use that example above to explain it? |
@joyeecheung No strong preferences, just wanted to make sure that it’s just a simplification of the code and otherwise doesn’t really change anything |
Yeah, I believe this is a simplification of the code. The cpp format linter is complaining. A re-format might be needed. |
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template. Previously the initialization was similar to: ``` function Binding() {} Binding.prototype.property = ...; module.exports = new Binding; ``` Now it's similar to: ``` module.exports = { property: ... }; ```
084dfdd
to
be2d7ed
Compare
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template. Previously the initialization was similar to: ``` function Binding() {} Binding.prototype.property = ...; module.exports = new Binding; ``` Now it's similar to: ``` module.exports = { property: ... }; ``` PR-URL: #47913 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in c0365fd with the commit message fixed. |
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template. Previously the initialization was similar to: ``` function Binding() {} Binding.prototype.property = ...; module.exports = new Binding; ``` Now it's similar to: ``` module.exports = { property: ... }; ``` PR-URL: #47913 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template. Previously the initialization was similar to: ``` function Binding() {} Binding.prototype.property = ...; module.exports = new Binding; ``` Now it's similar to: ``` module.exports = { property: ... }; ``` PR-URL: nodejs#47913 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template. Previously the initialization was similar to: ``` function Binding() {} Binding.prototype.property = ...; module.exports = new Binding; ``` Now it's similar to: ``` module.exports = { property: ... }; ``` PR-URL: nodejs#47913 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
This patch makes the binding templates ObjectTemplates, since we don't actually need the constructor function. This also avoids setting the properties on prototype, and instead initializes them directly on the object template.