ghcjs / ghcjs-base

base library for GHCJS for JavaScript interaction and marshalling, used by higher level libraries like JSC
MIT License
45 stars 67 forks source link

export `getJSVal` from `Data.JSString` #103

Open adnelson opened 6 years ago

adnelson commented 6 years ago

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.

hamishmack commented 6 years ago

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