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

Why are toJSString/fromJSString in ghcjs-dom and not ghcjs-base? #57

Open
qrilka opened this issue Nov 3, 2016 · 2 comments
Open

Why are toJSString/fromJSString in ghcjs-dom and not ghcjs-base? #57

qrilka opened this issue Nov 3, 2016 · 2 comments

Comments

@qrilka
Copy link

qrilka commented Nov 3, 2016

Isn't JSString just a javascript string? How are functions to convert it to/from String related to DOM?

@hamishmack
Copy link
Member

The string conversion stuff in ghcjs-dom predates the ones toJSString/fromJSString in ghcjs-base. We should investigate migrating. They are subtly different though. For instance in ghcjs-dom they use toJSVal and fromJSVal (from ghcjs-base) to do the conversion. In ghcjs-base toJString/fromJSString can convert differently from toJSVal/fromJSVal for the same type. I think I prefer the ghcjs-dom approach (but could be convinced otherwise with an example of where this is useful).

Isn't JSString just a javascript string?

Yes it is. There is a bit of a wrinkle when using the old ghcjs-dom-webkit where DOMString is not a JSString (former is a C UTF8 string for use with the webkit_dom_* functions and latter is a JSStringRef for use with JavaScriptCore), but that version of ghcjs-dom should probably be considered deprecated in favour of ghcjs-dom-jsaddle.

How are functions to convert it to/from String related to DOM?

In general you will see ghcjs-dom (which is a terrible name since it has a lot more than just DOM stuff in it) exporting a lot of things that are needed to provide compatibility between the GHC and GHCJS versions of ghcjs-dom. Over time we have been trying to simply export ghcjs-base functions were possible when compiling with GHCJS. Migrating to the ghcjs-base versions of these functions would be in keeping with that effort.

@hamishmack
Copy link
Member

Hmm just looked in ghcjs-base and it looks like we disabled it in GHCJS.Foreign. I don't think @luite liked the way it worked and I don't think he was happy with they way ghcjs-dom does it either. I think the his main concern was that user would get error messages from GHC like:

Int does not have an instance of FromJSString you could try adding "instance FromJSString Int"

New users might try that and and because Int has a FromJSVal instance it would compile, but break horribly at runtime.

I think if we can come up with a solution that makes it harder to add new instances (perhaps just removing the default implementations) we could get it into ghcjs-base.

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

No branches or pull requests

2 participants