Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalling nested rb Date to js Date is not working. #136

Open
awinograd opened this issue Apr 3, 2019 · 3 comments
Open

Marshalling nested rb Date to js Date is not working. #136

awinograd opened this issue Apr 3, 2019 · 3 comments
Labels

Comments

@awinograd
Copy link

ctx = MiniRacer::Context.new
ctx.eval("var foo = function (obj) { console.log(obj); }")
ctx.call("foo", { my_date: Date.today }) # JS logs => "{ my_date: "Undefined Conversion" }"

DateTime and Time both work fine. Looks like Date falls into the default case here: https://github.com/discourse/mini_racer/blob/b3c9b35859deb189586384f3ae927586a36dda14/ext/mini_racer_extension/mini_racer_extension.cc#L528

@awinograd
Copy link
Author

awinograd commented Apr 3, 2019

This may be fixed by #128 since it looks like it falls back to to_s before Undefined conversion

At least partially so as js would get the value in string form (rather than a date obj)

@tisba tisba added the bug label Feb 13, 2022
@tisba
Copy link
Collaborator

tisba commented Feb 13, 2022

Can confirm with 0.6.2. The nesting does not seem to be required, it also doesn't work when directly passing a Date object:

require "mini_racer"
require "date"

ctx = MiniRacer::Context.new
ctx.eval("var echoFn = (obj) => obj;")
ctx.call("echoFn", Date.today)
#  => "Undefined Conversion"

@awinograd Out of curiosity: How do you access the "JS logs" with MiniRacer? 🤔

@SamSaffron Am I right to assume this is a bug? Also, is there an overview on how types get translated in both directions?

@SamSaffron
Copy link
Collaborator

I would say it is kind of on the feature side of things vs bug, there is a missing conversion internally in the ruby2js part.

We should get this sorted though, agree. We should stop treating it as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants