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

Fix crash in DowncastError Display impl, remove String member #606

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

sbillig
Copy link
Contributor

@sbillig sbillig commented Sep 26, 2020

In the Display impl for DowncastError, fmt() calls self.to_string(), which calls fmt(), which calls self.to_string(), which... causing the following to crash:

    let s = cx.string("hello");
    if let Err(e) = s.downcast::<JsNumber>() {
        eprintln!("downcast error: {}", e);
    }

This commit also removes the String member in DowncastError, eliminating the allocation overhead on creation (which is then paid when/if the error is thrown), and removes the Error::description() impl, which has been deprecated since rust 1.42.

@kjvalencik
Copy link
Member

kjvalencik commented Sep 27, 2020

@sbillig This is great! Thanks for fixing this. Would you mind adding a test to test/dynamic and test/napi to prevent a regression in the future?

@sbillig
Copy link
Contributor Author

sbillig commented Oct 6, 2020

@kjvalencik I added a simple test.

@kjvalencik kjvalencik merged commit 32f3276 into neon-bindings:master Oct 6, 2020
@kjvalencik
Copy link
Member

@sbillig Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants