-
Notifications
You must be signed in to change notification settings - Fork 48.8k
[Flight] Support classes in renderDebugModel #33590
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
base: main
Are you sure you want to change the base?
Conversation
Such as if the body contains native code.
e57882c
to
a1dc769
Compare
return name.replace(/^\[object (.*)\]$/, function (m, p0) { | ||
return p0; | ||
}); | ||
return name.slice(8, name.length - 1); |
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.
With the regex now gone, a comment explaining the magic 8 would be nice, e.g.:
return name.slice(8, name.length - 1); | |
// Extract 'Object' from '[object Object]': | |
return name.slice(8, name.length - 1); |
for (const propName in object) { | ||
if (hasOwnProperty.call(value, propName) || isGetter(proto, propName)) { | ||
// We intentionally invoke getters on the prototype to read any enumerable getters. | ||
instanceDescription[propName] = object[propName]; |
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.
I'm a bit concerned that this might trigger unwanted side effects, like the getters on the "exotic" promises in Next.js.
This adds better support for serializing class instances as Debug values.
It adds a new marker on the object
{ "": "$P...", ... }
which indicates which constructor's prototype to use for this object's prototype. It doesn't encode arbitrary prototypes and it doesn't encode any of the properties on the prototype. It might get some of the properties from the prototype by virtue oftoString
on aclass
constructor will include the whole class's body.This will ensure that the instance gets the right name in logs.
Additionally, this now also invokes getters if they're enumerable on the prototype. This lets us reify values that can only be read from native classes.