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

napi_is_function #340

Closed
jorangreef opened this issue Sep 15, 2018 · 4 comments
Closed

napi_is_function #340

jorangreef opened this issue Sep 15, 2018 · 4 comments

Comments

@jorangreef
Copy link

I have looked through all the documentation, but there doesn't seem to be a way to verify that a napi_value is a JS function, e.g. using something like napi_is_function?

The reason for asking, is that I need to verify all user-supplied arguments (including a JS callback) and throw an exception before queuing async work.

@jorangreef
Copy link
Author

I just came across napi_function which can be used like this:

napi_valuetype type;
assert(napi_typeof(env, argv[0], &type) == napi_ok);
if (type != napi_function) {}

@gabrielschulhof
Copy link
Collaborator

@jorangreef yep, that's the way to ascertain whether a napi_value holds one of the primitive types + napi_external 🙂

@ralphtheninja
Copy link

@jorangreef Check out napi-macros module by @mafintosh. There might be some handy stuff for you in there. Also, maybe add a NAPI_ARGV_FUNCTION() which does this assertion?

@jorangreef
Copy link
Author

Thanks @gabrielschulhof and @ralphtheninja

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

3 participants