Skip to content
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

Debug::fmt Causes Causes a Stack Overflow #608

Closed
jcdickinson opened this issue Aug 7, 2020 · 2 comments · Fixed by #630
Closed

Debug::fmt Causes Causes a Stack Overflow #608

jcdickinson opened this issue Aug 7, 2020 · 2 comments · Fixed by #630
Labels
bug Something isn't working
Milestone

Comments

@jcdickinson
Copy link
Contributor

Describe the bug
For any object that contains prototype, Debug::fmt will cause a stack overflow. This is especially frustrating when some tests fail, as it can mask the reason for the failure.

To Reproduce

Evaluate the following JS and println!("{:?}", result).

new Date()

Expected behavior

Print the debug structure of the value.

Actual behavior

A stack overflow occurs.

Build environment (please complete the following information):

  • OS: Windows
  • Version: 10
  • Target triple: x86_64-unknown-windows-msvc
  • Rustc version: 1.45.1 (c367798cf 2020-07-26)
@jcdickinson jcdickinson added the bug Something isn't working label Aug 7, 2020
@Razican
Copy link
Member

Razican commented Aug 11, 2020

I think we have to decide if we will somehow print the prototype, or if the prototype should have a special debug implementation, so that it doesn't end with circular reference debugging.

What do you think, @HalidOdat, @jasonwilliams, @Lan2u?

@jcdickinson
Copy link
Contributor Author

prototype is merely a guaranteed case, as @HalidOdat points out on my PR.

One thought I had would be to have a trait such as:

trait SafeDebug {
    fn fmt(&self, f: &mut Formatter, s: &mut HashSet<usize>) -> Result<(), std::fmt::Error>;
}

The HashSet can then be used to avoid infinite recursion (by adding the address of GcObject to it), with the additional benefit that it won't print the same structure multiple times (which would make Debug nearly useless if you have a large structure appear multiple times in the output).

The main drawback of all of this is that we'd lose #[derive(Debug)] and we'd have to implement both Debug (forwarding to SafeDebug) and SafeDebug for everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants