You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
aqueenan
changed the title
Return undefined null instead of throwing an exception
Return undefined or null instead of throwing an exception
Aug 23, 2019
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?
Motivation
Throwing an exception when returning
JsValue::undefined()
andJsValue::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 forJsValue::undefined()
and returnnull
to JavaScript forJsValue::null()
.Also consider returning
Symbol
to JavaScript forJsValue::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
andnull
, the JavaScript normal behaviour is to returnundefined
andnull
The text was updated successfully, but these errors were encountered: