-
-
Notifications
You must be signed in to change notification settings - Fork 33k
crypto: allow inspecting a crypto key prototype #57890
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
Conversation
Review requested:
|
18d0465
to
25242b2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57890 +/- ##
==========================================
- Coverage 90.24% 90.21% -0.04%
==========================================
Files 630 630
Lines 185670 186445 +775
Branches 36401 36621 +220
==========================================
+ Hits 167567 168196 +629
- Misses 10992 11052 +60
- Partials 7111 7197 +86
🚀 New features to boost your workflow:
|
0a09337
to
6b1cc1d
Compare
This would fail so far due to accessing a undefined property.
6b1cc1d
to
7215b4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only necessary for inspect()
, perhaps the fix could be inside [kInspect]() { ... }
? In any other case, get type()
should throw if this[kKeyObject]
is undefined
.
@tniessen I thought about that as well initially but discarded the thought, when thinking about directly accessing the property. I think it should just return undefined in that case, since it would otherwise be a bad error message for the user. |
dismissing my approval, @tniessen is correct in that if the property is not defined a throw is appropriate behaviour for regular instances of CryptoKey
@panva @jasnell @tniessen would one of you mind picking this up? I just stumbled upon it while working on something else and I did not expect a lot of bikeshedding in this case. I don't really feel strongly enough about either implementation. The current suggestion would require all of our instanceof checks to be extended to the accessed property being accessible in all getters to have a consistent behavior (accessing .type would otherwise throw while accessing the other properties would not, even though they are also |
@BridgeAR what are the use cases for inspecting the prototype in the first place? (genuinely just curious here) |
@panva I have none. I just wrote some tests elsewhere and this failed. The current error message is quite bad in that case (accessing a property of undefined). I also wondered about it meant to fail as @tniessen pointed out, but doing that only for .type would be highly inconsistent with all other properties, so I decided to just be lenient and show undefined (which I find is actually fine for this specific case). |
I am a bit confused as to what the desired output is (other than not throwing an error). I assumed inspecting the prototype should behave like inspecting many other prototypes in Node.js, e.g., I think the root problem is that |
To clarify, I was not suggesting that we should explicitly check for this case and throw in the getters. If we can somehow fix the prototype chain such that
I think that, if this patch ends up explicitly allowing In the end, explicitly allowing this might not be a particularly elegant solution, but since we are talking about JavaScript, I can live with that. |
I'll go ahead and close this for now. I don't think it's important enough for now. |
This would fail so far due to accessing a undefined property.