From 3aa5b7d939409bb5abab0fd4478e44f4e643e297 Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Thu, 15 Mar 2018 17:22:30 -0700 Subject: [PATCH] n-api: add more `int64_t` tests * Updated tests for `Number` and `int32_t` * Added new tests for `int64_t` * Updated N-API `int64_t` behavior to return zero for all non-finite numbers * Clarified the documentation for these calls. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/19402 Refs: https://github.com/nodejs/node-chakracore/pull/500 Reviewed-By: Michael Dawson Reviewed-By: James M Snell --- doc/api/n-api.md | 27 ++++-- src/node_api.cc | 23 +++-- test/addons-napi/test_number/test.js | 135 ++++++++++++++++++++------- 3 files changed, 135 insertions(+), 50 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index e176cbdf1ef9cd..38d7b22f558ec2 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1806,13 +1806,17 @@ napi_status napi_get_value_int32(napi_env env, - `[out] result`: C int32 primitive equivalent of the given JavaScript Number. Returns `napi_ok` if the API succeeded. If a non-number `napi_value` -is passed in `napi_number_expected . +is passed in `napi_number_expected`. This API returns the C int32 primitive equivalent -of the given JavaScript Number. If the number exceeds the range of the -32 bit integer, then the result is truncated to the equivalent of the -bottom 32 bits. This can result in a large positive number becoming -a negative number if the value is > 2^31 -1. +of the given JavaScript Number. + +If the number exceeds the range of the 32 bit integer, then the result is +truncated to the equivalent of the bottom 32 bits. This can result in a large +positive number becoming a negative number if the value is > 2^31 -1. + +Non-finite number values (NaN, positive infinity, or negative infinity) set the +result to zero. #### napi_get_value_int64