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

Cannot convert undefined or null to object #264

Open
polymorphicengine opened this issue Mar 15, 2022 · 0 comments
Open

Cannot convert undefined or null to object #264

polymorphicengine opened this issue Mar 15, 2022 · 0 comments

Comments

@polymorphicengine
Copy link

polymorphicengine commented Mar 15, 2022

Hello, I'm using the threepenny library for a code editor based on the codemirror library.

I have the following function that expects a CodeMirror editor object as input and get's triggered by pressing STR+ENTER while the editor is selected.

getValue :: JSObject -> UI String
getValue cm = callFunction $ ffi "(%1).getValue()" cm

it can apperently happen, that sometimes the argument is 'undefined' so I tried something like this:

getValue :: JSObject -> UI String
getValue cm = callFunction $ ffi "(function (a) { if (typeof a === 'undefined' || a === null) {console.log(\"hm1\"); return \"\";} else {console.log(\"okk\");  return a.getValue(); } })(%1)" cm

But this will sometimes throw

haskell.js:359 Uncaught TypeError: Cannot convert undefined or null to object
    at Object.Haskell.freeStablePtr (haskell.js:359:22)
    at eval (eval at receive (haskell.js:266:11), <anonymous>:1:9)
    at receive (haskell.js:266:11)
    at WebSocket.ws.onmessage (haskell.js:108:9)

The annoying thing is that it is not very easy to reproduce this, as it doesn't occur very often. But when it occurs it's very annoying because it crashes the editor.
I unfortunatley don't have a lot of experience with JavaScript, so I'm hoping that someone here can help me out.

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

1 participant