Skip to content

Return undefined or null instead of throwing an exception #1734

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

Closed
aqueenan opened this issue Aug 23, 2019 · 2 comments
Closed

Return undefined or null instead of throwing an exception #1734

aqueenan opened this issue Aug 23, 2019 · 2 comments

Comments

@aqueenan
Copy link

Motivation

Throwing an exception when returning JsValue::undefined() and JsValue::null() doesn't make sense because only a local exception handler could have any idea what it means.

https://eslint.org/docs/rules/no-throw-literal

Proposed Solution

Return undefined to JavaScript for JsValue::undefined() and return null to JavaScript for JsValue::null().

Also consider returning Symbol to JavaScript for JsValue::symbol(description: Option<&str>).

Alternatives

Instead of throwing value types, wrap them in a JavaScript Error object as recommended at https://eslint.org/docs/rules/no-throw-literal.

That's a good solution for other literals, so I'll raise it as another feature request.

However, for undefined and null, the JavaScript normal behaviour is to return undefined and null

@aqueenan aqueenan changed the title Return undefined null instead of throwing an exception Return undefined or null instead of throwing an exception Aug 23, 2019
@alexcrichton
Copy link
Contributor

Thanks for the report @aqueenan! Can you perhaps show some example code for this issue? I think that the error object behavior looks to be covered by #1735 but I'm not sure what this issue means with respect to null and undefined. I'm also not entirely sure what you mean about Symbol values?

@alexcrichton
Copy link
Contributor

From reading over the discussion in #1735 I think this was handled there, but let me know if I'm closing in error!

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

No branches or pull requests

2 participants