Skip to content

Return undefined or null instead of throwing an exception #1734

Closed
@aqueenan

Description

@aqueenan

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions