n-api: do not call into JS when that is not allowed
Check whether calling into JS is allowed before doing so.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines