Commit 6a3aa878 by Konstantin Käfer

make sure that we're only calling functions

parent 0668424b
......@@ -53,7 +53,7 @@ void Database::Process() {
// Call all callbacks with the error object.
while (!queue.empty()) {
Call* call = queue.front();
if (!call->baton->callback.IsEmpty()) {
if (!call->baton->callback.IsEmpty() && call->baton->callback->IsFunction()) {
TRY_CATCH_CALL(handle_, call->baton->callback, 1, argv);
called = true;
}
......@@ -89,7 +89,7 @@ void Database::Process() {
void Database::Schedule(EIO_Callback callback, Baton* baton, bool exclusive = false) {
if (!open && locked) {
EXCEPTION(String::New("Database is closed"), SQLITE_MISUSE, exception);
if (!baton->callback.IsEmpty()) {
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
Local<Value> argv[] = { exception };
TRY_CATCH_CALL(handle_, baton->callback, 1, argv);
}
......@@ -183,7 +183,7 @@ int Database::EIO_AfterOpen(eio_req *req) {
argv[0] = Local<Value>::New(Null());
}
if (!baton->callback.IsEmpty()) {
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
TRY_CATCH_CALL(db->handle_, baton->callback, 1, argv);
}
else if (!db->open) {
......@@ -253,7 +253,7 @@ int Database::EIO_AfterClose(eio_req *req) {
}
// Fire callbacks.
if (!baton->callback.IsEmpty()) {
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
TRY_CATCH_CALL(db->handle_, baton->callback, 1, argv);
}
else if (db->open) {
......
......@@ -173,11 +173,13 @@ int Statement::EIO_AfterPrepare(eio_req *req) {
argv[0] = Local<Value>::New(Null());
}
fprintf(stderr, "after prepare\n");
// Fire callbacks.
if (!baton->callback.IsEmpty()) {
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
TRY_CATCH_CALL(stmt->handle_, baton->callback, 1, argv);
}
else {
else if (!stmt->prepared) {
Local<Value> args[] = { String::NewSymbol("error"), argv[0] };
EMIT_EVENT(stmt->handle_, 2, args);
}
......@@ -191,7 +193,6 @@ int Statement::EIO_AfterPrepare(eio_req *req) {
stmt->Finalize();
}
delete baton;
return 0;
}
......@@ -213,7 +214,7 @@ void Statement::Finalize(Baton* baton) {
baton->stmt->Finalize();
// Fire callback in case there was one.
if (!baton->callback.IsEmpty()) {
if (!baton->callback.IsEmpty() && baton->callback->IsFunction()) {
TRY_CATCH_CALL(baton->stmt->handle_, baton->callback, 0, NULL);
}
......@@ -247,7 +248,8 @@ void Statement::CleanQueue() {
Call* call = queue.front();
queue.pop();
if (prepared && !call->baton->callback.IsEmpty()) {
if (prepared && !call->baton->callback.IsEmpty() &&
call->baton->callback->IsFunction()) {
TRY_CATCH_CALL(handle_, call->baton->callback, 1, argv);
called = true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment