Skip to content

Handle JS null values within Ruby code #24

Closed
@richardboehme

Description

@richardboehme

Hey, thanks for providing those great NPM packages!

I'm currently experimenting with writing DOM-Interaction using the JS interoperability module that this package provides. I wonder if it's possible to handle null values with the JS module?

I try to read from localStorage and if a key was not set localStorage.getItem will return null. This null value gets wrapped into a JS::Object which isn't really useful because all reflection methods complain that null is not an object. Could we return nil instead or add a method to JS::Object to identify it being null?

My example:

null_value = JS::global[:localStorage].call('getItem', 'foobar')
p null_value.inspect
# => Uncaught TypeError: Cannot read properties of null (reading 'toString')

I'm happy to help, just not sure how we should approach this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions