Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ginchereau <jasongin@microsoft.com>2017-07-19 06:22:35 +0300
committerJason Ginchereau <jasongin@microsoft.com>2017-08-08 03:31:17 +0300
commitaf70c3b4781d8df928d183580b8075cd566ce0b5 (patch)
treee8aa823ca954220063269e47e35547de28e99c3c /test/addons-napi/test_object
parenta974753676536e239fbd937e6ffebb74c84d7cbb (diff)
n-api: optimize number API performance
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: https://github.com/nodejs/node/issues/14379 PR-URL: https://github.com/nodejs/node/pull/14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/addons-napi/test_object')
-rw-r--r--test/addons-napi/test_object/test_object.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/test/addons-napi/test_object/test_object.c b/test/addons-napi/test_object/test_object.c
index 663e561a35b..88ac79c170f 100644
--- a/test/addons-napi/test_object/test_object.c
+++ b/test/addons-napi/test_object/test_object.c
@@ -144,7 +144,7 @@ napi_value New(napi_env env, napi_callback_info info) {
NAPI_CALL(env, napi_create_object(env, &ret));
napi_value num;
- NAPI_CALL(env, napi_create_number(env, 987654321, &num));
+ NAPI_CALL(env, napi_create_int32(env, 987654321, &num));
NAPI_CALL(env, napi_set_named_property(env, ret, "test_number", num));
@@ -187,7 +187,7 @@ napi_value Inflate(napi_env env, napi_callback_info info) {
double double_val;
NAPI_CALL(env, napi_get_value_double(env, value, &double_val));
- NAPI_CALL(env, napi_create_number(env, double_val + 1, &value));
+ NAPI_CALL(env, napi_create_double(env, double_val + 1, &value));
NAPI_CALL(env, napi_set_property(env, obj, property_str, value));
}