Skip to content

Commit

Permalink
Add a test case to cover out of range integer error
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoalencar committed Sep 24, 2021
1 parent c84ccae commit 465b1a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ template <class T> Values::Field*
return new Values::Float(pos, source.ToNumber().DoubleValue());
}
else if (source.IsBigInt()) {
bool hadLoss;
auto ret = new Values::Integer(pos, source.As<Napi::BigInt>().Int64Value(&hadLoss));
bool lossless;
auto ret = new Values::Integer(pos, source.As<Napi::BigInt>().Int64Value(&lossless));

if (!hadLoss) {
Napi::TypeError::New(
if (!lossless) {
Napi::RangeError::New(
source.Env(),
"Converting BigInt to internal representation results is not lossless.")
"Value can't be losslessly converted to 64 bit integer.")
.ThrowAsJavaScriptException();
return NULL;
}
Expand Down
14 changes: 14 additions & 0 deletions test/other_objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,18 @@ describe('data types', function() {
});
});

it('should fail to serialize larger numbers', function (done) {
const bigint = 0xffffffffffffffffffffn; // 80 bits
let error;

try {
db.run('INSERT INTO bigint_table VALUES(?)', bigint);
} catch (err) {
error = err;
} finally {
assert.notEqual(error, undefined);
done();
}
})

});

0 comments on commit 465b1a1

Please sign in to comment.