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
13 changes: 13 additions & 0 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,19 @@ void Database::AggregateFunction(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
THROW_AND_RETURN_ON_BAD_STATE(env, !db->IsOpen(), "database is not open");
THROW_AND_RETURN_IF_IN_AUTHORIZER(env, db);

if (!args[0]->IsString()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"name\" argument must be a string.");
return;
}

if (!args[1]->IsObject()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"options\" argument must be an object.");
return;
}

Utf8Value name(env->isolate(), args[0].As<String>());
Local<Object> options = args[1].As<Object>();
Local<Value> start_v;
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-sqlite-aggregate-function.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ describe('Database.prototype.aggregate()', () => {
return fn;
}

test('throws if name is not a string', (t) => {
t.assert.throws(() => {
db.aggregate(123, { start: 0, step: () => {} });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "name" argument must be a string.'
});
});

test('throws if options is not an object', (t) => {
t.assert.throws(() => {
db.aggregate('sum');
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be an object.'
});
});

test('throws if options.start is not provided', (t) => {
t.assert.throws(() => {
db.aggregate('sum', {
Expand Down
Loading