Skip to content

Commit

Permalink
Calling Database.connect() callback using Database context
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano committed May 27, 2011
1 parent a3a8362 commit d1db761
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
THROW_EXCEPTION("Could not create EIO request")
}

request->context = v8::Persistent<v8::Object>::New(args.This());
request->binding = binding;
request->error = NULL;

Expand Down Expand Up @@ -129,12 +130,14 @@ void node_db::Binding::connectFinished(connect_request_t* request) {

if (request->binding->cbConnect != NULL && !request->binding->cbConnect->IsEmpty()) {
v8::TryCatch tryCatch;
(*(request->binding->cbConnect))->Call(v8::Context::GetCurrent()->Global(), connected ? 2 : 1, argv);
(*(request->binding->cbConnect))->Call(request->context, connected ? 2 : 1, argv);
if (tryCatch.HasCaught()) {
node::FatalException(tryCatch);
}
}

request->context.Dispose();

delete request;
}

Expand Down
1 change: 1 addition & 0 deletions binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Binding : public node::EventEmitter {

protected:
struct connect_request_t {
v8::Persistent<v8::Object> context;
Binding* binding;
const char* error;
};
Expand Down

0 comments on commit d1db761

Please sign in to comment.