GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||
GeezerVison is showing github.com — util: Handle null prototype on inspect by antsmartian · Pull Request #22331 · nodejs/node Conversation
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Had to remove this test case as this we are checking the message for both cases (with prototype and without prototype). So it was failing with this change. May be I need to do the same test case outside this loop?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
None of these tests should work as before if we detect a null prototype on each of these data types. So the test has to be rewritten anyway.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is a good start but it should not only check for objects but for any type that we explicitly test for and mark it as having a null prototype.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
None of these tests should work as before if we detect a null prototype on each of these data types. So the test has to be rewritten anyway.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think this solves the superficial case of #22141 where a prototype is null, but not the general problem of My 2¢. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@TimothyGu Yes, but when using I'm not sure, what do you mean by:
Am I missing something here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@antsman whatever changes you make here should be made to assertion, not inspection, is Timothy's point. I feel the same way. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I guess the real problem here is that, when assert fails with May be I'm wrong here too. Open for thoughts. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@TimothyGu @devsnek for me this is not about |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I would still say that a solution that works for all prototypes rather than special casing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@TimothyGu that is the plan. Currently all prototypes are handled in inspect besides the null prototype. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
For reference, Chrome DevTools use a pseudo- |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR @TimothyGu Just an update. I'm working on the same for handling all prototypes. Will update the PR in a day or two.. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
b6fccaa to
7ddca64
Compare
There was an error while loading. Please reload this page.
|
@BridgeAR I have implemented the check on all the types. Can you please have a look at it? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7ddca64 to
cd98c73
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is already looking really good! Thanks a lot for looking into it!
Just a few comments and we should make sure the null prototype is also printed in case a tag exists but no constructor.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks like a typo after SharedArrayBuffer?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Addressed all other comments, but I couldn't able to see any typo 🤔 Sorry could you please explain me, whats wrong here? cc @BridgeAR
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See my comment above :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add https://github.com/nodejs/node/blob/cd98c735e879e1218b1c8514ab4218efa841bba4/test/parallel/test-util-inspect.js#L1616-L1620 as well. Otherwise important things would not be tested anymore.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would you please also add Arrays, Dataviews and ArrayBuffers? Errors, Dates and regular expressions should be handled in a different PR as they do not show subclassing at all and that should be fixed as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please inline this check into the getPrefix check. That way the code should be simpler and pretty straight forward.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thought about it. Will work on that and update the PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
cd98c73 to
09c796c
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Due to the changes the types have to be 'ArrayBuffer' and 'SharedArrayBuffer' (without the whitespace at the end).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See my comment above :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This condition should now be obsolete.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If the value has a prototype, we do not have to search for it anymore. Therefore it would be best to write this as:
const clazz = Object.getPrototypeOf(value) || findTypedConstructor(value) || clazzWithNullPrototype(Uint8Array, 'Uint8Array')
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly. If we write like the following:
const clazz = Object.getPrototypeOf(value) || findTypedConstructor(value) || clazzWithNullPrototype(Uint8Array, 'Uint8Array')
when there is no prototype, then findTypedConstructor will definitely return the typed array constructor. So we won't reach clazzWithNullPrototype (when there is no prototype) -- missing the subclass stuff.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You are correct, findTypedConstructor should always return the actual type.
Therefore it should likely be:
let clazz = Object.getPrototypeOf(value); if (!clazz) { const constructor = findTypedConstructor(value); clazz = clazzWithNullProrotype(constructor, constructor.name); }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This condition tests for constructor !== '' so instead of testing in another if for the other case, we can just move the code above below this if. In that case we already know, that the constructor is an empty string and don't have to check again.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Well this is true, but the line:
return `[${fallback}: null prototype] `;
definitely needs a check whether a constructor is empty or not.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What I mean is:
if (constructor !== '') { ... as before ... } if (tag !== '' && fallback !== 'tag') { return `[${fallback}: null prototype] [${tag}] `; } return `[${fallback}: null prototype] `;
That way we are sure the constructor is definitely empty.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR Sorry to trouble you, may be you missed my last comments? :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
09c796c to
9dc530c
Compare
|
Ping @BridgeAR |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Great work :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking nit: adding the line seems obsolete.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking nit: I would remove the newline here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: this now seems to be a duplicated entry with the test below. Since the test below tests more than this one, it would be best to move this entry (or just keep it).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9dc530c to
9112c00
Compare
This makes sure the `null` prototype is always detected properly.
4f52f0f to
215700c
Compare
|
@BridgeAR I have moved the logic to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR Anything else blocking this PR from getting merged? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This makes sure the `null` prototype is always detected properly. PR-URL: nodejs#22331 Fixes: nodejs#22141 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
|
Landed in f4e4ef5 🎉 @antsmartian thanks for sticking to it and being patient! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR Sorry to ping on the closed thread. If you remember, one of the early comments you mentioned that:
I was looking to implement for Also as said in the issue, we need to handle But looks like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@antsmartian feel free to chat with me on IRC (even though I am not always around). It is indeed not a good idea to mutate the input at all. Instead, we should be able to just create the output as we expect it to look like and we only change to change a single string: the stack after accessing it. We also already have the constructor name and don't have to get it again. So it should be similar to: function formatError(value, constructorName) { if (value.stack) { let stack = value.stack; if (!stack.startsWith(constructorName)) { // Note: this check is likely not sufficient. return stack.replace(..., constructorName); } return stack; } return errorToString(value); } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@BridgeAR Thanks. (can you just tell me your IRC handle, I searched for bridgear, doesn't look like its correct) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This makes sure the prototype is always detected properly. PR-URL: nodejs#22331 Fixes: nodejs#22141 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
This makes sure the prototype is always detected properly. Backport-PR-URL: #23655 PR-URL: #22331 Fixes: #22141 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
This makes sure the prototype is always detected properly. Backport-PR-URL: #23655 PR-URL: #22331 Fixes: #22141 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
This makes sure the prototype is always detected properly. Backport-PR-URL: #23655 PR-URL: #22331 Fixes: #22141 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.