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

More (unnecessary?) NAPI_PREAMBLE() calls #238

Closed
4 of 5 tasks
gabrielschulhof opened this issue Apr 27, 2017 · 8 comments
Closed
4 of 5 tasks

More (unnecessary?) NAPI_PREAMBLE() calls #238

gabrielschulhof opened this issue Apr 27, 2017 · 8 comments
Assignees

Comments

@gabrielschulhof
Copy link
Collaborator

We have

  • napi_is_array (val->IsArray())
  • napi_is_buffer (node::Buffer::HasInstance())
  • napi_is_arraybuffer (val->IsArrayBuffer())
  • napi_is_typedarray (val->IsTypedArray())

that have NAPI_PREAMBLE(), whereas

  • napi_is_error (val->IsNativeError())

does not have it.

I don't believe the ones above that have NAPI_PREAMBLE() need it, for the same reason that napi_typeof() doesn't need it. What do @nodejs/addon-api think?

@mhdawson
Copy link
Member

If you have checked and don't believe we need them there, I'm happy to have them be removed.

@gabrielschulhof
Copy link
Collaborator Author

gabrielschulhof commented Apr 27, 2017

The only thing I'm not sure about is whether the engine would ever throw an exception in response to IsArrayBuffer(), or IsArray() or functions of this nature. I think I'll remove the NAPI_PREAMBLE()s, because it doesn't make sense to me that it should ever throw an exception in such cases.

@jasongin
Copy link
Member

+1

The four listed above seem the most obvious, though we may also consider several other APIs that don't have any possibility of invoking JavaScript code. Does V8 ever throw exceptions when not invoking JS code? I assume not.

@gabrielschulhof
Copy link
Collaborator Author

OK, so while we're on the topic, what about these:

  • napi_get_value_string_latin1
  • napi_get_value_string_utf8
  • napi_get_value_string_utf16
  • napi_get_value_external
  • napi_get_buffer_info
  • napi_get_arraybuffer_info
  • napi_get_typedarray_info
    We should test how these functions behave if we pass in the wrong type, or, better yet CHECK_TO_<type> at the top.

@jasongin
Copy link
Member

better yet CHECK_TO_ at the top

Generally we have avoided automatic type coercions, because they can have a significant perf cost. (I think there may even be a few places currently doing type coercions that shouldn't.) If the wrong type is passed into an API, it should just return an appropriate error code.

@jasongin
Copy link
Member

And yes, I agree with adding all those getters to the list.

@gabrielschulhof
Copy link
Collaborator Author

They all have checks, so that's good.

@gabrielschulhof
Copy link
Collaborator Author

Yeah, sorry, I meant type checks, not coercions.

gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 27, 2017
These APIs do not need a try-catch around their body, because no
exceptions are thrown in their implementation:
- `napi_is_array()`
- `napi_get_value_string_latin1()`
- `napi_get_value_string_utf8()`
- `napi_get_value_string_utf16()`
- `napi_get_value_external()`
- `napi_is_buffer()`
- `napi_is_arraybuffer()`
- `napi_get_arraybuffer_info()`
- `napi_is_typedarray()`
- `napi_get_typedarray_info()`

Fixes nodejs/abi-stable-node#238
anchnk pushed a commit to anchnk/node that referenced this issue May 6, 2017
These APIs do not need a try-catch around their body, because no
exceptions are thrown in their implementation:
- `napi_is_array()`
- `napi_get_value_string_latin1()`
- `napi_get_value_string_utf8()`
- `napi_get_value_string_utf16()`
- `napi_get_value_external()`
- `napi_is_buffer()`
- `napi_is_arraybuffer()`
- `napi_get_arraybuffer_info()`
- `napi_is_typedarray()`
- `napi_get_typedarray_info()`

Fixes: nodejs/abi-stable-node#238
PR-URL: nodejs#12705
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jason Ginchereau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 10, 2018
These APIs do not need a try-catch around their body, because no
exceptions are thrown in their implementation:
- `napi_is_array()`
- `napi_get_value_string_latin1()`
- `napi_get_value_string_utf8()`
- `napi_get_value_string_utf16()`
- `napi_get_value_external()`
- `napi_is_buffer()`
- `napi_is_arraybuffer()`
- `napi_get_arraybuffer_info()`
- `napi_is_typedarray()`
- `napi_get_typedarray_info()`

Fixes: nodejs/abi-stable-node#238
PR-URL: nodejs#12705
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jason Ginchereau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit to nodejs/node that referenced this issue Apr 16, 2018
These APIs do not need a try-catch around their body, because no
exceptions are thrown in their implementation:
- `napi_is_array()`
- `napi_get_value_string_latin1()`
- `napi_get_value_string_utf8()`
- `napi_get_value_string_utf16()`
- `napi_get_value_external()`
- `napi_is_buffer()`
- `napi_is_arraybuffer()`
- `napi_get_arraybuffer_info()`
- `napi_is_typedarray()`
- `napi_get_typedarray_info()`

Fixes: nodejs/abi-stable-node#238
Backport-PR-URL: #19447
PR-URL: #12705
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jason Ginchereau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
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

Successfully merging a pull request may close this issue.

3 participants