Commit 6a3aa878 by Konstantin Käfer

make sure that we're only calling functions

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