-
Notifications
You must be signed in to change notification settings - Fork 10
From js any #7
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
From js any #7
Conversation
@JSExport | ||
object JValue { | ||
/** | ||
* Converts a Javascript object/value coming from Javascript to a [[JValue]]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say Scala.js Javascript object/value rather than just Javascript object/value. This is to clear confusion from Scala.js Javascript versus Javascript alone (which the AST also supports).
Also applies to anywhere else where it happens to be mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revered the doc for toJsAny, but I'm not sure I understand the nuance here, isn't it the case that js.Any
correspond to both Javascript values and Scala.js Javascript values?
Thanks for the pull request. I am not sure that it makes sense that any possible Scala.js javascript value can be converted to a JSON value. Doesn't I will look at the rounding error later today, definitely don't want an implementation that is needlessly losing numeric data but I have to see how Scala.js handles numbers in more detail (as to why this happening). |
For reference, this implementation was derived from https://goo.gl/4gmC13 (which return a precise error showing the parsing failed), which was in turned inspired from https://goo.gl/iQ0ANV.
Sorry for taking so long (and for such little rework). BTW the problem on number rounding still remains; I did not investigated it at all... |
Thanks, I will have a look into the rounding error |
I am going to close this. @OlivierBlanvillain I will reopen it when I you update your PR after #30 is done since a lot of changes have happened since then. |
This PR adds a
def fromJsAny(json: js.Any): JValue
method for both safe and unsafe ATDs.As illustrated in the tests, the intent is to have the following law:
I could not make this pass (I think) due to rounding errors on
JNumber
, depending on your feedback I could rework this with either static test cases or a solution to the rounding stuff.