Skip to content

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

Closed

Conversation

OlivierBlanvillain
Copy link

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:

forAll { j: JValue => fromJsAny(j.toJsAny) == j }

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.

@JSExport
object JValue {
/**
* Converts a Javascript object/value coming from Javascript to a [[JValue]].
Copy link
Owner

@mdedetrich mdedetrich Jun 2, 2016

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

Copy link
Author

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?

@mdedetrich
Copy link
Owner

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 js.Any also encapsulate types such as Javascript function and whatnot (which makes no sense in JSON whatsoever)? Sounds to me that it makes more sense for fromJsAny to be return an Option[JValue] rather than just a JValue.

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.
@OlivierBlanvillain
Copy link
Author

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...

@mdedetrich
Copy link
Owner

Thanks, I will have a look into the rounding error

@mdedetrich
Copy link
Owner

mdedetrich commented Jul 4, 2017

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.

@mdedetrich mdedetrich closed this Jul 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants