GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — n-api,test: add int64 bounds tests · nodejs/node@0c9577e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/addons-napi/test_number
    • test.js
    • test_number.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/addons-napi/test_number/test.js‎

Copy file name to clipboardExpand all lines: test/addons-napi/test_number/test.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ assert.strictEqual(1, test_number.TestInt32Truncation(4294967297));
4545
assert.strictEqual(0, test_number.TestInt32Truncation(4294967296));
4646
assert.strictEqual(-1, test_number.TestInt32Truncation(4294967295));
4747
assert.strictEqual(3, test_number.TestInt32Truncation(4294967296 * 5 + 3));
48+
49+
// validate that the boundaries of safe integer can be passed through
50+
// successfully
51+
assert.strictEqual(Number.MAX_SAFE_INTEGER,
52+
test_number.TestInt64Truncation(Number.MAX_SAFE_INTEGER));
53+
assert.strictEqual(Number.MIN_SAFE_INTEGER,
54+
test_number.TestInt64Truncation(Number.MIN_SAFE_INTEGER));
Collapse file

‎test/addons-napi/test_number/test_number.c‎

Copy file name to clipboardExpand all lines: test/addons-napi/test_number/test_number.c
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,33 @@ napi_value TestInt32Truncation(napi_env env, napi_callback_info info) {
4545
return output;
4646
}
4747

48+
napi_value TestInt64Truncation(napi_env env, napi_callback_info info) {
49+
size_t argc = 1;
50+
napi_value args[1];
51+
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
52+
53+
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
54+
55+
napi_valuetype valuetype0;
56+
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
57+
58+
NAPI_ASSERT(env, valuetype0 == napi_number,
59+
"Wrong type of arguments. Expects a number as first argument.");
60+
61+
int64_t input;
62+
NAPI_CALL(env, napi_get_value_int64(env, args[0], &input));
63+
64+
napi_value output;
65+
NAPI_CALL(env, napi_create_int64(env, input, &output));
66+
67+
return output;
68+
}
69+
4870
napi_value Init(napi_env env, napi_value exports) {
4971
napi_property_descriptor descriptors[] = {
5072
DECLARE_NAPI_PROPERTY("Test", Test),
5173
DECLARE_NAPI_PROPERTY("TestInt32Truncation", TestInt32Truncation),
74+
DECLARE_NAPI_PROPERTY("TestInt64Truncation", TestInt64Truncation),
5275
};
5376

5477
NAPI_CALL(env, napi_define_properties(

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.