| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4c1181d commit 584fadc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,3 +45,10 @@ assert.strictEqual(1, test_number.TestInt32Truncation(4294967297)); | |||
| 45 | 45 | assert.strictEqual(0, test_number.TestInt32Truncation(4294967296)); | |
| 46 | 46 | assert.strictEqual(-1, test_number.TestInt32Truncation(4294967295)); | |
| 47 | 47 | 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)); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,10 +45,33 @@ napi_value TestInt32Truncation(napi_env env, napi_callback_info info) { | |||
| 45 | 45 | return output; | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 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 | + | ||
| 48 | 70 | napi_value Init(napi_env env, napi_value exports) { | |
| 49 | 71 | napi_property_descriptor descriptors[] = { | |
| 50 | 72 | DECLARE_NAPI_PROPERTY("Test", Test), | |
| 51 | 73 | DECLARE_NAPI_PROPERTY("TestInt32Truncation", TestInt32Truncation), | |
| 74 | + DECLARE_NAPI_PROPERTY("TestInt64Truncation", TestInt64Truncation), | ||
| 52 | 75 | }; | |
| 53 | 76 | ||
| 54 | 77 | NAPI_CALL(env, napi_define_properties( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments