Skip to content

Can't call a function with "NaN" input when using MiniRacer #139

@dvkch

Description

@dvkch

I'm currently using ExecJS to allow mini scripts to be written in a backoffice, to create small functions that can convert an input value into another.

While using Duktape worked wonders, it doesn't support recent JS syntax (like string interpolation, String.prototype.padStart, etc), I switched to MiniRacer to avoid using an external runtime.

I am now facing the following error :

JS script
function transform(value) {
   return value
}
Ruby code
def run(value)
  ExecJS.runtime = ExecJS::Runtimes::MiniRacer
  ctx = ExecJS.compile('')
  ctx.call(js_code, value)
end
Exception
JSON::GeneratorError: NaN not allowed in JSON

This seems linked to the fact that input values are sent as JSON in MiniRacerRuntime, see

# TODO optimise generate
.

Would there be any other way to improve the situation ? I'm open to using another interpreter, but keeping a recent enough dialect of JS + disallowing external runtime seems to limit the choices only to MiniRacer (unless you are running ruby truffle)

Thanks!

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