@@ -145,19 +145,41 @@ void GitTreeEntry::NameAfterWork(uv_work_t* req) {
145145}
146146
147147Handle<Value> GitTreeEntry::FileMode (const Arguments& args) {
148- // HandleScope scope;
148+ HandleScope scope;
149149
150- // GitTreeEntry *entry = ObjectWrap::Unwrap<GitTreeEntry>(args.This());
150+ if (args.Length () == 0 || !args[0 ]->IsFunction ()) {
151+ return ThrowException (Exception::Error (String::New (" Callback is required and must be a Function." )));
152+ }
153+
154+ FileModeBaton *baton = new FileModeBaton;
155+ baton->request .data = baton;
156+ baton->rawEntry = ObjectWrap::Unwrap<GitTreeEntry>(args.This ())->GetValue ();
157+ baton->callback = Persistent<Function>::New (Local<Function>::Cast (args[0 ]));
158+
159+ uv_queue_work (uv_default_loop (), &baton->request , FileModeWork, (uv_after_work_cb)FileModeAfterWork);
151160
152- // return scope.Close(Number::New(git_tree_entry_filemode(entry->entry)));
153161 return Undefined ();
154162}
155163void GitTreeEntry::FileModeWork (uv_work_t * req) {
164+ FileModeBaton *baton = static_cast <FileModeBaton *>(req->data );
156165
157-
166+ baton-> fileMode = git_tree_entry_filemode (baton-> rawEntry );
158167}
159168void GitTreeEntry::FileModeAfterWork (uv_work_t * req) {
169+ HandleScope scope;
170+ FileModeBaton *baton = static_cast <FileModeBaton *>(req->data );
160171
172+ Handle<Value> argv[2 ] = {
173+ Local<Value>::New (Null ()),
174+ Integer::New (baton->fileMode )
175+ };
176+
177+ TryCatch try_catch;
178+ baton->callback ->Call (Context::GetCurrent ()->Global (), 2 , argv);
179+ if (try_catch.HasCaught ()) {
180+ node::FatalException (try_catch);
181+ }
182+ delete req;
161183}
162184
163185Handle<Value> GitTreeEntry::Oid (const Arguments& args) {
0 commit comments