Skip to content

Floats not automatically converted (but Integers are) #213

Closed
@sebnozzi

Description

@sebnozzi

This might be an issue?

It is definitely a showstopper in many situation where one does not know whether the value (coming from somewhere else) might be an Integer or a Float. In one case the call to JS will succeed and in another it will fail.

Discussed in #211

Originally posted by sebnozzi May 12, 2023
When passing parameters in a JavaScript call Integers and Strings are converted just fine; but Floats aren't.

Why is this so?

Consider this code:

require "js"

JS.global[:window].call(:alert, 123) # works
JS.global[:window].call(:alert, 123.5) # FAILS

Instead, one has to resort to this:

JS.global[:window].call(:alert, JS.eval("return 123.5")) # works

Is this intended? Am I missing something? (seems like an overkill to me)

Also see my other thread about not being able to call to_js to a Float value.

Link in "try Ruby Playground"

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