node/test/js-native-api/test_bigint/test.js
legendecas 689ab46c64 n-api: return napi_invalid_arg on napi_create_bigint_words
N-API statuses shall be preferred over throwing JavaScript Errors on
checks occurred in N-APIs.

PR-URL: https://github.com/nodejs/node/pull/31312
Refs: https://github.com/nodejs/node/issues/29849
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2020-01-13 21:16:05 -08:00

46 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
const {
IsLossless,
TestInt64,
TestUint64,
TestWords,
CreateTooBigBigInt,
} = require(`./build/${common.buildType}/test_bigint`);
[
0n,
-0n,
1n,
-1n,
100n,
2121n,
-1233n,
986583n,
-976675n,
98765432213456789876546896323445679887645323232436587988766545658n,
-4350987086545760976737453646576078997096876957864353245245769809n,
].forEach((num) => {
if (num > -(2n ** 63n) && num < 2n ** 63n) {
assert.strictEqual(TestInt64(num), num);
assert.strictEqual(IsLossless(num, true), true);
} else {
assert.strictEqual(IsLossless(num, true), false);
}
if (num >= 0 && num < 2n ** 64n) {
assert.strictEqual(TestUint64(num), num);
assert.strictEqual(IsLossless(num, false), true);
} else {
assert.strictEqual(IsLossless(num, false), false);
}
assert.strictEqual(num, TestWords(num));
});
assert.throws(CreateTooBigBigInt, {
name: 'Error',
message: 'Invalid argument',
});