-
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
extending options from a prototype #62
extending options from a prototype #62
Comments
perhaps we can have a test case for this to find a more optimal path, perhaps one that avoids |
This is a somewhat contentious issue. IMO, I agree with the current behavior -- Node/IO apis should only take the given object into account, and ignore its [[Proto]] chain. That said, the TC should probably make an authoritative decision about "how Node/IO deals with API parameters" -- ideally something that can be put into the docs. |
I'd rather support proto chain, because sometimes it's very convenient to have. Imho, this proto getters case is a very strong argument to do so. According to my benchmarks,
So it's faster even if we're talking plain js objects. But This is the reason I'm usually using I suppose this is an old code, and v8 didn't have |
I do not think it would be safe to assume that the absence of its usage in Node's APIs for options objects is due to the lack of
While performance has always been a guiding concern of Node, there has also long been a desire to make the API more explicit where possible, even at the cost of CPU cycles. I can envision a situation where |
I did shoot myself in a foot once, when I had an option object like The fact that you can specify the same thing in two different ways is an api issue, which has nothing to do with prototype chains imho.
I suppose an addition to |
If you outlaw the proto chain on options objects, it will cause breakage on legacy code. I wonder if in the specified case, Object.create(Object.freeze(options || {})) might cause V8 to optimize the case (eg it can rely on static rather than dynamic lookups on the proto chain) - and if not it may be a case that v8 optimize in the future |
I feel somewhat strongly that you should always follow the prototype chain, i.e. just use [[Get]]. This is the most natural pattern, i.e. Another way of thinking about this is that if you were to write such options-taking functions in ES6 you would likely do function client({ agent, protocol, ... }) {
/* use agent, protocol, etc. */
} Probably http.client itself couldn't work this way because it has so many overloads and defaults, but it should still be useful semantic guidance. |
From TC meeting, #144:
@indutny and @piscisaureus also expressed opinions on this but there was no resolution, just an agreement that there shal be further bikeshedding. I'm going to remove the tc-agenda label for now but if this keeps on going on and doesn't get anywhere productive then the label could be put back for a future meeting. |
feels good to know you guys discussed this at least. 🙌 io.js 🙌 |
/cc @moll |
Closing this. There's no definitive resolution from the TC, but @domenic swayed me to the proto-side via the ES6 destructuring argument. If anyone notices any specific APIs that are not accepting inherited attributes, feel free to open a PR and cc me. I'd be happy to take a look at them, and am generally +1 on making those sorts of changes. |
Original commit message: Merged: [interpreter] Store accumulator to callee after optional chain checks Revision: df98901c19ce17ca995ee6750379b0f004210d68 BUG=chromium:1171954 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true R=rmcilroy@chromium.org (cherry picked from commit f309db52c2ccab8c9a04fcd236e89deb077061f9) Change-Id: If09e1503ca07b47a112362495ec0bb9d502118c9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2674008 Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Cr-Original-Commit-Position: refs/branch-heads/8.9@{nodejs#33} Cr-Original-Branched-From: 16b9bbbd581c25391981aa03180b76aa60463a3e-refs/heads/8.9.255@{#1} Cr-Original-Branched-From: d16a2a688498bd1c3e6a49edb25d8c4ca56232dc-refs/heads/master@{#72039} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2706110 Reviewed-by: Mythri Alle <mythria@chromium.org> Commit-Queue: Achuith Bhandarkar <achuith@chromium.org> Cr-Commit-Position: refs/branch-heads/8.6@{nodejs#62} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Refs: v8/v8@e527ba4
Original commit message: Merged: [interpreter] Store accumulator to callee after optional chain checks Revision: df98901c19ce17ca995ee6750379b0f004210d68 BUG=chromium:1171954 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true R=rmcilroy@chromium.org (cherry picked from commit f309db52c2ccab8c9a04fcd236e89deb077061f9) Change-Id: If09e1503ca07b47a112362495ec0bb9d502118c9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2674008 Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Cr-Original-Commit-Position: refs/branch-heads/8.9@{nodejs#33} Cr-Original-Branched-From: 16b9bbbd581c25391981aa03180b76aa60463a3e-refs/heads/8.9.255@{#1} Cr-Original-Branched-From: d16a2a688498bd1c3e6a49edb25d8c4ca56232dc-refs/heads/master@{#72039} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2706110 Reviewed-by: Mythri Alle <mythria@chromium.org> Commit-Queue: Achuith Bhandarkar <achuith@chromium.org> Cr-Commit-Position: refs/branch-heads/8.6@{nodejs#62} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Refs: v8/v8@e527ba4
Original commit message: Merged: [interpreter] Store accumulator to callee after optional chain checks Revision: df98901c19ce17ca995ee6750379b0f004210d68 BUG=chromium:1171954 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true R=rmcilroy@chromium.org (cherry picked from commit f309db52c2ccab8c9a04fcd236e89deb077061f9) Change-Id: If09e1503ca07b47a112362495ec0bb9d502118c9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2674008 Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Cr-Original-Commit-Position: refs/branch-heads/8.9@{#33} Cr-Original-Branched-From: 16b9bbbd581c25391981aa03180b76aa60463a3e-refs/heads/8.9.255@{#1} Cr-Original-Branched-From: d16a2a688498bd1c3e6a49edb25d8c4ca56232dc-refs/heads/master@{#72039} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2706110 Reviewed-by: Mythri Alle <mythria@chromium.org> Commit-Queue: Achuith Bhandarkar <achuith@chromium.org> Cr-Commit-Position: refs/branch-heads/8.6@{#62} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Refs: v8/v8@e527ba4 PR-URL: #38275 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
i currently have an issue when creating
http.client()
requests from anoptions
object that is created from a constructor: petkaantonov/urlparser#5https://github.com/iojs/io.js/blob/v0.12/lib/_http_client.js#L50
my solution would be
options = Object.create(options || {})
or something, but i'm pretty sure someone's going to complain about performance or something...what do you guys think?
The text was updated successfully, but these errors were encountered: