Skip to content

Commit

Permalink
Query.execute() callback now is issued in the Query instance scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano committed May 31, 2011
1 parent 5277081 commit 7ef22e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions query.cc
Expand Up @@ -638,6 +638,7 @@ v8::Handle<v8::Value> node_db::Query::Execute(const v8::Arguments& args) {
query->sql.clear();
query->sql << sql;

request->context = v8::Persistent<v8::Object>::New(args.This());
request->query = query;
request->buffered = false;
request->result = NULL;
Expand Down Expand Up @@ -780,7 +781,7 @@ int node_db::Query::eioExecuteFinished(eio_req* eioRequest) {

if (request->query->cbExecute != NULL && !request->query->cbExecute->IsEmpty()) {
v8::TryCatch tryCatch;
(*(request->query->cbExecute))->Call(v8::Context::GetCurrent()->Global(), !isEmpty ? 3 : 2, argv);
(*(request->query->cbExecute))->Call(request->context, !isEmpty ? 3 : 2, argv);
if (tryCatch.HasCaught()) {
node::FatalException(tryCatch);
}
Expand All @@ -793,7 +794,7 @@ int node_db::Query::eioExecuteFinished(eio_req* eioRequest) {

if (request->query->cbExecute != NULL && !request->query->cbExecute->IsEmpty()) {
v8::TryCatch tryCatch;
(*(request->query->cbExecute))->Call(v8::Context::GetCurrent()->Global(), 1, argv);
(*(request->query->cbExecute))->Call(request->context, 1, argv);
if (tryCatch.HasCaught()) {
node::FatalException(tryCatch);
}
Expand Down Expand Up @@ -882,7 +883,7 @@ void node_db::Query::executeAsync(execute_request_t* request) {

if (this->cbExecute != NULL && !this->cbExecute->IsEmpty()) {
v8::TryCatch tryCatch;
(*(this->cbExecute))->Call(v8::Context::GetCurrent()->Global(), !isEmpty ? 3 : 2, argv);
(*(this->cbExecute))->Call(request->context, !isEmpty ? 3 : 2, argv);
if (tryCatch.HasCaught()) {
node::FatalException(tryCatch);
}
Expand All @@ -898,7 +899,7 @@ void node_db::Query::executeAsync(execute_request_t* request) {

if (this->cbExecute != NULL && !this->cbExecute->IsEmpty()) {
v8::TryCatch tryCatch;
(*(this->cbExecute))->Call(v8::Context::GetCurrent()->Global(), 1, argv);
(*(this->cbExecute))->Call(request->context, 1, argv);
if (tryCatch.HasCaught()) {
node::FatalException(tryCatch);
}
Expand Down Expand Up @@ -934,6 +935,8 @@ void node_db::Query::freeRequest(execute_request_t* request, bool freeAll) {
delete request->result;
}

request->context.Dispose();

delete request;
}
}
Expand Down
1 change: 1 addition & 0 deletions query.h
Expand Up @@ -29,6 +29,7 @@ class Query : public node::EventEmitter {
unsigned long* columnLengths;
};
struct execute_request_t {
v8::Persistent<v8::Object> context;
Query* query;
Result *result;
const char* error;
Expand Down

0 comments on commit 7ef22e6

Please sign in to comment.