@@ -1372,12 +1372,81 @@ JavaScript DataView Objects are described in
1372
1372
[Section 24.3][] of the ECMAScript Language Specification.
1373
1373
1374
1374
### Functions to convert from C types to N-API
1375
- #### *napi_create_number *
1375
+ #### *napi_create_int32 *
1376
1376
<!-- YAML
1377
- added: v8.0.0
1377
+ added: REPLACEME
1378
+ -->
1379
+ ```C
1380
+ napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)
1381
+ ```
1382
+
1383
+ - ` [in] env ` : The environment that the API is invoked under.
1384
+ - ` [in] value ` : Integer value to be represented in JavaScript.
1385
+ - ` [out] result ` : A ` napi_value ` representing a JavaScript Number.
1386
+
1387
+ Returns ` napi_ok ` if the API succeeded.
1388
+
1389
+ This API is used to convert from the C ` int32_t ` type to the JavaScript
1390
+ Number type.
1391
+
1392
+ The JavaScript Number type is described in
1393
+ [ Section 6.1.6] ( https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type )
1394
+ of the ECMAScript Language Specification.
1395
+
1396
+ #### * napi_create_uint32*
1397
+ <!-- YAML
1398
+ added: REPLACEME
1399
+ -->
1400
+ ``` C
1401
+ napi_status napi_create_uint32 (napi_env env, uint32_t value, napi_value* result)
1402
+ ```
1403
+
1404
+ - `[in] env`: The environment that the API is invoked under.
1405
+ - `[in] value`: Unsigned integer value to be represented in JavaScript.
1406
+ - `[out] result`: A `napi_value` representing a JavaScript Number.
1407
+
1408
+ Returns `napi_ok` if the API succeeded.
1409
+
1410
+ This API is used to convert from the C `uint32_t` type to the JavaScript
1411
+ Number type.
1412
+
1413
+ The JavaScript Number type is described in
1414
+ [Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
1415
+ of the ECMAScript Language Specification.
1416
+
1417
+ #### *napi_create_int64*
1418
+ <!-- YAML
1419
+ added: REPLACEME
1420
+ -->
1421
+ ```C
1422
+ napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)
1423
+ ```
1424
+
1425
+ - ` [in] env ` : The environment that the API is invoked under.
1426
+ - ` [in] value ` : Integer value to be represented in JavaScript.
1427
+ - ` [out] result ` : A ` napi_value ` representing a JavaScript Number.
1428
+
1429
+ Returns ` napi_ok ` if the API succeeded.
1430
+
1431
+ This API is used to convert from the C ` int64_t ` type to the JavaScript
1432
+ Number type.
1433
+
1434
+ The JavaScript Number type is described in
1435
+ [ Section 6.1.6] ( https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type )
1436
+ of the ECMAScript Language Specification. Note the complete range of ` int64_t `
1437
+ cannot be represented with full precision in JavaScript. Integer values
1438
+ outside the range of
1439
+ [ ` Number.MIN_SAFE_INTEGER ` ] ( https://tc39.github.io/ecma262/#sec-number.min_safe_integer )
1440
+ -(2^53 - 1) -
1441
+ [ ` Number.MAX_SAFE_INTEGER ` ] ( https://tc39.github.io/ecma262/#sec-number.max_safe_integer )
1442
+ (2^53 - 1) will lose precision.
1443
+
1444
+ #### * napi_create_double*
1445
+ <!-- YAML
1446
+ added: REPLACEME
1378
1447
-->
1379
1448
``` C
1380
- napi_status napi_create_number (napi_env env, double value, napi_value* result)
1449
+ napi_status napi_create_double (napi_env env, double value, napi_value* result)
1381
1450
```
1382
1451
1383
1452
- `[in] env`: The environment that the API is invoked under.
@@ -1386,7 +1455,7 @@ napi_status napi_create_number(napi_env env, double value, napi_value* result)
1386
1455
1387
1456
Returns `napi_ok` if the API succeeded.
1388
1457
1389
- This API is used to convert from the C double type to the JavaScript
1458
+ This API is used to convert from the C ` double` type to the JavaScript
1390
1459
Number type.
1391
1460
1392
1461
The JavaScript Number type is described in
@@ -2170,7 +2239,7 @@ status = napi_create_object(env, &obj);
2170
2239
if (status != napi_ok) return status;
2171
2240
2172
2241
// Create a napi_value for 123
2173
- status = napi_create_number (env, 123 , &value);
2242
+ status = napi_create_int32 (env, 123 , &value);
2174
2243
if (status != napi_ok) return status;
2175
2244
2176
2245
// obj.myProp = 123
@@ -2244,9 +2313,9 @@ if (status != napi_ok) return status;
2244
2313
2245
2314
// Create napi_values for 123 and 456
2246
2315
napi_value fooValue, barValue;
2247
- status = napi_create_number (env, 123 , &fooValue);
2316
+ status = napi_create_int32 (env, 123 , &fooValue);
2248
2317
if (status != napi_ok) return status;
2249
- status = napi_create_number (env, 456 , &barValue);
2318
+ status = napi_create_int32 (env, 456 , &barValue);
2250
2319
if (status != napi_ok) return status;
2251
2320
2252
2321
// Set the properties
@@ -2707,7 +2776,7 @@ status = napi_get_named_property(env, global, "AddTwo", &add_two);
2707
2776
if (status != napi_ok) return ;
2708
2777
2709
2778
// const arg = 1337
2710
- status = napi_create_number (env, 1337 , &arg);
2779
+ status = napi_create_int32 (env, 1337 , &arg);
2711
2780
if (status != napi_ok) return ;
2712
2781
2713
2782
napi_value* argv = &arg;
0 commit comments