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

Document how to deal with null and undefined when using pFromJSVal #87

Open
louispan opened this issue Feb 19, 2017 · 2 comments
Open

Comments

@louispan
Copy link
Contributor

AFAIK JSString should never contain null or undefined.

However, it is an instance of PFromJSVal, which means the following compilable code will crash

print . unpack . pFromJSVal $ nullRef
@hamishmack
Copy link
Member

I think the same could be said of all the instances of pFromJSVal apart from the Maybe instance. When we use pFromJSVal we have to make sure the JSVal is valid and of the correct type. If it might be null we can use something like:

print . maybe "Value was null" unpack . pFromJSVal $ nullRef

@louispan
Copy link
Contributor Author

I see. So the pFromJSVal is an 'unsafe' interface like unsafeCoerce. Maybe the comments could be updated to that effect?

@hamishmack hamishmack changed the title JSString should not be a instance of PFromJSVal Document how to deal with null and undefined when using pFromJSVal Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants