jscl-project / jscl

A Lisp-to-JavaScript compiler bootstrapped from Common Lisp

Home Page:https://jscl-project.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getElementById error

hemml opened this issue · comments

commented

I'm trying to get element by id with:

CL-USER> (#j:document:getElementById "id")

but got the error:

ERROR: right-hand side of 'in' should be an object, got null

Good catch.

It works if the element exists, so the problem seems to be when the result of the evaluation is the null js's value.

For example, if we define window.test = null, then #j:test will give the same error.

The error is also different if used with a the primary value only.. I'll try to look further into it 👍

Okay, I think I fixed it in 3b69825.

There were quite a few places where we assumed that if something was a JS object, we could access properties from it. There could be more.. but at least this case seems to work.

Please check in master! 🙏

commented

Now it works fine, thanks!
BTW, how to check if returned value is undefined?

The javascript interop is not that great now and should be reworked. We don't have a good way of doing that.

If you would like to add it, we do have js-null-p in compiler.lisp, which is quite similar.

Otherwise, the closest thing we have is (jscl::%js-typeof |test|). But this doesn't take a value, but a symbol describing a JS variable. We could also just change that one to use a variable probably 🤔

I'll close this one for now. Feel free to open other issues as you find them! 👍

commented

Thanks a lot!
js-null-p works fine for me!