-
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
Conversation
e57882c
to
a1dc769
Compare
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.
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.
Yea, but for them to be discovered they have to be enumerable so the trick is to make them non-enumerable.
Getters are non-enumerable by default when defined by syntax and when added with defineProperty
.
If anything the concerning bit might be the enumerability trap but that's a concern regardless.
Such as if the body contains native code.
a1dc769
to
0682cde
Compare
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
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 of `toString` on a `class` 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. --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de> DiffTrain build for [18ee505](18ee505)
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 of `toString` on a `class` 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. --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de> DiffTrain build for [18ee505](facebook@18ee505)
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 of `toString` on a `class` 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. --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de> DiffTrain build for [18ee505](facebook@18ee505)
…nformation (#33592) Stacked on #33588, #33589 and #33590. This lets us automatically show the resolved value in the UI. <img width="863" alt="Screenshot 2025-06-22 at 12 54 41 AM" src="https://github.com/user-attachments/assets/a66d1d5e-0513-4767-910c-5c7169fc2df4" /> We can also show rejected I/O that may or may not have been handled with the error message. <img width="838" alt="Screenshot 2025-06-22 at 12 55 06 AM" src="https://github.com/user-attachments/assets/e0a8b6ae-08ba-46d8-8cc5-efb60956a1d1" /> To get this working we need to keep the Promise around for longer so that we can access it once we want to emit an async sequence. I do this by storing the WeakRefs but to ensure that the Promise doesn't get garbage collected, I keep a WeakMap of Promise to the Promise that it depended on. This lets the VM still clean up any Promise chains that have leaves that are cleaned up. So this makes Promises live until the last Promise downstream is done. At that point we can go back up the chain to read the values out of them. Additionally, to get the best possible value we don't want to get a Promise that's used by internals of a third-party function. We want the value that the first party gets to observe. To do this I had to change the logic for which "await" to use, to be the one that is the first await that happened in user space. It's not enough that the await has any first party at all on the stack - it has to be the very first frame. This is a little sketchy because it relies on the `.then()` call or `await` call not having any third party wrappers. But it gives the best object since it hides all the internals. For example when you call `fetch()` we now log that actual `Response` object.
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.