Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 163cb7a

Browse files
committedMay 12, 2022
Don't break support for NAPI_VERSION < 6
1 parent 9fae592 commit 163cb7a

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"remote_path": "v{version}",
1515
"package_name": "napi-v{napi_build_version}-{platform}-{libc}-{arch}.tar.gz",
1616
"napi_versions": [
17+
3,
1718
6
1819
]
1920
},

‎src/statement.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ template <class T> Values::Field*
204204
else if (OtherInstanceOf(source.As<Object>(), "Date")) {
205205
return new Values::Float(pos, source.ToNumber().DoubleValue());
206206
}
207+
#if NAPI_VERSION >= 6
207208
else if (source.IsBigInt()) {
208209
bool lossless;
209210
auto ret = new Values::Integer(pos, source.As<Napi::BigInt>().Int64Value(&lossless));
@@ -218,6 +219,7 @@ template <class T> Values::Field*
218219

219220
return ret;
220221
}
222+
#endif
221223
else if (source.IsObject()) {
222224
Napi::String napiVal = source.ToString();
223225
// Check whether toString returned a value that is not undefined.
@@ -826,11 +828,13 @@ Napi::Value Statement::RowToJS(Napi::Env env, Row* row) {
826828
case SQLITE_INTEGER: {
827829
auto field_value = ((Values::Integer*)field)->value;
828830

831+
#if NAPI_VERSION >= 6
829832
if (field_value > JS_MAX_SAFE_INTEGER || field_value < JS_MIN_SAFE_INTEGER) {
830833
value = Napi::BigInt::New(env, field_value);
831-
}
832-
else {
833-
value = Napi::Number::New(env, ((Values::Integer*)field)->value);
834+
} else
835+
#endif
836+
{
837+
value = Napi::Number::New(env, field_value);
834838
}
835839
} break;
836840
case SQLITE_FLOAT: {

‎test/other_objects.test.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,25 @@ describe('data types', function() {
9696
});
9797
});
9898

99-
[
100-
1n,
101-
1337n,
102-
8876343627091516928n,
103-
-8876343627091516928n,
104-
].forEach(function (bigint) {
105-
it('should serialize BigInt ' + bigint, function (done) {
106-
db.run("INSERT INTO bigint_table VALUES(?)", bigint, function(err) {
107-
if (err) throw err;
108-
db.get("SELECT big AS bigint FROM bigint_table", function (err, row) {
109-
if (err) throw err
110-
assert.equal(row.bigint, bigint);
111-
done();
99+
if (process.versions.napi >= '6') {
100+
[
101+
1n,
102+
1337n,
103+
8876343627091516928n,
104+
-8876343627091516928n,
105+
].forEach(function (bigint) {
106+
it('should serialize BigInt ' + bigint, function (done) {
107+
db.run("INSERT INTO bigint_table VALUES(?)", bigint, function(err) {
108+
if (err) throw err;
109+
db.get("SELECT big AS bigint FROM bigint_table", function (err, row) {
110+
if (err) throw err
111+
assert.equal(row.bigint, bigint);
112+
done();
113+
});
112114
});
113115
});
114116
});
115-
});
117+
}
116118

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

0 commit comments

Comments
 (0)
Please sign in to comment.