diff options
author | Kyle Farnung <kfarnung@microsoft.com> | 2018-03-15 17:22:30 -0700 |
---|---|---|
committer | Kyle Farnung <kfarnung@microsoft.com> | 2018-04-08 11:31:12 -0700 |
commit | c5291682491f1b7ee328b7fe5bbd037a91b8a79c (patch) | |
tree | 4ff9bd55d75905ccdfbf8f349e90d0ee06270cd6 /src | |
parent | 08a36a06667f9b615e09df1bb79eeed5fd5c7000 (diff) | |
download | android-node-v8-c5291682491f1b7ee328b7fe5bbd037a91b8a79c.tar.gz android-node-v8-c5291682491f1b7ee328b7fe5bbd037a91b8a79c.tar.bz2 android-node-v8-c5291682491f1b7ee328b7fe5bbd037a91b8a79c.zip |
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.
PR-URL: https://github.com/nodejs/node/pull/19402
Refs: https://github.com/nodejs/node-chakracore/pull/500
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_api.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index 73c2e60d29..3a02e5effa 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -2170,15 +2170,16 @@ napi_status napi_get_value_int64(napi_env env, RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected); - // v8::Value::IntegerValue() converts NaN to INT64_MIN, inconsistent with - // v8::Value::Int32Value() that converts NaN to 0. So special-case NaN here. + // v8::Value::IntegerValue() converts NaN, +Inf, and -Inf to INT64_MIN, + // inconsistent with v8::Value::Int32Value() which converts those values to 0. + // Special-case all non-finite values to match that behavior. double doubleValue = val.As<v8::Number>()->Value(); - if (std::isnan(doubleValue)) { - *result = 0; - } else { + if (std::isfinite(doubleValue)) { // Empty context: https://github.com/nodejs/node/issues/14379 v8::Local<v8::Context> context; *result = val->IntegerValue(context).FromJust(); + } else { + *result = 0; } return napi_clear_last_error(env); |