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_call_function (and maybe others) - we assume napi_value passed in is not NULL #227

Closed
gabrielschulhof opened this issue Apr 13, 2017 · 3 comments
Assignees

Comments

@gabrielschulhof
Copy link
Collaborator

napi_status napi_call_function(napi_env env,
                               napi_value recv,
                               napi_value func,
                               size_t argc,
                               const napi_value* argv,
                               napi_value* result) {
  NAPI_PREAMBLE(env);

  v8::Isolate* isolate = env->isolate;
  v8::Local<v8::Context> context = isolate->GetCurrentContext();

  v8::Local<v8::Value> v8recv = v8impl::V8LocalValueFromJsValue(recv);
...

What if recv is NULL? I am tempted to allow NULL here, because we forego an additional N-API call just to retrieve a JS undefined as a napi_value. Still, we should not assume that it's not NULL.

@gabrielschulhof gabrielschulhof self-assigned this Apr 13, 2017
@jasongin
Copy link
Member

It looks like we're missing calls to both CHECK_ARG(recv) and CHECK_ARG(func) here.

I do agree that it might make sense to allow recv to be null, though in that case I think it should substitute the global object rather than undefined.

napi_make_callback() has the same issues.

@addaleax
Copy link
Member

though in that case I think it should substitute the global object rather than undefined.

@jasongin Why? I’ve noticed that node-api does it that way too, and it looks very deliberate, but I’m still confused by that. I would say it’s an antipattern in JavaScript to let this default to global, and I wouldn’t be surprised if this tripped up users that are used to JS strict mode.

@jasongin
Copy link
Member

OK, that would be my mistake then. I didn't realize strict mode changed that behavior. (I don't normally write JavaScript code that relies on the default value of this either way.)

addaleax added a commit to addaleax/node-api that referenced this issue Apr 13, 2017
addaleax added a commit to nodejs/node-addon-api that referenced this issue Apr 14, 2017
gabrielschulhof pushed a commit to gabrielschulhof/abi-stable-node that referenced this issue Apr 20, 2017
We left out null-checks for many of the parameters passed to our APIs.
In particular, arguments of type `napi_value` were often accepted
without a null-check, even though they should never be null.

Additionally, many APIs simply returned `napi_ok` on success. This
leaves in place an error that may have occurred in a previous N-API
call. Others (those which perform `NAPI_PREAMBLE(env)` at the top)
OTOH explicitly clear the last error before proceeding. With this
modification all APIs explicitly clear the last error on success.

Fixes nodejs#227
gabrielschulhof pushed a commit to gabrielschulhof/abi-stable-node that referenced this issue Apr 20, 2017
We left out null-checks for many of the parameters passed to our APIs.
In particular, arguments of type `napi_value` were often accepted
without a null-check, even though they should never be null.

Additionally, many APIs simply returned `napi_ok` on success. This
leaves in place an error that may have occurred in a previous N-API
call. Others (those which perform `NAPI_PREAMBLE(env)` at the top)
OTOH explicitly clear the last error before proceeding. With this
modification all APIs explicitly clear the last error on success.

Fixes nodejs#227
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 23, 2017
We left out null-checks for many of the parameters passed to our APIs.
In particular, arguments of type `napi_value` were often accepted
without a null-check, even though they should never be null.

Additionally, many APIs simply returned `napi_ok` on success. This
leaves in place an error that may have occurred in a previous N-API
call. Others (those which perform `NAPI_PREAMBLE(env)` at the top)
OTOH explicitly clear the last error before proceeding. With this
modification all APIs explicitly clear the last error on success.

Fixes nodejs/abi-stable-node#227
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 10, 2018
We left out null-checks for many of the parameters passed to our APIs.
In particular, arguments of type `napi_value` were often accepted
without a null-check, even though they should never be null.

Additionally, many APIs simply returned `napi_ok` on success. This
leaves in place an error that may have occurred in a previous N-API
call. Others (those which perform `NAPI_PREAMBLE(env)` at the top)
OTOH explicitly clear the last error before proceeding. With this
modification all APIs explicitly clear the last error on success.

Fixes: nodejs/abi-stable-node#227
PR-URL: nodejs#12539
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit to nodejs/node that referenced this issue Apr 16, 2018
We left out null-checks for many of the parameters passed to our APIs.
In particular, arguments of type `napi_value` were often accepted
without a null-check, even though they should never be null.

Additionally, many APIs simply returned `napi_ok` on success. This
leaves in place an error that may have occurred in a previous N-API
call. Others (those which perform `NAPI_PREAMBLE(env)` at the top)
OTOH explicitly clear the last error before proceeding. With this
modification all APIs explicitly clear the last error on success.

Fixes: nodejs/abi-stable-node#227
Backport-PR-URL: #19447
PR-URL: #12539
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this issue Aug 24, 2022
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this issue Aug 26, 2022
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this issue Sep 19, 2022
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this issue Aug 11, 2023
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