Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,23 @@ void DatabaseSync::CreateTagStore(const FunctionCallbackInfo<Value>& args) {
return;
}
int capacity = 1000;
if (args.Length() > 0 && args[0]->IsNumber()) {
capacity = args[0].As<Number>()->Value();
if (args.Length() > 0 && !args[0]->IsUndefined()) {
if (!args[0]->IsNumber()) {
THROW_ERR_INVALID_ARG_TYPE(
env->isolate(),
"The \"maxSize\" argument must be a positive integer.");
return;
}
double val = args[0].As<Number>()->Value();
if (!std::isfinite(val) || std::floor(val) != val || val <= 0 ||
val > std::numeric_limits<int>::max()) {
THROW_ERR_OUT_OF_RANGE(
env->isolate(),
"The \"maxSize\" argument must be a positive integer.");
return;
}
capacity = static_cast<int>(val);
}

BaseObjectPtr<SQLTagStore> session =
SQLTagStore::Create(env, BaseObjectWeakPtr<DatabaseSync>(db), capacity);
if (!session) {
Expand Down
34 changes: 34 additions & 0 deletions test/parallel/test-sqlite-template-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,40 @@ test('TagStore capacity, size, and clear', () => {
assert.strictEqual(sql.capacity, 10);
});

test('createTagStore throws on invalid maxSize', () => {
const db = new DatabaseSync(':memory:');

assert.throws(() => db.createTagStore(0), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});

assert.throws(() => db.createTagStore(-1), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});

assert.throws(() => db.createTagStore(NaN), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});

assert.throws(() => db.createTagStore(1.5), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});

assert.throws(() => db.createTagStore('abc'), {
code: 'ERR_INVALID_ARG_TYPE',
message: /maxSize/,
});

assert.throws(() => db.createTagStore(Number.MAX_SAFE_INTEGER), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
});

test('sql.db returns the associated DatabaseSync instance', () => {
assert.strictEqual(sql.db, db);
});
Expand Down
Loading