Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Query.execute() callback now is issued in the Query instance scope

  • Loading branch information...
commit 7ef22e6b8e7096be2bb5dfd54709fbfce8e17826 1 parent 5277081
@mariano authored
Showing with 8 additions and 4 deletions.
  1. +7 −4 query.cc
  2. +1 −0  query.h
View
11 query.cc
@@ -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;
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -934,6 +935,8 @@ void node_db::Query::freeRequest(execute_request_t* request, bool freeAll) {
delete request->result;
}
+ request->context.Dispose();
+
delete request;
}
}
View
1  query.h
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.