-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
console/inspect output for functions is misleading in Hardened JS #55924
Comments
A similar issue also exists one level down: const obj = {};
console.log(obj); // => {}
{
const BultinObjectPrototype = Object.prototype;
Object.defineProperty(Object.prototype, "constructor", {
get: () => BuiltinObjectPrototype,
});
}
console.log(obj); // => Object <[Object: null prototype] {}> {} Failure to establish a constructor name does not imply a null prototype. |
The way the constructor is replaced is tricky. Accessing the getter would trigger side effects and it's as such impossible to identify the constructor properly. We could explore to improve The suggestion for fixing functions is something we can do. The current order was for performance reasons, while it's not a big overhead to get the type of an argument. |
Thanks, that matches my understanding. Would it make sense for me to open a PR, or is there some process between here and there? |
Go for it! |
PR-URL: #56188 Fixes: #55924 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Jordan Harband <[email protected]>
PR-URL: #56188 Fixes: #55924 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Jordan Harband <[email protected]>
PR-URL: #56188 Fixes: #55924 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Jordan Harband <[email protected]>
Version
v22.11.0
Platform
Subsystem
util
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
I expect
console.log({ m(){} })
output to always indicate that the value for property "m" is a function, even whenFunction.prototype.constructor
is an accessor that won't be invoked.What do you see instead?
Defining
Function.prototype.constructor
as an accessor replaces the useful output with text that makes it look like functions are plain objects.Additional information
My proposed fix is updating lib/internal/util/inspect.js
formatRaw
to privilege the "is function" check over "constructor is Object" while preserving their rendering details:node/lib/internal/util/inspect.js
Lines 957 to 969 in 01b9a54
Doing so will still affect the console/inspect output, but in a way that no longer fails to indicates functionness:
(although I am also open to tweaking that as well).
The text was updated successfully, but these errors were encountered: