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

export getJSVal from Data.JSString #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adnelson
Copy link

@adnelson adnelson commented Nov 8, 2017

Since JSString is just a newtype wrapper, and because JS is unityped, getJSVal should always be safe (or at least no less safe than the way it was generated in the first place). Furthermore, being able to treat a JSString as a JSVal is often important in FFI code, as many JS functions can accept multiple "types" of values.

The alternative is to use unsafeCoerce which is not super great. Also the function is defined but not used anywhere here or exported, so why not export it.

Apologies if this has already been brought up and decided against.

Since `JSString` is just a newtype wrapper, and because JS is unityped, `getJSVal` should always be safe (or at least no *less* safe than the way it was generated in the first place). Furthermore, being able to treat a `JSString` as a `JSVal` is often important in FFI code, as many JS functions can accept multiple "types" of values.

The alternative is to use `unsafeCoerce` which is not super great. Also the function is defined but not used anywhere here or exported, so why not export it...
@hamishmack
Copy link
Member

Instead of unsafeCoerce, you should be able to use pToJSVal from GHCJS.Marshal.Pure.

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.

None yet

2 participants