From 694b2d703a02501f288269bea7d1a5d643a83cc8 Mon Sep 17 00:00:00 2001 From: Philip Schatz Date: Sun, 1 Sep 2013 19:28:56 -0400 Subject: [PATCH 01/31] Add system dependencies for OSX install --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 70b805ba8..82ce94dc4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ $ npm install nodegit #### Install `nodegit` by cloning source from GitHub and running `node install`: #### +```` bash +# Install system dependencies +$ brew install cmake libzip +$ npm install -g node-gyp +```` + ```` bash $ git clone git://github.com/tbranyen/nodegit.git $ cd nodegit From 9365962f2a2652f89c67a07189a918ce86adef16 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 8 Sep 2013 01:40:43 +0200 Subject: [PATCH 02/31] Fixed compile error: memcpy not defined --- src/wrapper.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wrapper.cc b/src/wrapper.cc index d513cb5ad..3849c37e1 100644 --- a/src/wrapper.cc +++ b/src/wrapper.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include "../include/wrapper.h" #include "node_buffer.h" @@ -68,7 +69,7 @@ Handle Wrapper::ToBuffer(const Arguments& args) { Handle constructorArgs[1] = { Integer::New(len) }; Local nodeBuffer = bufferConstructor->NewInstance(1, constructorArgs); - memcpy(node::Buffer::Data(nodeBuffer), ObjectWrap::Unwrap(args.This())->GetValue(), len); + std::memcpy(node::Buffer::Data(nodeBuffer), ObjectWrap::Unwrap(args.This())->GetValue(), len); return scope.Close(nodeBuffer); } From 62da608e17c58b8ff6f0e827f707c560382b570f Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 8 Sep 2013 02:22:22 +0200 Subject: [PATCH 03/31] Resolved NULL for unsigned int compiler warning. --- src/branch.cc | 10 +++++----- src/commit.cc | 2 +- src/diff_list.cc | 4 ++-- src/odb.cc | 6 +++--- src/patch.cc | 26 +++++++++++++------------- src/reference.cc | 6 +++--- src/remote.cc | 2 +- src/repo.cc | 22 +++++++++++----------- src/signature.cc | 4 ++-- src/tag.cc | 2 +- src/tree.cc | 4 ++-- src/tree_builder.cc | 6 +++--- templates/convertFromV8.cc.ejs | 2 +- templates/syncFunction.cc.ejs | 2 +- 14 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/branch.cc b/src/branch.cc index e633ffce6..30a13899d 100644 --- a/src/branch.cc +++ b/src/branch.cc @@ -93,7 +93,7 @@ Handle Branch::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference *out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -220,7 +220,7 @@ Handle Branch::Move(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference *out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_new_branch_name; @@ -271,7 +271,7 @@ Handle Branch::Lookup(const Arguments& args) { return ThrowException(Exception::Error(String::New("BranchT branch_type is required."))); } - git_reference *out = NULL; + git_reference *out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -314,7 +314,7 @@ Handle Branch::Name(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference ref is required."))); } - const char *out = NULL; + const char *out = 0; git_reference * from_ref; from_ref = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -345,7 +345,7 @@ Handle Branch::Upstream(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference branch is required."))); } - git_reference *out = NULL; + git_reference *out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/commit.cc b/src/commit.cc index 43423dd35..a37a51f76 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -287,7 +287,7 @@ Handle GitCommit::NthGenAncestor(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number n is required."))); } - git_commit *ancestor = NULL; + git_commit *ancestor = 0; unsigned int from_n; from_n = (unsigned int) args[0]->ToUint32()->Value(); diff --git a/src/diff_list.cc b/src/diff_list.cc index 37691b435..4cbb5fdc6 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -182,8 +182,8 @@ Handle GitDiffList::Patch(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number idx is required."))); } - git_diff_patch *patch_out = NULL; - const git_diff_delta *delta_out = NULL; + git_diff_patch *patch_out = 0; + const git_diff_delta *delta_out = 0; size_t from_idx; from_idx = (size_t) args[0]->ToUint32()->Value(); diff --git a/src/odb.cc b/src/odb.cc index b02857571..aaac4468f 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -80,7 +80,7 @@ git_odb *GitOdb::GetValue() { Handle GitOdb::Create(const Arguments& args) { HandleScope scope; - git_odb *out = NULL; + git_odb *out = 0; int result = git_odb_new( &out @@ -112,7 +112,7 @@ Handle GitOdb::Open(const Arguments& args) { return ThrowException(Exception::Error(String::New("String objects_dir is required."))); } - git_odb *out = NULL; + git_odb *out = 0; const char * from_objects_dir; String::Utf8Value objects_dir(args[0]->ToString()); from_objects_dir = strdup(*objects_dir); @@ -268,7 +268,7 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number len is required."))); } - git_odb_object *out = NULL; + git_odb_object *out = 0; git_odb * from_db; from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_short_id; diff --git a/src/patch.cc b/src/patch.cc index a28863254..5b71c27a7 100644 --- a/src/patch.cc +++ b/src/patch.cc @@ -116,9 +116,9 @@ Handle GitPatch::Size(const Arguments& args) { Handle GitPatch::Stats(const Arguments& args) { HandleScope scope; - size_t total_context = NULL; - size_t total_additions = NULL; - size_t total_deletions = NULL; + size_t total_context = 0; + size_t total_additions = 0; + size_t total_deletions = 0; int result = git_diff_patch_line_stats( &total_context @@ -161,10 +161,10 @@ Handle GitPatch::Hunk(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } - const git_diff_range *range = NULL; - const char *header = NULL; - size_t header_len = NULL; - size_t lines_in_hunk = NULL; + const git_diff_range *range = 0; + const char *header = 0; + size_t header_len = 0; + size_t lines_in_hunk = 0; size_t from_hunk_idx; from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); @@ -249,11 +249,11 @@ Handle GitPatch::Line(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number line_of_hunk is required."))); } - char line_origin = NULL; - const char *content = NULL; - size_t content_len = NULL; - int old_lineno = NULL; - int new_lineno = NULL; + char line_origin = 0; + const char *content = 0; + size_t content_len = 0; + int old_lineno = 0; + int new_lineno = 0; size_t from_hunk_idx; from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); size_t from_line_of_hunk; @@ -303,7 +303,7 @@ Handle GitPatch::Line(const Arguments& args) { Handle GitPatch::ToString(const Arguments& args) { HandleScope scope; - char *string = NULL; + char *string = 0; int result = git_diff_patch_to_str( &string diff --git a/src/reference.cc b/src/reference.cc index 86258e948..46c344538 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -322,7 +322,7 @@ Handle GitReference::SetSymbolicTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("String target is required."))); } - git_reference *out = NULL; + git_reference *out = 0; const char * from_target; String::Utf8Value target(args[0]->ToString()); from_target = strdup(*target); @@ -360,7 +360,7 @@ Handle GitReference::setTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("Oid id is required."))); } - git_reference *out = NULL; + git_reference *out = 0; const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -594,7 +594,7 @@ Handle GitReference::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_object *out = NULL; + git_object *out = 0; git_otype from_type; from_type = (git_otype) args[0]->ToInt32()->Value(); diff --git a/src/remote.cc b/src/remote.cc index 3445111a0..8090391b8 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -280,7 +280,7 @@ Handle GitRemote::Download(const Arguments& args) { if (args[0]->IsFunction()) { Persistent::New(Local::Cast(args[0])); } else { - from_progress_cb = NULL; + from_progress_cb = 0; } baton->progress_cb = from_progress_cb; baton->payloadReference = Persistent::New(args[1]); diff --git a/src/repo.cc b/src/repo.cc index 98e598050..76b594223 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -313,7 +313,7 @@ Handle GitRepo::Workdir(const Arguments& args) { Handle GitRepo::Odb(const Arguments& args) { HandleScope scope; - git_odb *out = NULL; + git_odb *out = 0; int result = git_repository_odb( &out @@ -621,7 +621,7 @@ Handle GitRepo::CreateCommit(const Arguments& args) { String::Utf8Value update_ref(args[0]->ToString()); from_update_ref = strdup(*update_ref); } else { - from_update_ref = NULL; + from_update_ref = 0; } baton->update_ref = from_update_ref; baton->authorReference = Persistent::New(args[1]); @@ -638,7 +638,7 @@ Handle GitRepo::CreateCommit(const Arguments& args) { String::Utf8Value message_encoding(args[3]->ToString()); from_message_encoding = strdup(*message_encoding); } else { - from_message_encoding = NULL; + from_message_encoding = 0; } baton->message_encoding = from_message_encoding; baton->messageReference = Persistent::New(args[4]); @@ -934,7 +934,7 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference *out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -988,7 +988,7 @@ Handle GitRepo::CreateReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference *out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1124,7 +1124,7 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { Handle GitRepo::CreateRevWalk(const Arguments& args) { HandleScope scope; - git_revwalk *out = NULL; + git_revwalk *out = 0; int result = git_revwalk_new( &out @@ -1157,7 +1157,7 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_submodule *submodule = NULL; + git_submodule *submodule = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1203,7 +1203,7 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number use_gitlink is required."))); } - git_submodule *submodule = NULL; + git_submodule *submodule = 0; const char * from_url; String::Utf8Value url(args[0]->ToString()); from_url = strdup(*url); @@ -1800,7 +1800,7 @@ Handle GitRepo::GetReferences(const Arguments& args) { if (args[0]->IsUint32()) { from_list_flags = (unsigned int) args[0]->ToUint32()->Value(); } else { - from_list_flags = NULL; + from_list_flags = 0; } baton->list_flags = from_list_flags; baton->callback = Persistent::New(Local::Cast(args[1])); @@ -2160,7 +2160,7 @@ Handle GitRepo::Clone(const Arguments& args) { if (args[2]->IsObject()) { from_options = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); } else { - from_options = NULL; + from_options = 0; } baton->options = from_options; baton->callback = Persistent::New(Local::Cast(args[3])); @@ -2235,7 +2235,7 @@ Handle GitRepo::GetRemote(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_remote *out = NULL; + git_remote *out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/signature.cc b/src/signature.cc index de0d84051..e5387fa5e 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -88,7 +88,7 @@ Handle GitSignature::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number offset is required."))); } - git_signature *out = NULL; + git_signature *out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -140,7 +140,7 @@ Handle GitSignature::Now(const Arguments& args) { return ThrowException(Exception::Error(String::New("String email is required."))); } - git_signature *out = NULL; + git_signature *out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/tag.cc b/src/tag.cc index a0443dbb6..2111e0982 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -271,7 +271,7 @@ Handle GitTag::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Tag tag is required."))); } - git_object *tag_target_out = NULL; + git_object *tag_target_out = 0; const git_tag * from_tag; from_tag = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/tree.cc b/src/tree.cc index 3e8eaa888..1e84eb78d 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -298,7 +298,7 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { Handle GitTree::Builder(const Arguments& args) { HandleScope scope; - git_treebuilder *out = NULL; + git_treebuilder *out = 0; int result = git_treebuilder_create( &out @@ -359,7 +359,7 @@ Handle GitTree::DiffTree(const Arguments& args) { if (args[2]->IsObject()) { from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); } else { - from_opts = NULL; + from_opts = 0; } baton->opts = from_opts; baton->callback = Persistent::New(Local::Cast(args[3])); diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 798f8098a..3f261cb75 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -81,12 +81,12 @@ git_treebuilder *GitTreeBuilder::GetValue() { Handle GitTreeBuilder::Create(const Arguments& args) { HandleScope scope; - git_treebuilder *out = NULL; + git_treebuilder *out = 0; const git_tree * from_source; if (args[0]->IsObject()) { from_source = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); } else { - from_source = NULL; + from_source = 0; } int result = git_treebuilder_create( @@ -195,7 +195,7 @@ Handle GitTreeBuilder::Insert(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number filemode is required."))); } - const git_tree_entry *out = NULL; + const git_tree_entry *out = 0; const char * from_filename; String::Utf8Value filename(args[0]->ToString()); from_filename = strdup(*filename); diff --git a/templates/convertFromV8.cc.ejs b/templates/convertFromV8.cc.ejs index 9d26d998f..58f238533 100644 --- a/templates/convertFromV8.cc.ejs +++ b/templates/convertFromV8.cc.ejs @@ -26,7 +26,7 @@ <% } -%> <% if (arg.isOptional) { -%> } else { - from_<%- arg.name %> = NULL; + from_<%- arg.name %> = 0; } <% } -%> <% } -%> \ No newline at end of file diff --git a/templates/syncFunction.cc.ejs b/templates/syncFunction.cc.ejs index 599fe4a49..3044d2d50 100644 --- a/templates/syncFunction.cc.ejs +++ b/templates/syncFunction.cc.ejs @@ -13,7 +13,7 @@ Handle <%- cppClassName %>::<%- functionInfo.cppFunctionName %>(const Arg <% if (arg.shouldAlloc) { -%> <%- arg.cType %><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- arg.cType.replace('*', '') %>)); <% } else { -%> - <%- arg.cType.replace('*', '') %><%- arg.name %> = NULL; + <%- arg.cType.replace('*', '') %><%- arg.name %> = 0; <% } -%> <% } -%> <% From 6ca5347ffea01675862e50083ddddaa55291b01b Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 8 Sep 2013 03:12:29 +0200 Subject: [PATCH 04/31] Resolved a number of compiler warnings regarding return values Specifically the return values of git_index_find and git_odb_read_header. --- src/branch.cc | 10 +++---- src/commit.cc | 2 +- src/diff_list.cc | 4 +-- src/index.cc | 19 +++++-------- src/odb.cc | 50 +++++++++++++++++------------------ src/oid.cc | 2 +- src/patch.cc | 8 +++--- src/reference.cc | 6 ++--- src/repo.cc | 14 +++++----- src/signature.cc | 4 +-- src/tag.cc | 2 +- src/tree.cc | 2 +- src/tree_builder.cc | 4 +-- templates/class.cc.ejs | 13 +++++++++ templates/syncFunction.cc.ejs | 4 +-- v0.18.0.json | 3 +++ 16 files changed, 79 insertions(+), 68 deletions(-) diff --git a/src/branch.cc b/src/branch.cc index 30a13899d..cd6c94c64 100644 --- a/src/branch.cc +++ b/src/branch.cc @@ -93,7 +93,7 @@ Handle Branch::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = 0; + git_reference * out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -220,7 +220,7 @@ Handle Branch::Move(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = 0; + git_reference * out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_new_branch_name; @@ -271,7 +271,7 @@ Handle Branch::Lookup(const Arguments& args) { return ThrowException(Exception::Error(String::New("BranchT branch_type is required."))); } - git_reference *out = 0; + git_reference * out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -314,7 +314,7 @@ Handle Branch::Name(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference ref is required."))); } - const char *out = 0; + const char * out = 0; git_reference * from_ref; from_ref = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -345,7 +345,7 @@ Handle Branch::Upstream(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference branch is required."))); } - git_reference *out = 0; + git_reference * out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/commit.cc b/src/commit.cc index a37a51f76..a969aaa07 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -287,7 +287,7 @@ Handle GitCommit::NthGenAncestor(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number n is required."))); } - git_commit *ancestor = 0; + git_commit * ancestor = 0; unsigned int from_n; from_n = (unsigned int) args[0]->ToUint32()->Value(); diff --git a/src/diff_list.cc b/src/diff_list.cc index 4cbb5fdc6..9eae3e716 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -182,8 +182,8 @@ Handle GitDiffList::Patch(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number idx is required."))); } - git_diff_patch *patch_out = 0; - const git_diff_delta *delta_out = 0; + git_diff_patch * patch_out = 0; + const git_diff_delta * delta_out = 0; size_t from_idx; from_idx = (size_t) args[0]->ToUint32()->Value(); diff --git a/src/index.cc b/src/index.cc index 725192951..f54f9c790 100644 --- a/src/index.cc +++ b/src/index.cc @@ -676,34 +676,29 @@ Handle GitIndex::RemoveBypath(const Arguments& args) { } /** - * @param {Number} at_pos * @param {String} path - * @return {Number} result + * @return {Number} at_pos */ Handle GitIndex::Find(const Arguments& args) { HandleScope scope; - if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number at_pos is required."))); - } - if (args.Length() == 1 || !args[1]->IsString()) { + if (args.Length() == 0 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New("String path is required."))); } - size_t * from_at_pos; - from_at_pos = (size_t *) args[0]->ToUint32()->Value(); - const char * from_path; - String::Utf8Value path(args[1]->ToString()); + size_t at_pos = 0; + const char * from_path; + String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); int result = git_index_find( - from_at_pos + &at_pos , ObjectWrap::Unwrap(args.This())->GetValue() , from_path ); free((void *)from_path); Handle to; - to = Int32::New(result); + to = Uint32::New(at_pos); return scope.Close(to); } diff --git a/src/odb.cc b/src/odb.cc index aaac4468f..0711eb479 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -80,7 +80,7 @@ git_odb *GitOdb::GetValue() { Handle GitOdb::Create(const Arguments& args) { HandleScope scope; - git_odb *out = 0; + git_odb * out = 0; int result = git_odb_new( &out @@ -112,7 +112,7 @@ Handle GitOdb::Open(const Arguments& args) { return ThrowException(Exception::Error(String::New("String objects_dir is required."))); } - git_odb *out = 0; + git_odb * out = 0; const char * from_objects_dir; String::Utf8Value objects_dir(args[0]->ToString()); from_objects_dir = strdup(*objects_dir); @@ -268,7 +268,7 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number len is required."))); } - git_odb_object *out = 0; + git_odb_object * out = 0; git_odb * from_db; from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_short_id; @@ -300,38 +300,30 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { } /** - * @param {Number} len_out - * @param {Number} type_out * @param {Odb} db * @param {Oid} id + * @return {Number} len_out + * @return {Number} type_out */ Handle GitOdb::ReadHeader(const Arguments& args) { HandleScope scope; - if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number len_out is required."))); - } - if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type_out is required."))); - } - if (args.Length() == 2 || !args[2]->IsObject()) { + if (args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Odb db is required."))); } - if (args.Length() == 3 || !args[3]->IsObject()) { + if (args.Length() == 1 || !args[1]->IsObject()) { return ThrowException(Exception::Error(String::New("Oid id is required."))); } - size_t * from_len_out; - from_len_out = (size_t *) args[0]->ToUint32()->Value(); - git_otype * from_type_out; - from_type_out = (git_otype *) args[1]->ToInt32()->Value(); - git_odb * from_db; - from_db = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + size_t len_out = 0; + git_otype type_out = GIT_OBJ_ANY; + git_odb * from_db; + from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[3]->ToObject())->GetValue(); + from_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); int result = git_odb_read_header( - from_len_out - , from_type_out + &len_out + , &type_out , from_db , from_id ); @@ -343,7 +335,15 @@ Handle GitOdb::ReadHeader(const Arguments& args) { } } - return Undefined(); + Handle toReturn = Object::New(); + Handle to; + to = Uint32::New(len_out); + toReturn->Set(String::NewSymbol("len_out"), to); + + to = Int32::New(type_out); + toReturn->Set(String::NewSymbol("type_out"), to); + + return scope.Close(toReturn); } /** @@ -517,7 +517,7 @@ Handle GitOdb::Hash(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const void * from_data; from_data = Buffer::Data(args[0]->ToObject()); size_t from_len; @@ -563,7 +563,7 @@ Handle GitOdb::Hashfile(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_path; String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); diff --git a/src/oid.cc b/src/oid.cc index fbd8ee4a2..0f354998f 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -72,7 +72,7 @@ Handle GitOid::FromString(const Arguments& args) { return ThrowException(Exception::Error(String::New("String str is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_str; String::Utf8Value str(args[0]->ToString()); from_str = strdup(*str); diff --git a/src/patch.cc b/src/patch.cc index 5b71c27a7..1ee267a99 100644 --- a/src/patch.cc +++ b/src/patch.cc @@ -161,8 +161,8 @@ Handle GitPatch::Hunk(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } - const git_diff_range *range = 0; - const char *header = 0; + const git_diff_range * range = 0; + const char * header = 0; size_t header_len = 0; size_t lines_in_hunk = 0; size_t from_hunk_idx; @@ -250,7 +250,7 @@ Handle GitPatch::Line(const Arguments& args) { } char line_origin = 0; - const char *content = 0; + const char * content = 0; size_t content_len = 0; int old_lineno = 0; int new_lineno = 0; @@ -303,7 +303,7 @@ Handle GitPatch::Line(const Arguments& args) { Handle GitPatch::ToString(const Arguments& args) { HandleScope scope; - char *string = 0; + char * string = 0; int result = git_diff_patch_to_str( &string diff --git a/src/reference.cc b/src/reference.cc index 46c344538..a29744122 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -322,7 +322,7 @@ Handle GitReference::SetSymbolicTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("String target is required."))); } - git_reference *out = 0; + git_reference * out = 0; const char * from_target; String::Utf8Value target(args[0]->ToString()); from_target = strdup(*target); @@ -360,7 +360,7 @@ Handle GitReference::setTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("Oid id is required."))); } - git_reference *out = 0; + git_reference * out = 0; const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -594,7 +594,7 @@ Handle GitReference::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_object *out = 0; + git_object * out = 0; git_otype from_type; from_type = (git_otype) args[0]->ToInt32()->Value(); diff --git a/src/repo.cc b/src/repo.cc index 76b594223..c60013392 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -313,7 +313,7 @@ Handle GitRepo::Workdir(const Arguments& args) { Handle GitRepo::Odb(const Arguments& args) { HandleScope scope; - git_odb *out = 0; + git_odb * out = 0; int result = git_repository_odb( &out @@ -934,7 +934,7 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = 0; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -988,7 +988,7 @@ Handle GitRepo::CreateReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = 0; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1124,7 +1124,7 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { Handle GitRepo::CreateRevWalk(const Arguments& args) { HandleScope scope; - git_revwalk *out = 0; + git_revwalk * out = 0; int result = git_revwalk_new( &out @@ -1157,7 +1157,7 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_submodule *submodule = 0; + git_submodule * submodule = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1203,7 +1203,7 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number use_gitlink is required."))); } - git_submodule *submodule = 0; + git_submodule * submodule = 0; const char * from_url; String::Utf8Value url(args[0]->ToString()); from_url = strdup(*url); @@ -2235,7 +2235,7 @@ Handle GitRepo::GetRemote(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_remote *out = 0; + git_remote * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/signature.cc b/src/signature.cc index e5387fa5e..03ee935e5 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -88,7 +88,7 @@ Handle GitSignature::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number offset is required."))); } - git_signature *out = 0; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -140,7 +140,7 @@ Handle GitSignature::Now(const Arguments& args) { return ThrowException(Exception::Error(String::New("String email is required."))); } - git_signature *out = 0; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/tag.cc b/src/tag.cc index 2111e0982..5d7ee92a8 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -271,7 +271,7 @@ Handle GitTag::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Tag tag is required."))); } - git_object *tag_target_out = 0; + git_object * tag_target_out = 0; const git_tag * from_tag; from_tag = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/tree.cc b/src/tree.cc index 1e84eb78d..1ce6f5098 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -298,7 +298,7 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { Handle GitTree::Builder(const Arguments& args) { HandleScope scope; - git_treebuilder *out = 0; + git_treebuilder * out = 0; int result = git_treebuilder_create( &out diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 3f261cb75..1fa52c5e9 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -81,7 +81,7 @@ git_treebuilder *GitTreeBuilder::GetValue() { Handle GitTreeBuilder::Create(const Arguments& args) { HandleScope scope; - git_treebuilder *out = 0; + git_treebuilder * out = 0; const git_tree * from_source; if (args[0]->IsObject()) { from_source = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -195,7 +195,7 @@ Handle GitTreeBuilder::Insert(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number filemode is required."))); } - const git_tree_entry *out = 0; + const git_tree_entry * out = 0; const char * from_filename; String::Utf8Value filename(args[0]->ToString()); from_filename = strdup(*filename); diff --git a/templates/class.cc.ejs b/templates/class.cc.ejs index 1ddc9d618..1fba50578 100644 --- a/templates/class.cc.ejs +++ b/templates/class.cc.ejs @@ -9,6 +9,19 @@ else return 'Object'; } + + function isPointer(cType) { + return /\s*\*\s*$/.test(cType); + } + + function unPointer(cType) { + return cType.replace(/\s*\*\s*$/,''); + } + + function defaultValue(cType) { + if (cType === 'git_otype') { return 'GIT_OBJ_ANY'; } + else { return '0'; } + } -%> /** * This code is auto-generated; unless you know what you're doing, do not modify! diff --git a/templates/syncFunction.cc.ejs b/templates/syncFunction.cc.ejs index 3044d2d50..a7c00aa05 100644 --- a/templates/syncFunction.cc.ejs +++ b/templates/syncFunction.cc.ejs @@ -11,9 +11,9 @@ Handle <%- cppClassName %>::<%- functionInfo.cppFunctionName %>(const Arg if (!arg.isReturn) continue; -%> <% if (arg.shouldAlloc) { -%> - <%- arg.cType %><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- arg.cType.replace('*', '') %>)); + <%- arg.cType %><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- unPointer(arg.cType) %>)); <% } else { -%> - <%- arg.cType.replace('*', '') %><%- arg.name %> = 0; + <%- unPointer(arg.cType) %> <%- arg.name %> = <%- defaultValue(unPointer(arg.cType)) %>; <% } -%> <% } -%> <% diff --git a/v0.18.0.json b/v0.18.0.json index 8c781448c..932a3bf61 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -4858,6 +4858,7 @@ "args": [ { "name": "at_pos", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -6779,6 +6780,7 @@ "args": [ { "name": "len_out", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -6786,6 +6788,7 @@ }, { "name": "type_out", + "isReturn": true, "cType": "git_otype *", "cppClassName": "Int32", "jsClassName": "Number", From ada386e40f7c25c111b68ac40c9469b877721301 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 8 Sep 2013 15:21:48 +0200 Subject: [PATCH 05/31] Made the tests pass and making them self-contained --- .gitignore | 1 + package.json | 5 +++-- test/blob.js | 2 +- test/commit.js | 32 ++++++++++++++++---------------- test/difflist.js | 2 +- test/nodegit.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/npm-debug.log | 19 ------------------- test/reference.js | 2 +- test/repo.js | 42 +++++++++++++++++++++--------------------- test/tree.js | 6 +++--- test/tree_entry.js | 2 +- 11 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 test/nodegit.js delete mode 100644 test/npm-debug.log diff --git a/.gitignore b/.gitignore index 42cebca29..f1c077584 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /testing.js /out /test.git +/test/.reposCache diff --git a/package.json b/package.json index ecdcec807..e55d74acc 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,12 @@ "devDependencies": { "nodeunit": "", "rimraf": "1.0.x", - "ejs": "0.8.x" + "ejs": "0.8.x", + "ncp": "~0.4.2" }, "scripts": { "install": "node install.js", - "test": "cd test && nodeunit *.js", + "test": "cd test && nodeunit nodegit.js", "gen": "node gen.js" } } diff --git a/test/blob.js b/test/blob.js index b79adb69b..c3e9363c7 100644 --- a/test/blob.js +++ b/test/blob.js @@ -4,7 +4,7 @@ var git = require('../'), exports.content = function(test) { var testOid = git.Oid.fromString('111dd657329797f6165f52f5085f61ac976dcf04'); test.expect(1); - git.Repo.open(path.resolve('../.git'), function(err, repo) { + git.Repo.open(path.resolve('repos/workdir/.git'), function(err, repo) { repo.getBlob(testOid, function(err, blob) { test.equals(blob.toString().slice(0, 7), "@import"); test.done(); diff --git a/test/commit.js b/test/commit.js index 16515cd45..ef0b51e8e 100644 --- a/test/commit.js +++ b/test/commit.js @@ -6,7 +6,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; exports.message = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var message = commit.message(); test.equals(error, null, 'There should be no error'); @@ -18,7 +18,7 @@ exports.message = function(test) { exports.sha = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var sha = commit.sha(); test.equals(error, null, 'There should be no error'); @@ -30,7 +30,7 @@ exports.sha = function(test) { exports.time = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var time = commit.timeMs(); test.equals(error, null, 'There should be no error'); @@ -42,7 +42,7 @@ exports.time = function(test) { exports.date = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var date = commit.date(); test.equals(error, null, 'There should be no error'); @@ -54,7 +54,7 @@ exports.date = function(test) { exports.offset = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var offset = commit.offset(); test.equals(error, null, 'There should be no error'); @@ -66,7 +66,7 @@ exports.offset = function(test) { exports.author = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var author = commit.author(); test.equals(error, null, 'There should be no error'); @@ -78,7 +78,7 @@ exports.author = function(test) { exports.authorName = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var author = commit.author(); var name = author.name(); @@ -90,7 +90,7 @@ exports.authorName = function(test) { exports.authorEmail = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var author = commit.author(); var email = author.email(); @@ -102,7 +102,7 @@ exports.authorEmail = function(test) { exports.committerName = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var committer = commit.committer(); var name = committer.name(); @@ -114,7 +114,7 @@ exports.committerName = function(test) { exports.committerEmail = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { var committer = commit.committer(); var email = committer.email(); @@ -129,7 +129,7 @@ exports.committerEmail = function(test) { */ exports.improperCommitId = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit('not a proper commit sha', function(error, commit) { test.notEqual(error, null, 'Error should occur'); test.done(); @@ -142,7 +142,7 @@ exports.improperCommitId = function(test) { */ exports.history = function(test) { test.expect(4); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { test.equals(null, error, 'Getting latest branch commit should not error'); var historyCount = 0; @@ -167,7 +167,7 @@ exports.history = function(test) { */ exports.masterHead = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getBranch('master', function(error, branch) { var sha = branch.sha(); repository.getCommit(sha, function(error, commit) { @@ -185,7 +185,7 @@ exports.masterHead = function(test) { */ exports.parents = function(test) { test.expect(3); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { commit.getParents(function(error, parents) { test.equals(parents.length, 1, 'Commit should have exactly one parent'); @@ -203,7 +203,7 @@ exports.parents = function(test) { */ exports.tree = function(test) { test.expect(2); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { test.equals(error, null, 'Getting latest branch commit should not error'); @@ -226,7 +226,7 @@ exports.tree = function(test) { */ exports.getDiff = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { commit.getDiff(function(error, diff) { test.equals(diff.length, 1, 'Should be one item in parents diff trees'); diff --git a/test/difflist.js b/test/difflist.js index 6815e2d82..3c9e0f919 100644 --- a/test/difflist.js +++ b/test/difflist.js @@ -11,7 +11,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; */ exports.walkingDiffs = function(test) { test.expect(16); - git.Repo.open('../.git', function(error, repository) { + git.Repo.open('repos/workdir/.git', function(error, repository) { repository.getCommit(historyCountKnownSHA, function(error, commit) { commit.getDiff(function(error, diffList) { test.equal(null, error, 'Should not error'); diff --git a/test/nodegit.js b/test/nodegit.js new file mode 100644 index 000000000..e8192c6ad --- /dev/null +++ b/test/nodegit.js @@ -0,0 +1,45 @@ +var fs = require('fs'); +var rimraf = require('rimraf'); +var ncp = require('ncp').ncp; +var exec = require('child_process').exec; +var path = require('path'); +var async = require('async'); + +var testFiles = ['blob','difflist','oid','repo','tree_entry','commit','reference','revwalk','tree']; + +function setupReposCache(cb) { + fs.mkdir('.reposCache',function() { + async.series([ + function empty(cb) { exec('git init .reposCache/empty',cb); }, + function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git .reposCache/workdir',cb); }, + function nonrepo(cb) { + fs.mkdir('.reposCache/nonrepo',function() { + fs.writeFile('.reposCache/nonrepo/file.txt','This is a bogus file',cb); + }); + } + ],cb); + }); +} + +module.exports = { + setUp: function(cb) { + fs.exists('.reposCache',function(exists) { + if (exists) { + ncp('.reposCache','repos',cb); + } else { + setupReposCache(function(err) { + if (err) { return cb(err); } + ncp('.reposCache','repos',cb); + }); + } + }); + }, + tearDown: function(cb) { + rimraf('repos',cb); + } +}; + +for(var i in testFiles) { + var testFile = testFiles[i]; + module.exports[testFile] = require('./'+testFile); +} diff --git a/test/npm-debug.log b/test/npm-debug.log deleted file mode 100644 index b7d4604cd..000000000 --- a/test/npm-debug.log +++ /dev/null @@ -1,19 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'node', '/usr/local/bin/npm', 'run-script', 'gen' ] -2 info using npm@1.2.28 -3 info using node@v0.10.10 -4 verbose read json /Users/nkallen/Workspace/nodegit/test/package.json -5 error Error: ENOENT, open '/Users/nkallen/Workspace/nodegit/test/package.json' -6 error If you need help, you may report this log at: -6 error -6 error or email it to: -6 error -7 error System Darwin 12.3.0 -8 error command "node" "/usr/local/bin/npm" "run-script" "gen" -9 error cwd /Users/nkallen/Workspace/nodegit/test -10 error node -v v0.10.10 -11 error npm -v 1.2.28 -12 error path /Users/nkallen/Workspace/nodegit/test/package.json -13 error code ENOENT -14 error errno 34 -15 verbose exit [ 34, true ] diff --git a/test/reference.js b/test/reference.js index f7e2bb1f2..e608a622f 100644 --- a/test/reference.js +++ b/test/reference.js @@ -5,7 +5,7 @@ var git = require('../'), exports.lookup = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repo) { + git.Repo.open('repos/workdir/.git', function(error, repo) { repo.getReference('refs/heads/master', function(error, reference) { test.ok(reference instanceof git.Reference); test.done(); diff --git a/test/repo.js b/test/repo.js index 886dee035..4608d0d38 100644 --- a/test/repo.js +++ b/test/repo.js @@ -7,18 +7,23 @@ var git = require('../'), * Ensure the repo method can handle opening repositories with async/sync * signatures properly. */ -exports.open = function(test){ - test.expect(2); +exports.openInvalidRepo = function(test){ + test.expect(1); // Test invalid repository - git.Repo.open('../templates', function(error, repository) { - test.equals(error.message, "Could not find repository from '../templates'"); + git.Repo.open('repos/nonrepo', function(error, repository) { + test.equals(error.message, "Could not find repository from 'repos/nonrepo'"); + test.done(); + }); +}; - // Test valid repository - git.Repo.open('../.git', function(error, repository) { - test.equals(null, error, 'Valid repository error code'); - test.done(); - }); +exports.openValidRepo = function(test){ + test.expect(1); + + // Test valid repository + git.Repo.open('repos/workdir/.git', function(error, repository) { + test.equals(null, error, 'Valid repository error code'); + test.done(); }); }; @@ -40,18 +45,13 @@ exports.nonexistentDirectory = function(test) { */ exports.init = function(test) { test.expect(2); - // Cleanup, remove test repo directory - if it exists - rimraf('./test.git', function() { - // Create bare repo and test for creation - git.Repo.init('./test.git', true, function(error, path, isBare) { - test.equals(null, error, 'Successfully created bare repository'); - // Verify repo exists - git.Repo.open('./test.git', function(error, path, repo) { - test.equals(null, error, 'Valid repository created'); - - // Cleanup, remove test repo directory - rimraf('./test.git', test.done); - }); + // Create bare repo and test for creation + git.Repo.init('repos/newrepo', true, function(error, path, isBare) { + test.equals(null, error, 'Successfully created bare repository'); + // Verify repo exists + git.Repo.open('repos/newrepo', function(error, path, repo) { + test.equals(null, error, 'Valid repository created'); + test.done(); }); }); }; diff --git a/test/tree.js b/test/tree.js index 7bb73329f..686dc4c2c 100644 --- a/test/tree.js +++ b/test/tree.js @@ -8,7 +8,7 @@ var fileCount = 512; // Number of blob & blob executabless exports.walk = function(test) { test.expect(515); - git.Repo.open('../.git', function(error, repo) { + git.Repo.open('repos/workdir/.git', function(error, repo) { repo.getCommit(sha, function(error, commit) { var entryCount = 0; commit.getTree(function(error, tree) { @@ -29,8 +29,8 @@ exports.walk = function(test) { exports.insert = function(test) { test.expect(1); - git.Repo.open('../.git', function(error, repo) { - repo.getCommit('1e7bc7fba93aabc8c76ebea41918f9ad892141ed', function(error, commit) { + git.Repo.open('repos/workdir/.git', function(error, repo) { + repo.getCommit(sha, function(error, commit) { commit.getTree(function(error, tree) { var text = "this is a file\n", buffer = new Buffer(text); diff --git a/test/tree_entry.js b/test/tree_entry.js index 4ee9b1338..eb00f9c93 100644 --- a/test/tree_entry.js +++ b/test/tree_entry.js @@ -3,7 +3,7 @@ var git = require('../'); var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; var getEntry = function(path, callback) { - git.Repo.open('../.git', function(error, repo) { + git.Repo.open('repos/workdir/.git', function(error, repo) { repo.getCommit(sha, function(error, commit) { commit.getEntry(path, callback); }); From c372842cf0b5cb0a1b5e59882fa0db933bb9d334 Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Wed, 25 Sep 2013 23:53:16 +0200 Subject: [PATCH 06/31] index_entry: Added missing fields. This adds dev, ino, mode, uid, gid, file_size, oid, flags, and flags_extended, which were previously omitted. Fixes #94. --- v0.18.0.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/v0.18.0.json b/v0.18.0.json index 932a3bf61..b58864818 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -4142,7 +4142,8 @@ { "filename": "index_entry.h", "dependencies": [ - "../include/index_time.h" + "../include/index_time.h", + "../include/oid.h" ], "jsClassName": "IndexEntry", "cppClassName": "GitIndexEntry", @@ -4167,6 +4168,79 @@ "jsClassName": "IndexTime", "copy": "git_index_time_dup" }, + { + "jsFunctionName": "dev", + "cppFunctionName": "Dev", + "name": "dev", + "cType": "unsigned int", + "cppClassName": "Uint32", + "jsClassName": "Number" + }, + { + "jsFunctionName": "ino", + "cppFunctionName": "Ino", + "name": "ino", + "cType": "unsigned int", + "cppClassName": "Uint32", + "jsClassName": "Number" + }, + { + "jsFunctionName": "mode", + "cppFunctionName": "Mode", + "name": "mode", + "cType": "uint16_t", + "cppClassName": "Integer", + "jsClassName": "Number" + }, + { + "jsFunctionName": "uid", + "cppFunctionName": "Uid", + "name": "uid", + "cType": "unsigned int", + "cppClassName": "Uint32", + "jsClassName": "Number" + }, + { + "jsFunctionName": "gid", + "cppFunctionName": "gid", + "name": "gid", + "cType": "unsigned int", + "cppClassName": "Uint32", + "jsClassName": "Number" + }, + { + "jsFunctionName": "file_size", + "cppFunctionName": "FileSize", + "name": "file_size", + "cType": "unsigned int", + "cppClassName": "Uint32", + "jsClassName": "Number" + }, + { + "jsFunctionName": "oid", + "cppFunctionName": "Oid", + "name": "oid", + "cType": "git_oid", + "cppClassName": "GitOid", + "jsClassName": "Oid", + "copy": "git_oid_dup" + }, + { + "jsFunctionName": "flags", + "cppFunctionName": "Flags", + "name": "flags", + "cType": "uint16_t", + "cppClassName": "Integer", + "jsClassName": "Number" + }, + { + "jsFunctionName": "flags_extended", + "cppFunctionName": "FlagsExtended", + "name": "flags_extended", + "cType": "uint16_t", + "cppClassName": "Integer", + "jsClassName": "Number" + }, { "jsFunctionName": "path", "cppFunctionName": "Path", From c27d9c35e3715539d941254f2ce57042b978c49c Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Thu, 26 Sep 2013 22:25:47 +0200 Subject: [PATCH 07/31] Regenerated include/index_entry.h and src/index_entry.cc after new fields were added. --- include/index_entry.h | 9 ++++ src/index_entry.cc | 116 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/include/index_entry.h b/include/index_entry.h index 0416e4f5c..7bf5fc6a8 100644 --- a/include/index_entry.h +++ b/include/index_entry.h @@ -32,6 +32,15 @@ class GitIndexEntry : public ObjectWrap { static Handle Ctime(const Arguments& args); static Handle Mtime(const Arguments& args); + static Handle Dev(const Arguments& args); + static Handle Ino(const Arguments& args); + static Handle Mode(const Arguments& args); + static Handle Uid(const Arguments& args); + static Handle gid(const Arguments& args); + static Handle FileSize(const Arguments& args); + static Handle Oid(const Arguments& args); + static Handle Flags(const Arguments& args); + static Handle FlagsExtended(const Arguments& args); static Handle Path(const Arguments& args); git_index_entry *raw; diff --git a/src/index_entry.cc b/src/index_entry.cc index 4e94a9595..933ffafda 100644 --- a/src/index_entry.cc +++ b/src/index_entry.cc @@ -11,6 +11,7 @@ #include "../include/index_entry.h" #include "../include/index_time.h" +#include "../include/oid.h" using namespace v8; using namespace node; @@ -34,6 +35,15 @@ void GitIndexEntry::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "ctime", Ctime); NODE_SET_PROTOTYPE_METHOD(tpl, "mtime", Mtime); + NODE_SET_PROTOTYPE_METHOD(tpl, "dev", Dev); + NODE_SET_PROTOTYPE_METHOD(tpl, "ino", Ino); + NODE_SET_PROTOTYPE_METHOD(tpl, "mode", Mode); + NODE_SET_PROTOTYPE_METHOD(tpl, "uid", Uid); + NODE_SET_PROTOTYPE_METHOD(tpl, "gid", gid); + NODE_SET_PROTOTYPE_METHOD(tpl, "file_size", FileSize); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); + NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags); + NODE_SET_PROTOTYPE_METHOD(tpl, "flags_extended", FlagsExtended); NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path); constructor_template = Persistent::New(tpl->GetFunction()); @@ -100,6 +110,112 @@ Handle GitIndexEntry::Mtime(const Arguments& args) { return scope.Close(to); } +Handle GitIndexEntry::Dev(const Arguments& args) { + HandleScope scope; + Handle to; + + unsigned int dev = + ObjectWrap::Unwrap(args.This())->GetValue()->dev; + + to = Uint32::New(dev); + return scope.Close(to); +} + +Handle GitIndexEntry::Ino(const Arguments& args) { + HandleScope scope; + Handle to; + + unsigned int ino = + ObjectWrap::Unwrap(args.This())->GetValue()->ino; + + to = Uint32::New(ino); + return scope.Close(to); +} + +Handle GitIndexEntry::Mode(const Arguments& args) { + HandleScope scope; + Handle to; + + uint16_t mode = + ObjectWrap::Unwrap(args.This())->GetValue()->mode; + + to = Integer::New(mode); + return scope.Close(to); +} + +Handle GitIndexEntry::Uid(const Arguments& args) { + HandleScope scope; + Handle to; + + unsigned int uid = + ObjectWrap::Unwrap(args.This())->GetValue()->uid; + + to = Uint32::New(uid); + return scope.Close(to); +} + +Handle GitIndexEntry::gid(const Arguments& args) { + HandleScope scope; + Handle to; + + unsigned int gid = + ObjectWrap::Unwrap(args.This())->GetValue()->gid; + + to = Uint32::New(gid); + return scope.Close(to); +} + +Handle GitIndexEntry::FileSize(const Arguments& args) { + HandleScope scope; + Handle to; + + unsigned int file_size = + ObjectWrap::Unwrap(args.This())->GetValue()->file_size; + + to = Uint32::New(file_size); + return scope.Close(to); +} + +Handle GitIndexEntry::Oid(const Arguments& args) { + HandleScope scope; + Handle to; + + git_oid *oid = + &ObjectWrap::Unwrap(args.This())->GetValue()->oid; + + if (oid != NULL) { + oid = (git_oid *)git_oid_dup(oid); + } + if (oid != NULL) { + to = GitOid::New((void *)oid); + } else { + to = Null(); + } + return scope.Close(to); +} + +Handle GitIndexEntry::Flags(const Arguments& args) { + HandleScope scope; + Handle to; + + uint16_t flags = + ObjectWrap::Unwrap(args.This())->GetValue()->flags; + + to = Integer::New(flags); + return scope.Close(to); +} + +Handle GitIndexEntry::FlagsExtended(const Arguments& args) { + HandleScope scope; + Handle to; + + uint16_t flags_extended = + ObjectWrap::Unwrap(args.This())->GetValue()->flags_extended; + + to = Integer::New(flags_extended); + return scope.Close(to); +} + Handle GitIndexEntry::Path(const Arguments& args) { HandleScope scope; Handle to; From db9ba9892219d69dc26f9dd193477fa7161951fd Mon Sep 17 00:00:00 2001 From: Didier Colens Date: Wed, 2 Oct 2013 09:41:10 +0200 Subject: [PATCH 08/31] new add and remove file example --- example/add-and-commit.js | 59 ++++++++++++++++++++++++++++++++++++ example/remove-and-commit.js | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 example/add-and-commit.js create mode 100644 example/remove-and-commit.js diff --git a/example/add-and-commit.js b/example/add-and-commit.js new file mode 100644 index 000000000..d9c5da2b7 --- /dev/null +++ b/example/add-and-commit.js @@ -0,0 +1,59 @@ +var git = require('../'), + path = require('path'), + fs = require('fs'), + fileName = 'newfile.txt', + fileContent = 'hello world' + ; + +/** + * This example creates a certain file `newfile.txt`, adds it to the git index and + * commits it to head. Similar to a `git add newfile.txt` followed by a `git commit` +**/ + +//open a git repo +git.Repo.open(path.resolve(__dirname, '../.git'), function(openReporError, repo) { + if (openReporError) throw openReporError; + + //create the file in the repo's workdir + fs.writeFile(path.join(repo.workdir(), fileName), fileContent, function(writeError) { + if (writeError) throw writeError; + + //add the file to the index... + repo.openIndex(function(openIndexError, index) { + if (openIndexError) throw openIndexError; + + index.read(function(readError) { + if (readError) throw readError; + + index.addByPath(fileName, function(addByPathError) { + if (addByPathError) throw addByPathError; + + index.write(function(writeError) { + if (writeError) throw writeError; + + index.writeTree(function(writeTreeError, oid) { + if (writeTreeError) throw writeTreeError; + + //get HEAD + git.Reference.oidForName(repo, 'HEAD', function(oidForName, head) { + if (oidForName) throw oidForName; + + //get latest commit (will be the parent commit) + repo.getCommit(head, function(getCommitError, parent) { + if (getCommitError) throw getCommitError; + var author = git.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60); + var committer = git.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90); + + //commit + repo.createCommit('HEAD', author, committer, 'message', oid, [parent], function(error, commitId) { + console.log("New Commit:", commitId.sha()); + }); + }); + }); + }); + }); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/example/remove-and-commit.js b/example/remove-and-commit.js new file mode 100644 index 000000000..5a4c17684 --- /dev/null +++ b/example/remove-and-commit.js @@ -0,0 +1,53 @@ +var git = require('../'), + path = require('path'), + fileName = 'newfile.txt' + ; + +/** + * This example deletes a certain file `newfile.txt`, removes it from the git index and + * commits it to head. Similar to a `git rm newfile.txt` followed by a `git commit` + * Use add-and-commit.js to create the file first. +**/ + +//open a git repo +git.Repo.open(path.resolve(__dirname, '../.git'), function(openReporError, repo) { + if (openReporError) throw openReporError; + + //remove the file from the index... + repo.openIndex(function(openIndexError, index) { + if (openIndexError) throw openIndexError; + + index.read(function(readError) { + if (readError) throw readError; + + index.removeByPath(fileName); + + index.write(function(writeError) { + if (writeError) throw writeError; + + index.writeTree(function(writeTreeError, oid) { + if (writeTreeError) throw writeTreeError; + + //get HEAD + git.Reference.oidForName(repo, 'HEAD', function(oidForName, head) { + if (oidForName) throw oidForName; + + //get latest commit (will be the parent commit) + repo.getCommit(head, function(getCommitError, parent) { + if (getCommitError) throw getCommitError; + var author = git.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60); + var committer = git.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90); + + //commit + repo.createCommit('HEAD', author, committer, 'message', oid, [parent], function(error, commitId) { + console.log("New Commit:", commitId.sha()); + // the file is removed from the git repo, use fs.unlink now to remove it + // from the filesystem. + }); + }); + }); + }); + }); + }); + }); +}); \ No newline at end of file From 4a34168b80fe706f52417106821c9cbfec630e47 Mon Sep 17 00:00:00 2001 From: dcolens Date: Wed, 2 Oct 2013 17:27:52 +0200 Subject: [PATCH 09/31] cmake 2.8 is required to build nodegit The "--build" option appeared in 2.8, some distros such as rhel provide cmake 2.6 by default and it can take a while to figure why the build fails. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 462e22e18..08a0d5140 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Building and installing ### Dependencies ### -To install `nodegit` you need `Node.js`, `python` and `cmake`. +To install `nodegit` you need `Node.js`, `python` and `cmake` (>=2.8). ### Easy install (Recommended) ### This will install and configure everything you need to use `nodegit`. From d706049488ac1139bb8bfa053c89dc4e7da4e6b4 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Fri, 4 Oct 2013 07:15:02 +0200 Subject: [PATCH 10/31] Fixed method names in reference example fixes #98 --- example/general.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/example/general.js b/example/general.js index 2a7baea94..13928c2ac 100644 --- a/example/general.js +++ b/example/general.js @@ -28,7 +28,7 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { // **nodegit** uses a simple wrapper around hash values called an `Oid`. // The oid validates that the SHA is well-formed. - var oid = git.Oid.fromString('fd373a561d63bfc0a5665608fe057f2131d81fee'); + var oid = git.Oid.fromString('c27d9c35e3715539d941254f2ce57042b978c49c'); // Most functions in in **nodegit** that take an oid will also take a // string, so for example, you can look up a commit by a string SHA or @@ -175,6 +175,7 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { }); }); + // #### Tree Parsing // A Tree is how Git represents the state of the filesystem @@ -315,8 +316,8 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { repo.getReference(referenceName, function(error, reference) { if (error) throw error; - if (reference.isOid()) { - console.log("Reference:", referenceName, reference.oid()); + if (reference.isConcrete()) { + console.log("Reference:", referenceName, reference.target()); } else if (reference.isSymbolic()) { console.log("Reference:", referenceName, reference.symbolicTarget()); } From 58f05820ae6219a936dc48efab1b76e127ce0901 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Fri, 4 Oct 2013 16:31:15 +0200 Subject: [PATCH 11/31] Fixed wrong variable name. --- lib/object.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/object.js b/lib/object.js index df6300f1b..64c774f84 100644 --- a/lib/object.js +++ b/lib/object.js @@ -18,7 +18,7 @@ git.Object.Type = { * @return {Boolean} */ git.Object.prototype.isCommit = function() { - return this.type() == Object.Type.Commit; + return this.type() == git.Object.Type.Commit; }; /** @@ -26,7 +26,7 @@ git.Object.prototype.isCommit = function() { * @return {Boolean} */ git.Object.prototype.isTree = function() { - return this.type() == Object.Type.Tree; + return this.type() == git.Object.Type.Tree; }; /** @@ -34,7 +34,7 @@ git.Object.prototype.isTree = function() { * @return {Boolean} */ git.Object.prototype.isBlob = function() { - return this.type() == Object.Type.Blob; + return this.type() == git.Object.Type.Blob; }; /** @@ -42,5 +42,5 @@ git.Object.prototype.isBlob = function() { * @return {Boolean} */ git.Object.prototype.isTag = function() { - return this.type() == Object.Type.Tag; + return this.type() == git.Object.Type.Tag; }; From a57309a4fc903750422090afbbf7a008f5e1cfa0 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Fri, 4 Oct 2013 16:32:27 +0200 Subject: [PATCH 12/31] Fixed unknown oid for general examples --- example/general.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/general.js b/example/general.js index 13928c2ac..559a42861 100644 --- a/example/general.js +++ b/example/general.js @@ -158,7 +158,7 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { // functions very similarly to the commit lookup, parsing and creation // methods, since the objects themselves are very similar. - oid = git.Oid.fromString("97f6d755647aca272e7c8003323472cefca772fc"); + oid = git.Oid.fromString("43f0ac7359e30b769f6b1714e0adbaf51bedbb65"); repo.getTag(oid, function(error, tag) { if (error) throw error; From 3109af8141c72b8100215de29954ff58b27908e0 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Fri, 4 Oct 2013 16:40:55 +0200 Subject: [PATCH 13/31] Fixed unknown commit oid --- example/new-commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/new-commit.js b/example/new-commit.js index 7fd130931..4bf733c53 100755 --- a/example/new-commit.js +++ b/example/new-commit.js @@ -7,7 +7,7 @@ var git = require('../'), git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { if (error) throw error; - repo.getCommit('0a70ef1237bc1ea50dbccd395e1a114201b75a68', function(error, commit) { + repo.getCommit('eebd0ead15d62eaf0ba276da53af43bbc3ce43ab', function(error, commit) { if (error) throw error; commit.getTree(function(error, tree) { From 586d25b5809966de7ace6be5deeec8cf3978beaf Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Sat, 5 Oct 2013 08:56:02 +0200 Subject: [PATCH 14/31] Changed default value of working dir to a existing git folder --- example/apps/git_profanity_check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/apps/git_profanity_check.js b/example/apps/git_profanity_check.js index 09f0e09db..618eb7a66 100644 --- a/example/apps/git_profanity_check.js +++ b/example/apps/git_profanity_check.js @@ -8,7 +8,7 @@ var git = require('../../'); var curses = ['add', 'swears', 'here'], - path = './.git', + path = '../../.git', branchName = 'master', reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); From 19211752b6c6bd2d1a5980f5a2dc3e78ecc97add Mon Sep 17 00:00:00 2001 From: Kris Ciccarello Date: Mon, 7 Oct 2013 10:28:06 -0400 Subject: [PATCH 15/31] Changed v0.18.0.json so diffWorkDir DiffOptions argument is optional. Added .idea to .gitignore to support webstorm. --- .gitignore | 1 + src/tree.cc | 9 +++++---- v0.18.0.json | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f1c077584..3c15360fc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /out /test.git /test/.reposCache +.idea diff --git a/src/tree.cc b/src/tree.cc index 1ce6f5098..4096d945b 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -536,9 +536,6 @@ Handle GitTree::DiffWorkDir(const Arguments& args) { if (args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repository repo is required."))); } - if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffOptions opts is required."))); - } if (args.Length() == 2 || !args[2]->IsFunction()) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); @@ -556,8 +553,12 @@ Handle GitTree::DiffWorkDir(const Arguments& args) { baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); baton->optsReference = Persistent::New(args[1]); const git_diff_options * from_opts; + if (args[1]->IsObject()) { from_opts = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->opts = from_opts; + } else { + from_opts = 0; + } + baton->opts = from_opts; baton->callback = Persistent::New(Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, DiffWorkDirWork, (uv_after_work_cb)DiffWorkDirAfterWork); diff --git a/v0.18.0.json b/v0.18.0.json index b58864818..1fe9ce996 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -17064,6 +17064,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ], From a93de760bbc4018e6372b5fb0aee39bc0cbb0ce6 Mon Sep 17 00:00:00 2001 From: Kris Ciccarello Date: Mon, 7 Oct 2013 21:04:42 -0400 Subject: [PATCH 16/31] Updated v0.18.0.json to make the index and DiffOptions arguments in tree.diffIndex optional (libgit2 supports null for both) --- src/tree.cc | 18 ++++++++++-------- v0.18.0.json | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/tree.cc b/src/tree.cc index 4096d945b..398012ddf 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -435,12 +435,6 @@ Handle GitTree::DiffIndex(const Arguments& args) { if (args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repository repo is required."))); } - if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Index index is required."))); - } - if (args.Length() == 2 || !args[2]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffOptions opts is required."))); - } if (args.Length() == 3 || !args[3]->IsFunction()) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); @@ -458,12 +452,20 @@ Handle GitTree::DiffIndex(const Arguments& args) { baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); baton->indexReference = Persistent::New(args[1]); git_index * from_index; + if (args[1]->IsObject()) { from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->index = from_index; + } else { + from_index = 0; + } + baton->index = from_index; baton->optsReference = Persistent::New(args[2]); const git_diff_options * from_opts; + if (args[2]->IsObject()) { from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - baton->opts = from_opts; + } else { + from_opts = 0; + } + baton->opts = from_opts; baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, DiffIndexWork, (uv_after_work_cb)DiffIndexAfterWork); diff --git a/v0.18.0.json b/v0.18.0.json index 1fe9ce996..9ae029ae2 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -17010,6 +17010,7 @@ "cType": "git_index *", "cppClassName": "GitIndex", "jsClassName": "Index", + "isOptional": true, "comment": "The index to diff with; repo index used if NULL." }, { @@ -17017,6 +17018,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ], From 7f085b3169797fa41288a6e12bda4f36148e1277 Mon Sep 17 00:00:00 2001 From: Kris Ciccarello Date: Tue, 8 Oct 2013 12:06:35 -0400 Subject: [PATCH 17/31] Updated v0.18.0.json to make the index and DiffOptions arguments in Index.indexToWorkdir optional (libgit2 supports null for both) --- src/index.cc | 18 ++++++++++-------- v0.18.0.json | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/index.cc b/src/index.cc index f54f9c790..191c6ccfe 100644 --- a/src/index.cc +++ b/src/index.cc @@ -771,12 +771,6 @@ Handle GitIndex::IndexToWorkdir(const Arguments& args) { if (args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repository repo is required."))); } - if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Index index is required."))); - } - if (args.Length() == 2 || !args[2]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffOptions opts is required."))); - } if (args.Length() == 3 || !args[3]->IsFunction()) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); @@ -792,12 +786,20 @@ Handle GitIndex::IndexToWorkdir(const Arguments& args) { baton->repo = from_repo; baton->indexReference = Persistent::New(args[1]); git_index * from_index; + if (args[1]->IsObject()) { from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->index = from_index; + } else { + from_index = 0; + } + baton->index = from_index; baton->optsReference = Persistent::New(args[2]); const git_diff_options * from_opts; + if (args[2]->IsObject()) { from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - baton->opts = from_opts; + } else { + from_opts = 0; + } + baton->opts = from_opts; baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, IndexToWorkdirWork, (uv_after_work_cb)IndexToWorkdirAfterWork); diff --git a/v0.18.0.json b/v0.18.0.json index 9ae029ae2..5c800ca1d 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -5439,6 +5439,7 @@ "cType": "git_index *", "cppClassName": "GitIndex", "jsClassName": "Index", + "isOptional": true, "comment": "The index to diff from; repo index used if NULL." }, { @@ -5446,6 +5447,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ], From 694adc5369687c47e02642941906cfc5cb21e6c2 Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Tue, 8 Oct 2013 22:15:46 +0200 Subject: [PATCH 18/31] Duplicate git_error before passing it on as it will cross a thread boundary. --- include/functions/copy.h | 3 +++ src/functions/copy.cc | 8 ++++++++ templates/asyncFunction.cc.ejs | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/functions/copy.h b/include/functions/copy.h index fe2408740..9cc8659ef 100644 --- a/include/functions/copy.h +++ b/include/functions/copy.h @@ -1,10 +1,13 @@ #include +#include + #include "git2.h" #ifndef COPY_FUNCTIONS #define COPY_FUNCTIONS +const git_error *git_error_dup(const git_error *arg); const git_oid *git_oid_dup(const git_oid *arg); const git_index_entry *git_index_entry_dup(const git_index_entry *arg); const git_index_time *git_index_time_dup(const git_index_time *arg); diff --git a/src/functions/copy.cc b/src/functions/copy.cc index c6e86ca2b..d534c3da0 100644 --- a/src/functions/copy.cc +++ b/src/functions/copy.cc @@ -1,7 +1,15 @@ #include +#include #include "git2.h" +const git_error *git_error_dup(const git_error *arg) { + git_error *result = (git_error *)malloc(sizeof(git_error)); + result->klass = arg->klass; + result->message = strdup(arg->message); + return result; +} + const git_oid *git_oid_dup(const git_oid *arg) { git_oid *result = (git_oid *)malloc(sizeof(git_oid)); git_oid_cpy(result, arg); diff --git a/templates/asyncFunction.cc.ejs b/templates/asyncFunction.cc.ejs index 1a4c98347..d168aef84 100644 --- a/templates/asyncFunction.cc.ejs +++ b/templates/asyncFunction.cc.ejs @@ -1,3 +1,5 @@ +#include "../include/functions/copy.h" + /** <% include doc.cc.ejs -%> */ @@ -57,7 +59,7 @@ void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Work(uv_work_t *req <% if (functionInfo.return.isErrorCode) { -%> baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } <% } else if (functionInfo.return.cType != "void") { -%> baton->result = result; From 29276d50cc9c533998532afefeb570dbc4932fa5 Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Tue, 8 Oct 2013 22:16:25 +0200 Subject: [PATCH 19/31] Regenerated sources. --- src/index.cc | 28 ++++++++++++---- src/object.cc | 4 ++- src/odb.cc | 8 +++-- src/reference.cc | 16 ++++++--- src/remote.cc | 10 ++++-- src/repo.cc | 80 +++++++++++++++++++++++++++++++++------------ src/revwalk.cc | 36 +++++++++++++++----- src/submodule.cc | 32 +++++++++++++----- src/tag.cc | 4 ++- src/tree.cc | 16 ++++++--- src/tree_builder.cc | 4 ++- src/tree_entry.cc | 4 ++- 12 files changed, 182 insertions(+), 60 deletions(-) diff --git a/src/index.cc b/src/index.cc index f54f9c790..5fd29f75a 100644 --- a/src/index.cc +++ b/src/index.cc @@ -83,6 +83,8 @@ git_index *GitIndex::GetValue() { } +#include "../include/functions/copy.h" + /** * @param {String} index_path * @param {Index} callback @@ -121,7 +123,7 @@ void GitIndex::OpenWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -163,6 +165,8 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitIndex::Read(const Arguments& args) { @@ -192,7 +196,7 @@ void GitIndex::ReadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -227,6 +231,8 @@ void GitIndex::ReadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitIndex::Write(const Arguments& args) { @@ -256,7 +262,7 @@ void GitIndex::WriteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -291,6 +297,8 @@ void GitIndex::WriteAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Tree} tree */ @@ -329,7 +337,7 @@ void GitIndex::ReadTreeWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -365,6 +373,8 @@ void GitIndex::ReadTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} callback */ @@ -397,7 +407,7 @@ void GitIndex::WriteTreeWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -570,6 +580,8 @@ Handle GitIndex::RemoveDirectory(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {String} path */ @@ -609,7 +621,7 @@ void GitIndex::AddBypathWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -760,6 +772,8 @@ Handle GitIndex::HasConflicts(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Index} index @@ -815,7 +829,7 @@ void GitIndex::IndexToWorkdirWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/object.cc b/src/object.cc index efb43047b..b98640bfb 100644 --- a/src/object.cc +++ b/src/object.cc @@ -104,6 +104,8 @@ Handle GitObject::Type(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Number} target_type * @param {Object} callback @@ -144,7 +146,7 @@ void GitObject::PeelWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/odb.cc b/src/odb.cc index 0711eb479..ae44def47 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -168,6 +168,8 @@ Handle GitOdb::AddDiskAlternate(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {OdbObject} callback @@ -208,7 +210,7 @@ void GitOdb::ReadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -393,6 +395,8 @@ Handle GitOdb::Refresh(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {String} data * @param {Number} len @@ -453,7 +457,7 @@ void GitOdb::WriteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/reference.cc b/src/reference.cc index a29744122..c9be6b031 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -77,6 +77,8 @@ git_reference *GitReference::GetValue() { } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {String} name @@ -125,7 +127,7 @@ void GitReference::OidForNameWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -240,6 +242,8 @@ Handle GitReference::Name(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Reference} callback */ @@ -271,7 +275,7 @@ void GitReference::ResolveWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -386,6 +390,8 @@ Handle GitReference::setTarget(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {String} new_name * @param {Number} force @@ -436,7 +442,7 @@ void GitReference::RenameWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -480,6 +486,8 @@ void GitReference::RenameAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitReference::Delete(const Arguments& args) { @@ -509,7 +517,7 @@ void GitReference::DeleteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/remote.cc b/src/remote.cc index 8090391b8..73ed3a3b4 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -184,6 +184,8 @@ Handle GitRemote::SetPushUrl(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {Number} direction */ @@ -222,7 +224,7 @@ void GitRemote::ConnectWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -258,6 +260,8 @@ void GitRemote::ConnectAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Function} progress_cb * @param {void} payload @@ -300,7 +304,7 @@ void GitRemote::DownloadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -370,6 +374,8 @@ Handle GitRemote::Stop(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** */ Handle GitRemote::Disconnect(const Arguments& args) { diff --git a/src/repo.cc b/src/repo.cc index c60013392..b2de39821 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -105,6 +105,8 @@ git_repository *GitRepo::GetValue() { } +#include "../include/functions/copy.h" + /** * @param {String} path * @param {Repository} callback @@ -143,7 +145,7 @@ void GitRepo::OpenWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -185,6 +187,8 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} path * @param {Boolean} is_bare @@ -232,7 +236,7 @@ void GitRepo::InitWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -336,6 +340,8 @@ Handle GitRepo::Odb(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Index} callback */ @@ -367,7 +373,7 @@ void GitRepo::openIndexWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -408,6 +414,8 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {Blob} callback @@ -448,7 +456,7 @@ void GitRepo::GetBlobWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -490,6 +498,8 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {Commit} callback @@ -530,7 +540,7 @@ void GitRepo::GetCommitWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -572,6 +582,8 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} update_ref * @param {Signature} author @@ -686,7 +698,7 @@ void GitRepo::CreateCommitWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -740,6 +752,8 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {Number} type @@ -789,7 +803,7 @@ void GitRepo::GetObjectWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -832,6 +846,8 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} name * @param {Reference} callback @@ -873,7 +889,7 @@ void GitRepo::GetReferenceWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1022,6 +1038,8 @@ Handle GitRepo::CreateReference(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {String} name * @param {String} url @@ -1073,7 +1091,7 @@ void GitRepo::AddRemoteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1239,6 +1257,8 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {Tag} callback @@ -1279,7 +1299,7 @@ void GitRepo::GetTagWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1321,6 +1341,8 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} tag_name * @param {Object} target @@ -1400,7 +1422,7 @@ void GitRepo::CreateTagWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1449,6 +1471,8 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} tag_name * @param {Object} target @@ -1509,7 +1533,7 @@ void GitRepo::CreateLightweightTagWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1555,6 +1579,8 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @param {Tree} callback @@ -1595,7 +1621,7 @@ void GitRepo::GetTreeWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1637,6 +1663,8 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitRepo::ReloadSubmodules(const Arguments& args) { @@ -1666,7 +1694,7 @@ void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1701,6 +1729,8 @@ void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} tag_name */ @@ -1740,7 +1770,7 @@ void GitRepo::DeleteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1777,6 +1807,8 @@ void GitRepo::DeleteAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Number} list_flags * @param {Array} callback @@ -1819,7 +1851,7 @@ void GitRepo::GetReferencesWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1865,6 +1897,8 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Buffer} buffer * @param {Number} len @@ -1915,7 +1949,7 @@ void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -1959,6 +1993,8 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} path * @param {Oid} callback @@ -2001,7 +2037,7 @@ void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -2045,6 +2081,8 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Array} callback */ @@ -2077,7 +2115,7 @@ void GitRepo::GetRemotesWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -2122,6 +2160,8 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} url * @param {String} local_path @@ -2180,7 +2220,7 @@ void GitRepo::CloneWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/revwalk.cc b/src/revwalk.cc index ec5ff3c5d..493805297 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -86,6 +86,8 @@ Handle GitRevWalk::Reset(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {Oid} id */ @@ -124,7 +126,7 @@ void GitRevWalk::PushWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -160,6 +162,8 @@ void GitRevWalk::PushAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} glob */ @@ -199,7 +203,7 @@ void GitRevWalk::PushGlobWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -236,6 +240,8 @@ void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitRevWalk::PushHead(const Arguments& args) { @@ -265,7 +271,7 @@ void GitRevWalk::PushHeadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -300,6 +306,8 @@ void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} commit_id */ @@ -338,7 +346,7 @@ void GitRevWalk::HideWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -374,6 +382,8 @@ void GitRevWalk::HideAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} glob */ @@ -413,7 +423,7 @@ void GitRevWalk::HideGlobWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -450,6 +460,8 @@ void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitRevWalk::HideHead(const Arguments& args) { @@ -479,7 +491,7 @@ void GitRevWalk::HideHeadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -514,6 +526,8 @@ void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} refname */ @@ -553,7 +567,7 @@ void GitRevWalk::PushRefWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -590,6 +604,8 @@ void GitRevWalk::PushRefAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} refname */ @@ -629,7 +645,7 @@ void GitRevWalk::HideRefWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -666,6 +682,8 @@ void GitRevWalk::HideRefAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} callback */ @@ -698,7 +716,7 @@ void GitRevWalk::NextWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/submodule.cc b/src/submodule.cc index d6b968a0b..700cc735d 100644 --- a/src/submodule.cc +++ b/src/submodule.cc @@ -76,6 +76,8 @@ git_submodule *GitSubmodule::GetValue() { } +#include "../include/functions/copy.h" + /** */ Handle GitSubmodule::AddFinalize(const Arguments& args) { @@ -105,7 +107,7 @@ void GitSubmodule::AddFinalizeWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -140,6 +142,8 @@ void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Number} write_index */ @@ -178,7 +182,7 @@ void GitSubmodule::AddToIndexWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -214,6 +218,8 @@ void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitSubmodule::Save(const Arguments& args) { @@ -243,7 +249,7 @@ void GitSubmodule::SaveWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -401,6 +407,8 @@ Handle GitSubmodule::HeadId(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Number} overwrite */ @@ -439,7 +447,7 @@ void GitSubmodule::InitWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -475,6 +483,8 @@ void GitSubmodule::InitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitSubmodule::Sync(const Arguments& args) { @@ -504,7 +514,7 @@ void GitSubmodule::SyncWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -539,6 +549,8 @@ void GitSubmodule::SyncAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Repository} callback */ @@ -570,7 +582,7 @@ void GitSubmodule::OpenWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -611,6 +623,8 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ Handle GitSubmodule::Reload(const Arguments& args) { @@ -640,7 +654,7 @@ void GitSubmodule::ReloadWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -675,6 +689,8 @@ void GitSubmodule::ReloadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Number} status */ @@ -713,7 +729,7 @@ void GitSubmodule::StatusWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/tag.cc b/src/tag.cc index 5d7ee92a8..b5628d7a8 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -95,6 +95,8 @@ Handle GitTag::Oid(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Object} callback */ @@ -126,7 +128,7 @@ void GitTag::GetTargetWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/tree.cc b/src/tree.cc index 398012ddf..0a916eadd 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -208,6 +208,8 @@ Handle GitTree::EntryByOid(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {String} path * @param {TreeEntry} callback @@ -249,7 +251,7 @@ void GitTree::GetEntryWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -321,6 +323,8 @@ Handle GitTree::Builder(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Tree} new_tree @@ -380,7 +384,7 @@ void GitTree::DiffTreeWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -424,6 +428,8 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Index} index @@ -484,7 +490,7 @@ void GitTree::DiffIndexWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } @@ -528,6 +534,8 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {DiffOptions} opts @@ -578,7 +586,7 @@ void GitTree::DiffWorkDirWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 1fa52c5e9..4d8fc34ca 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -261,6 +261,8 @@ Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) { return Undefined(); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Oid} callback @@ -302,7 +304,7 @@ void GitTreeBuilder::WriteWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } diff --git a/src/tree_entry.cc b/src/tree_entry.cc index a2f4aa7a6..844709167 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -139,6 +139,8 @@ Handle GitTreeEntry::filemode(const Arguments& args) { return scope.Close(to); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Object} callback @@ -179,7 +181,7 @@ void GitTreeEntry::GetObjectWork(uv_work_t *req) { ); baton->error_code = result; if (result != GIT_OK) { - baton->error = giterr_last(); + baton->error = git_error_dup(giterr_last()); } } From 7822faccaf2fd9dd933039550a9a2ab236132fc7 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 8 Oct 2013 21:34:43 -0400 Subject: [PATCH 20/31] Checking for nulls; freeing memory --- src/index.cc | 35 +++++++++--- src/object.cc | 5 +- src/odb.cc | 10 +++- src/reference.cc | 20 +++++-- src/remote.cc | 13 ++++- src/repo.cc | 100 ++++++++++++++++++++++++++------- src/revwalk.cc | 45 ++++++++++++--- src/submodule.cc | 40 ++++++++++--- src/tag.cc | 5 +- src/tree.cc | 20 +++++-- src/tree_builder.cc | 5 +- src/tree_entry.cc | 5 +- templates/asyncFunction.cc.ejs | 5 +- 13 files changed, 247 insertions(+), 61 deletions(-) diff --git a/src/index.cc b/src/index.cc index 5fd29f75a..29a6dcb16 100644 --- a/src/index.cc +++ b/src/index.cc @@ -122,7 +122,7 @@ void GitIndex::OpenWork(uv_work_t *req) { baton->index_path ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -151,6 +151,9 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -195,7 +198,7 @@ void GitIndex::ReadWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -218,6 +221,9 @@ void GitIndex::ReadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -261,7 +267,7 @@ void GitIndex::WriteWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -284,6 +290,9 @@ void GitIndex::WriteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -336,7 +345,7 @@ void GitIndex::ReadTreeWork(uv_work_t *req) { baton->tree ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -359,6 +368,9 @@ void GitIndex::ReadTreeAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -406,7 +418,7 @@ void GitIndex::WriteTreeWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -435,6 +447,9 @@ void GitIndex::WriteTreeAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -620,7 +635,7 @@ void GitIndex::AddBypathWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -643,6 +658,9 @@ void GitIndex::AddBypathAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -828,7 +846,7 @@ void GitIndex::IndexToWorkdirWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -857,6 +875,9 @@ void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/object.cc b/src/object.cc index b98640bfb..a881eb29b 100644 --- a/src/object.cc +++ b/src/object.cc @@ -145,7 +145,7 @@ void GitObject::PeelWork(uv_work_t *req) { baton->target_type ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -174,6 +174,9 @@ void GitObject::PeelAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/odb.cc b/src/odb.cc index ae44def47..27ef552be 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -209,7 +209,7 @@ void GitOdb::ReadWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -238,6 +238,9 @@ void GitOdb::ReadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -456,7 +459,7 @@ void GitOdb::WriteWork(uv_work_t *req) { baton->type ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -485,6 +488,9 @@ void GitOdb::WriteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/reference.cc b/src/reference.cc index c9be6b031..1bf677a98 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -126,7 +126,7 @@ void GitReference::OidForNameWork(uv_work_t *req) { baton->name ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -155,6 +155,9 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -274,7 +277,7 @@ void GitReference::ResolveWork(uv_work_t *req) { baton->ref ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -303,6 +306,9 @@ void GitReference::ResolveAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -441,7 +447,7 @@ void GitReference::RenameWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -470,6 +476,9 @@ void GitReference::RenameAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -516,7 +525,7 @@ void GitReference::DeleteWork(uv_work_t *req) { baton->ref ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -539,6 +548,9 @@ void GitReference::DeleteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/remote.cc b/src/remote.cc index 73ed3a3b4..73f0cd81d 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -223,7 +223,7 @@ void GitRemote::ConnectWork(uv_work_t *req) { baton->direction ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -246,6 +246,9 @@ void GitRemote::ConnectAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -303,7 +306,7 @@ void GitRemote::DownloadWork(uv_work_t *req) { baton->payload ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -326,6 +329,9 @@ void GitRemote::DownloadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -423,6 +429,9 @@ void GitRemote::DisconnectAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/repo.cc b/src/repo.cc index b2de39821..e8ce988a0 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -144,7 +144,7 @@ void GitRepo::OpenWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -173,6 +173,9 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -235,7 +238,7 @@ void GitRepo::InitWork(uv_work_t *req) { baton->is_bare ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -264,6 +267,9 @@ void GitRepo::InitAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -372,7 +378,7 @@ void GitRepo::openIndexWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -401,6 +407,9 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -455,7 +464,7 @@ void GitRepo::GetBlobWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -484,6 +493,9 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -539,7 +551,7 @@ void GitRepo::GetCommitWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -568,6 +580,9 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -697,7 +712,7 @@ void GitRepo::CreateCommitWork(uv_work_t *req) { baton->parents ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -726,6 +741,9 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -802,7 +820,7 @@ void GitRepo::GetObjectWork(uv_work_t *req) { baton->type ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -831,6 +849,9 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -888,7 +909,7 @@ void GitRepo::GetReferenceWork(uv_work_t *req) { baton->name ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -917,6 +938,9 @@ void GitRepo::GetReferenceAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1090,7 +1114,7 @@ void GitRepo::AddRemoteWork(uv_work_t *req) { baton->url ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1119,6 +1143,9 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1298,7 +1325,7 @@ void GitRepo::GetTagWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1327,6 +1354,9 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1421,7 +1451,7 @@ void GitRepo::CreateTagWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1450,6 +1480,9 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1532,7 +1565,7 @@ void GitRepo::CreateLightweightTagWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1561,6 +1594,9 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1620,7 +1656,7 @@ void GitRepo::GetTreeWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1649,6 +1685,9 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1693,7 +1732,7 @@ void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1716,6 +1755,9 @@ void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1769,7 +1811,7 @@ void GitRepo::DeleteWork(uv_work_t *req) { baton->tag_name ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1792,6 +1834,9 @@ void GitRepo::DeleteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1850,7 +1895,7 @@ void GitRepo::GetReferencesWork(uv_work_t *req) { baton->list_flags ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1880,6 +1925,9 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -1948,7 +1996,7 @@ void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { baton->len ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -1977,6 +2025,9 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -2036,7 +2087,7 @@ void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -2065,6 +2116,9 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -2114,7 +2168,7 @@ void GitRepo::GetRemotesWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -2144,6 +2198,9 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -2219,7 +2276,7 @@ void GitRepo::CloneWork(uv_work_t *req) { baton->options ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -2248,6 +2305,9 @@ void GitRepo::CloneAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/revwalk.cc b/src/revwalk.cc index 493805297..bdb4ce47d 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -125,7 +125,7 @@ void GitRevWalk::PushWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -148,6 +148,9 @@ void GitRevWalk::PushAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -202,7 +205,7 @@ void GitRevWalk::PushGlobWork(uv_work_t *req) { baton->glob ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -225,6 +228,9 @@ void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -270,7 +276,7 @@ void GitRevWalk::PushHeadWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -293,6 +299,9 @@ void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -345,7 +354,7 @@ void GitRevWalk::HideWork(uv_work_t *req) { baton->commit_id ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -368,6 +377,9 @@ void GitRevWalk::HideAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -422,7 +434,7 @@ void GitRevWalk::HideGlobWork(uv_work_t *req) { baton->glob ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -445,6 +457,9 @@ void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -490,7 +505,7 @@ void GitRevWalk::HideHeadWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -513,6 +528,9 @@ void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -566,7 +584,7 @@ void GitRevWalk::PushRefWork(uv_work_t *req) { baton->refname ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -589,6 +607,9 @@ void GitRevWalk::PushRefAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -644,7 +665,7 @@ void GitRevWalk::HideRefWork(uv_work_t *req) { baton->refname ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -667,6 +688,9 @@ void GitRevWalk::HideRefAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -715,7 +739,7 @@ void GitRevWalk::NextWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -744,6 +768,9 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/submodule.cc b/src/submodule.cc index 700cc735d..8cddceb3e 100644 --- a/src/submodule.cc +++ b/src/submodule.cc @@ -106,7 +106,7 @@ void GitSubmodule::AddFinalizeWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -129,6 +129,9 @@ void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -181,7 +184,7 @@ void GitSubmodule::AddToIndexWork(uv_work_t *req) { baton->write_index ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -204,6 +207,9 @@ void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -248,7 +254,7 @@ void GitSubmodule::SaveWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -271,6 +277,9 @@ void GitSubmodule::SaveAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -446,7 +455,7 @@ void GitSubmodule::InitWork(uv_work_t *req) { baton->overwrite ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -469,6 +478,9 @@ void GitSubmodule::InitAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -513,7 +525,7 @@ void GitSubmodule::SyncWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -536,6 +548,9 @@ void GitSubmodule::SyncAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -581,7 +596,7 @@ void GitSubmodule::OpenWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -610,6 +625,9 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -653,7 +671,7 @@ void GitSubmodule::ReloadWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -676,6 +694,9 @@ void GitSubmodule::ReloadAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -728,7 +749,7 @@ void GitSubmodule::StatusWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -751,6 +772,9 @@ void GitSubmodule::StatusAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/tag.cc b/src/tag.cc index b5628d7a8..08b099d41 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -127,7 +127,7 @@ void GitTag::GetTargetWork(uv_work_t *req) { baton->tag ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -156,6 +156,9 @@ void GitTag::GetTargetAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/tree.cc b/src/tree.cc index 0a916eadd..3808df4a3 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -250,7 +250,7 @@ void GitTree::GetEntryWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -279,6 +279,9 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -383,7 +386,7 @@ void GitTree::DiffTreeWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -412,6 +415,9 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -489,7 +495,7 @@ void GitTree::DiffIndexWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -518,6 +524,9 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } @@ -585,7 +594,7 @@ void GitTree::DiffWorkDirWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -614,6 +623,9 @@ void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 4d8fc34ca..294831776 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -303,7 +303,7 @@ void GitTreeBuilder::WriteWork(uv_work_t *req) { baton->bld ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -332,6 +332,9 @@ void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 844709167..2d761e611 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -180,7 +180,7 @@ void GitTreeEntry::GetObjectWork(uv_work_t *req) { baton->entry ); baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } @@ -209,6 +209,9 @@ void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } diff --git a/templates/asyncFunction.cc.ejs b/templates/asyncFunction.cc.ejs index d168aef84..98ef78218 100644 --- a/templates/asyncFunction.cc.ejs +++ b/templates/asyncFunction.cc.ejs @@ -58,7 +58,7 @@ void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Work(uv_work_t *req ); <% if (functionInfo.return.isErrorCode) { -%> baton->error_code = result; - if (result != GIT_OK) { + if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } <% } else if (functionInfo.return.cType != "void") { -%> @@ -101,6 +101,9 @@ void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>AfterWork(uv_work_t Exception::Error(String::New(baton->error->message)) }; baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (baton->error->message) + free((void *)baton->error->message); + free((void *)baton->error); } else { baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } From 04fefbc9dc93989cd6b99846714d212067e6576c Mon Sep 17 00:00:00 2001 From: Andreas Lind Petersen Date: Sun, 13 Oct 2013 14:56:57 +0200 Subject: [PATCH 21/31] Try requiring build/Debug/nodegit if build/Release/nodegit wasn't found. --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6ca1b327d..0f47b4177 100755 --- a/index.js +++ b/index.js @@ -10,7 +10,12 @@ if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) { } // Assign raw api to module -var rawApi = require('./build/Release/nodegit'); +var rawApi; +try { + rawApi = require('./build/Release/nodegit'); +} catch (e) { + rawApi = require('./build/Debug/nodegit'); +} for (var key in rawApi) { exports[key] = rawApi[key]; } From 4a34f3be1522c988c2bec7115d53a18a7739c302 Mon Sep 17 00:00:00 2001 From: Kris Ciccarello Date: Mon, 18 Nov 2013 14:50:04 -0500 Subject: [PATCH 22/31] Added git_diff_delta_dup to git_diff_get_patch to fix a memory issue when accessing DiffList patches. --- src/diff_list.cc | 3 +++ v0.18.0.json | 1 + 2 files changed, 4 insertions(+) diff --git a/src/diff_list.cc b/src/diff_list.cc index 9eae3e716..2ef784398 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -211,6 +211,9 @@ Handle GitDiffList::Patch(const Arguments& args) { toReturn->Set(String::NewSymbol("patch"), to); if (delta_out != NULL) { + delta_out = (const git_diff_delta * )git_diff_delta_dup(delta_out); + } + if (delta_out != NULL) { to = GitDelta::New((void *)delta_out); } else { to = Null(); diff --git a/v0.18.0.json b/v0.18.0.json index 5c800ca1d..58127837d 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -3689,6 +3689,7 @@ "name": "delta_out", "jsName": "delta", "cType": "const git_diff_delta **", + "copy": "git_diff_delta_dup", "cppClassName": "GitDelta", "jsClassName": "Delta", "isReturn": true, From d46f7da82969ca6620864d79a55b951be0540bda Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Sat, 1 Mar 2014 19:34:56 +0100 Subject: [PATCH 23/31] Add Node 0.11+ Compatibility using NAN #164 --- include/blob.h | 14 +- include/branch.h | 31 +- include/clone_options.h | 7 +- include/commit.h | 31 +- include/delta.h | 16 +- include/diff.h | 26 +- include/diff_file.h | 16 +- include/diff_find_options.h | 7 +- include/diff_list.h | 20 +- include/diff_options.h | 7 +- include/diff_range.h | 14 +- include/index.h | 41 +- include/index_entry.h | 34 +- include/index_time.h | 11 +- include/object.h | 12 +- include/odb.h | 28 +- include/odb_object.h | 17 +- include/oid.h | 14 +- include/patch.h | 21 +- include/refdb.h | 7 +- include/reference.h | 39 +- include/remote.h | 41 +- include/repo.h | 64 +-- include/revwalk.h | 28 +- include/signature.h | 26 +- include/submodule.h | 35 +- include/tag.h | 23 +- include/threads.h | 12 +- include/time.h | 15 +- include/tree.h | 26 +- include/tree_builder.h | 21 +- include/tree_entry.h | 16 +- include/wrapper.h | 8 +- package.json | 3 +- src/base.cc | 2 +- src/blob.cc | 56 +- src/branch.cc | 9 +- src/clone_options.cc | 28 +- src/commit.cc | 105 ++-- src/delta.cc | 59 +- src/diff.cc | 9 +- src/diff_file.cc | 59 +- src/diff_find_options.cc | 29 +- src/diff_list.cc | 79 +-- src/diff_options.cc | 28 +- src/diff_range.cc | 53 +- src/index.cc | 360 ++++++------ src/index_entry.cc | 101 ++-- src/index_time.cc | 41 +- src/object.cc | 76 +-- src/odb.cc | 230 ++++---- src/odb_object.cc | 52 +- src/oid.cc | 46 +- src/patch.cc | 94 ++-- src/refdb.cc | 28 +- src/reference.cc | 285 +++++----- src/remote.cc | 258 ++++----- src/repo.cc | 1052 ++++++++++++++++++----------------- src/revwalk.cc | 342 ++++++------ src/signature.cc | 80 +-- src/submodule.cc | 289 +++++----- src/tag.cc | 98 ++-- src/threads.cc | 28 +- src/time.cc | 43 +- src/tree.cc | 282 +++++----- src/tree_builder.cc | 122 ++-- src/tree_entry.cc | 86 +-- src/wrapper.cc | 38 +- 68 files changed, 2703 insertions(+), 2575 deletions(-) diff --git a/include/blob.h b/include/blob.h index 561338354..94f3537bd 100755 --- a/include/blob.h +++ b/include/blob.h @@ -8,6 +8,7 @@ #include #include #include +#include "nan.h" #include "git2.h" @@ -17,7 +18,7 @@ using namespace v8; class GitBlob : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_blob *GetValue(); @@ -28,13 +29,12 @@ class GitBlob : public ObjectWrap { GitBlob(git_blob *raw); ~GitBlob(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); - - static Handle Oid(const Arguments& args); - static Handle Content(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle IsBinary(const Arguments& args); + static NAN_METHOD(Oid); + static NAN_METHOD(Content); + static NAN_METHOD(Size); + static NAN_METHOD(IsBinary); git_blob *raw; }; diff --git a/include/branch.h b/include/branch.h index bfbf9bcdb..67b4eb373 100644 --- a/include/branch.h +++ b/include/branch.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class Branch : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_branch *GetValue(); @@ -28,20 +30,19 @@ class Branch : public ObjectWrap { Branch(git_branch *raw); ~Branch(); - static Handle New(const Arguments& args); - - - static Handle Create(const Arguments& args); - static Handle Delete(const Arguments& args); - static Handle Foreach(const Arguments& args); - static Handle Move(const Arguments& args); - static Handle Lookup(const Arguments& args); - static Handle Name(const Arguments& args); - static Handle Upstream(const Arguments& args); - static Handle SetUpstream(const Arguments& args); - static Handle UpstreamName(const Arguments& args); - static Handle IsHead(const Arguments& args); - static Handle RemoteName(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(Create); + static NAN_METHOD(Delete); + static NAN_METHOD(Foreach); + static NAN_METHOD(Move); + static NAN_METHOD(Lookup); + static NAN_METHOD(Name); + static NAN_METHOD(Upstream); + static NAN_METHOD(SetUpstream); + static NAN_METHOD(UpstreamName); + static NAN_METHOD(IsHead); + static NAN_METHOD(RemoteName); git_branch *raw; }; diff --git a/include/clone_options.h b/include/clone_options.h index 14da5daad..42db7e0c8 100644 --- a/include/clone_options.h +++ b/include/clone_options.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitCloneOptions : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_clone_options *GetValue(); @@ -28,8 +30,7 @@ class GitCloneOptions : public ObjectWrap { GitCloneOptions(git_clone_options *raw); ~GitCloneOptions(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); git_clone_options *raw; }; diff --git a/include/commit.h b/include/commit.h index 6f69f5889..a02ed9f77 100755 --- a/include/commit.h +++ b/include/commit.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitCommit : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_commit *GetValue(); @@ -28,20 +30,19 @@ class GitCommit : public ObjectWrap { GitCommit(git_commit *raw); ~GitCommit(); - static Handle New(const Arguments& args); - - - static Handle Oid(const Arguments& args); - static Handle MessageEncoding(const Arguments& args); - static Handle Message(const Arguments& args); - static Handle Time(const Arguments& args); - static Handle Offset(const Arguments& args); - static Handle Committer(const Arguments& args); - static Handle Author(const Arguments& args); - static Handle TreeId(const Arguments& args); - static Handle ParentCount(const Arguments& args); - static Handle ParentId(const Arguments& args); - static Handle NthGenAncestor(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(Oid); + static NAN_METHOD(MessageEncoding); + static NAN_METHOD(Message); + static NAN_METHOD(Time); + static NAN_METHOD(Offset); + static NAN_METHOD(Committer); + static NAN_METHOD(Author); + static NAN_METHOD(TreeId); + static NAN_METHOD(ParentCount); + static NAN_METHOD(ParentId); + static NAN_METHOD(NthGenAncestor); git_commit *raw; }; diff --git a/include/delta.h b/include/delta.h index e06f6283c..d46511b9c 100644 --- a/include/delta.h +++ b/include/delta.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDelta : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_delta *GetValue(); @@ -28,13 +30,13 @@ class GitDelta : public ObjectWrap { GitDelta(git_diff_delta *raw); ~GitDelta(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); - static Handle OldFile(const Arguments& args); - static Handle NewFile(const Arguments& args); - static Handle Status(const Arguments& args); - static Handle Similarity(const Arguments& args); - static Handle Flags(const Arguments& args); + static NAN_METHOD(OldFile); + static NAN_METHOD(NewFile); + static NAN_METHOD(Status); + static NAN_METHOD(Similarity); + static NAN_METHOD(Flags); git_diff_delta *raw; }; diff --git a/include/diff.h b/include/diff.h index 677f22b50..fa88badfa 100644 --- a/include/diff.h +++ b/include/diff.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiff : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_list *GetValue(); @@ -26,10 +28,10 @@ class GitDiff : public ObjectWrap { GitDiff(git_diff_list *raw); ~GitDiff(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(TreeToTree); - static Handle TreeToTree(const Arguments& args); static void TreeToTreeWork(uv_work_t* req); static void TreeToTreeAfterWork(uv_work_t* req); @@ -47,7 +49,7 @@ class GitDiff : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle TreeToIndex(const Arguments& args); + static NAN_METHOD(TreeToIndex); static void TreeToIndexWork(uv_work_t* req); static void TreeToIndexAfterWork(uv_work_t* req); @@ -65,7 +67,7 @@ class GitDiff : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle IndexToWorkdir(const Arguments& args); + static NAN_METHOD(IndexToWorkdir); static void IndexToWorkdirWork(uv_work_t* req); static void IndexToWorkdirAfterWork(uv_work_t* req); @@ -81,7 +83,7 @@ class GitDiff : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle TreeToWorkdir(const Arguments& args); + static NAN_METHOD(TreeToWorkdir); static void TreeToWorkdirWork(uv_work_t* req); static void TreeToWorkdirAfterWork(uv_work_t* req); @@ -97,12 +99,12 @@ class GitDiff : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle Merge(const Arguments& args); - static Handle FindSimilar(const Arguments& args); - static Handle StatusChar(const Arguments& args); - static Handle NumDeltas(const Arguments& args); - static Handle NumDeltasOfType(const Arguments& args); - static Handle GetPatch(const Arguments& args); + static NAN_METHOD(Merge); + static NAN_METHOD(FindSimilar); + static NAN_METHOD(StatusChar); + static NAN_METHOD(NumDeltas); + static NAN_METHOD(NumDeltasOfType); + static NAN_METHOD(GetPatch); git_diff_list *raw; }; diff --git a/include/diff_file.h b/include/diff_file.h index f7f8210d0..adb50ab42 100644 --- a/include/diff_file.h +++ b/include/diff_file.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiffFile : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_file *GetValue(); @@ -28,13 +30,13 @@ class GitDiffFile : public ObjectWrap { GitDiffFile(git_diff_file *raw); ~GitDiffFile(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); - static Handle Oid(const Arguments& args); - static Handle Path(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle Flags(const Arguments& args); - static Handle Mode(const Arguments& args); + static NAN_METHOD(Oid); + static NAN_METHOD(Path); + static NAN_METHOD(Size); + static NAN_METHOD(Flags); + static NAN_METHOD(Mode); git_diff_file *raw; }; diff --git a/include/diff_find_options.h b/include/diff_find_options.h index 3500d1b23..d76efe975 100644 --- a/include/diff_find_options.h +++ b/include/diff_find_options.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiffFindOptions : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_find_options *GetValue(); @@ -28,8 +30,7 @@ class GitDiffFindOptions : public ObjectWrap { GitDiffFindOptions(git_diff_find_options *raw); ~GitDiffFindOptions(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); git_diff_find_options *raw; }; diff --git a/include/diff_list.h b/include/diff_list.h index 185a00e56..04c604766 100644 --- a/include/diff_list.h +++ b/include/diff_list.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiffList : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_list *GetValue(); @@ -27,15 +29,15 @@ class GitDiffList : public ObjectWrap { private: GitDiffList(git_diff_list *raw); ~GitDiffList(); + + static NAN_METHOD(New); + + static NAN_METHOD(Merge); + static NAN_METHOD(FindSimilar); + static NAN_METHOD(Size); + static NAN_METHOD(NumDeltasOfType); + static NAN_METHOD(Patch); - static Handle New(const Arguments& args); - - - static Handle Merge(const Arguments& args); - static Handle FindSimilar(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle NumDeltasOfType(const Arguments& args); - static Handle Patch(const Arguments& args); git_diff_list *raw; }; diff --git a/include/diff_options.h b/include/diff_options.h index 6dd93a0b8..292269763 100644 --- a/include/diff_options.h +++ b/include/diff_options.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiffOptions : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_options *GetValue(); @@ -28,8 +30,7 @@ class GitDiffOptions : public ObjectWrap { GitDiffOptions(git_diff_options *raw); ~GitDiffOptions(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); git_diff_options *raw; }; diff --git a/include/diff_range.h b/include/diff_range.h index bb44337b4..7df5b8042 100644 --- a/include/diff_range.h +++ b/include/diff_range.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitDiffRange : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_range *GetValue(); @@ -28,12 +30,12 @@ class GitDiffRange : public ObjectWrap { GitDiffRange(git_diff_range *raw); ~GitDiffRange(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); - static Handle OldStart(const Arguments& args); - static Handle OldLines(const Arguments& args); - static Handle NewStart(const Arguments& args); - static Handle NewLines(const Arguments& args); + static NAN_METHOD(OldStart); + static NAN_METHOD(OldLines); + static NAN_METHOD(NewStart); + static NAN_METHOD(NewLines); git_diff_range *raw; }; diff --git a/include/index.h b/include/index.h index e634d7ea0..4edafefec 100755 --- a/include/index.h +++ b/include/index.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitIndex : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_index *GetValue(); @@ -28,10 +30,9 @@ class GitIndex : public ObjectWrap { GitIndex(git_index *raw); ~GitIndex(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle Open(const Arguments& args); + static NAN_METHOD(Open); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -44,7 +45,7 @@ class GitIndex : public ObjectWrap { const char * index_path; Persistent callback; }; - static Handle Read(const Arguments& args); + static NAN_METHOD(Read); static void ReadWork(uv_work_t* req); static void ReadAfterWork(uv_work_t* req); @@ -56,7 +57,7 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - static Handle Write(const Arguments& args); + static NAN_METHOD(Write); static void WriteWork(uv_work_t* req); static void WriteAfterWork(uv_work_t* req); @@ -68,7 +69,7 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - static Handle ReadTree(const Arguments& args); + static NAN_METHOD(ReadTree); static void ReadTreeWork(uv_work_t* req); static void ReadTreeAfterWork(uv_work_t* req); @@ -82,7 +83,7 @@ class GitIndex : public ObjectWrap { const git_tree * tree; Persistent callback; }; - static Handle WriteTree(const Arguments& args); + static NAN_METHOD(WriteTree); static void WriteTreeWork(uv_work_t* req); static void WriteTreeAfterWork(uv_work_t* req); @@ -95,12 +96,12 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - static Handle Size(const Arguments& args); - static Handle Clear(const Arguments& args); - static Handle Entry(const Arguments& args); - static Handle Remove(const Arguments& args); - static Handle RemoveDirectory(const Arguments& args); - static Handle AddBypath(const Arguments& args); + static NAN_METHOD(Size); + static NAN_METHOD(Clear); + static NAN_METHOD(Entry); + static NAN_METHOD(Remove); + static NAN_METHOD(RemoveDirectory); + static NAN_METHOD(AddBypath); static void AddBypathWork(uv_work_t* req); static void AddBypathAfterWork(uv_work_t* req); @@ -114,12 +115,12 @@ class GitIndex : public ObjectWrap { const char * path; Persistent callback; }; - static Handle RemoveBypath(const Arguments& args); - static Handle Find(const Arguments& args); - static Handle ConflictRemove(const Arguments& args); - static Handle ConflictCleanup(const Arguments& args); - static Handle HasConflicts(const Arguments& args); - static Handle IndexToWorkdir(const Arguments& args); + static NAN_METHOD(RemoveBypath); + static NAN_METHOD(Find); + static NAN_METHOD(ConflictRemove); + static NAN_METHOD(ConflictCleanup); + static NAN_METHOD(HasConflicts); + static NAN_METHOD(IndexToWorkdir); static void IndexToWorkdirWork(uv_work_t* req); static void IndexToWorkdirAfterWork(uv_work_t* req); diff --git a/include/index_entry.h b/include/index_entry.h index 7bf5fc6a8..8e3ea5072 100644 --- a/include/index_entry.h +++ b/include/index_entry.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitIndexEntry : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_index_entry *GetValue(); @@ -28,21 +30,21 @@ class GitIndexEntry : public ObjectWrap { GitIndexEntry(git_index_entry *raw); ~GitIndexEntry(); - static Handle New(const Arguments& args); - - static Handle Ctime(const Arguments& args); - static Handle Mtime(const Arguments& args); - static Handle Dev(const Arguments& args); - static Handle Ino(const Arguments& args); - static Handle Mode(const Arguments& args); - static Handle Uid(const Arguments& args); - static Handle gid(const Arguments& args); - static Handle FileSize(const Arguments& args); - static Handle Oid(const Arguments& args); - static Handle Flags(const Arguments& args); - static Handle FlagsExtended(const Arguments& args); - static Handle Path(const Arguments& args); - + static NAN_METHOD(New); + + static NAN_METHOD(Ctime); + static NAN_METHOD(Mtime); + static NAN_METHOD(Dev); + static NAN_METHOD(Ino); + static NAN_METHOD(Mode); + static NAN_METHOD(Uid); + static NAN_METHOD(gid); + static NAN_METHOD(FileSize); + static NAN_METHOD(Oid); + static NAN_METHOD(Flags); + static NAN_METHOD(FlagsExtended); + static NAN_METHOD(Path); + git_index_entry *raw; }; diff --git a/include/index_time.h b/include/index_time.h index 765ce6cc7..ad8dc49a5 100644 --- a/include/index_time.h +++ b/include/index_time.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitIndexTime : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_index_time *GetValue(); @@ -28,11 +30,10 @@ class GitIndexTime : public ObjectWrap { GitIndexTime(git_index_time *raw); ~GitIndexTime(); - static Handle New(const Arguments& args); - - static Handle Seconds(const Arguments& args); - static Handle Nanoseconds(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Seconds); + static NAN_METHOD(Nanoseconds); git_index_time *raw; }; diff --git a/include/object.h b/include/object.h index 6ab9d3537..e4188ed83 100644 --- a/include/object.h +++ b/include/object.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitObject : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_object *GetValue(); @@ -28,12 +30,12 @@ class GitObject : public ObjectWrap { GitObject(git_object *raw); ~GitObject(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Oid); + static NAN_METHOD(Type); + static NAN_METHOD(Peel); - static Handle Oid(const Arguments& args); - static Handle Type(const Arguments& args); - static Handle Peel(const Arguments& args); static void PeelWork(uv_work_t* req); static void PeelAfterWork(uv_work_t* req); diff --git a/include/odb.h b/include/odb.h index 6ed9913d9..5dbde3946 100644 --- a/include/odb.h +++ b/include/odb.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitOdb : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_odb *GetValue(); @@ -28,13 +30,13 @@ class GitOdb : public ObjectWrap { GitOdb(git_odb *raw); ~GitOdb(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Create); + static NAN_METHOD(Open); + static NAN_METHOD(AddDiskAlternate); + static NAN_METHOD(Read); - static Handle Create(const Arguments& args); - static Handle Open(const Arguments& args); - static Handle AddDiskAlternate(const Arguments& args); - static Handle Read(const Arguments& args); static void ReadWork(uv_work_t* req); static void ReadAfterWork(uv_work_t* req); @@ -49,11 +51,11 @@ class GitOdb : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle ReadPrefix(const Arguments& args); - static Handle ReadHeader(const Arguments& args); - static Handle Exists(const Arguments& args); - static Handle Refresh(const Arguments& args); - static Handle Write(const Arguments& args); + static NAN_METHOD(ReadPrefix); + static NAN_METHOD(ReadHeader); + static NAN_METHOD(Exists); + static NAN_METHOD(Refresh); + static NAN_METHOD(Write); static void WriteWork(uv_work_t* req); static void WriteAfterWork(uv_work_t* req); @@ -72,8 +74,8 @@ class GitOdb : public ObjectWrap { git_otype type; Persistent callback; }; - static Handle Hash(const Arguments& args); - static Handle Hashfile(const Arguments& args); + static NAN_METHOD(Hash); + static NAN_METHOD(Hashfile); git_odb *raw; }; diff --git a/include/odb_object.h b/include/odb_object.h index 7938dfa49..54325a1fe 100644 --- a/include/odb_object.h +++ b/include/odb_object.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitOdbObject : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_odb_object *GetValue(); @@ -28,13 +30,12 @@ class GitOdbObject : public ObjectWrap { GitOdbObject(git_odb_object *raw); ~GitOdbObject(); - static Handle New(const Arguments& args); - - - static Handle Data(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle Type(const Arguments& args); - static Handle Oid(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(Data); + static NAN_METHOD(Size); + static NAN_METHOD(Type); + static NAN_METHOD(Oid); git_odb_object *raw; }; diff --git a/include/oid.h b/include/oid.h index 2ce3a9e5c..789b560ea 100755 --- a/include/oid.h +++ b/include/oid.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitOid : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_oid *GetValue(); @@ -28,11 +30,11 @@ class GitOid : public ObjectWrap { GitOid(git_oid *raw); ~GitOid(); - static Handle New(const Arguments& args); - - - static Handle FromString(const Arguments& args); - static Handle Sha(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(FromString); + static NAN_METHOD(Sha); + git_oid *raw; }; diff --git a/include/patch.h b/include/patch.h index 7a4d408ff..e5f445b41 100644 --- a/include/patch.h +++ b/include/patch.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitPatch : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_diff_patch *GetValue(); @@ -28,16 +30,15 @@ class GitPatch : public ObjectWrap { GitPatch(git_diff_patch *raw); ~GitPatch(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle Delta(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle Stats(const Arguments& args); - static Handle Hunk(const Arguments& args); - static Handle Lines(const Arguments& args); - static Handle Line(const Arguments& args); - static Handle ToString(const Arguments& args); + static NAN_METHOD(Delta); + static NAN_METHOD(Size); + static NAN_METHOD(Stats); + static NAN_METHOD(Hunk); + static NAN_METHOD(Lines); + static NAN_METHOD(Line); + static NAN_METHOD(ToString); git_diff_patch *raw; }; diff --git a/include/refdb.h b/include/refdb.h index 51355028f..c5914e84f 100644 --- a/include/refdb.h +++ b/include/refdb.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitRefDb : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_refdb *GetValue(); @@ -28,8 +30,7 @@ class GitRefDb : public ObjectWrap { GitRefDb(git_refdb *raw); ~GitRefDb(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); git_refdb *raw; }; diff --git a/include/reference.h b/include/reference.h index ae7d18ad4..7aef82a2c 100644 --- a/include/reference.h +++ b/include/reference.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitReference : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_reference *GetValue(); @@ -28,10 +30,10 @@ class GitReference : public ObjectWrap { GitReference(git_reference *raw); ~GitReference(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(OidForName); - static Handle OidForName(const Arguments& args); static void OidForNameWork(uv_work_t* req); static void OidForNameAfterWork(uv_work_t* req); @@ -46,11 +48,12 @@ class GitReference : public ObjectWrap { const char * name; Persistent callback; }; - static Handle Target(const Arguments& args); - static Handle SymbolicTarget(const Arguments& args); - static Handle Type(const Arguments& args); - static Handle Name(const Arguments& args); - static Handle Resolve(const Arguments& args); + static NAN_METHOD(Target); + static NAN_METHOD(SymbolicTarget); + static NAN_METHOD(Type); + static NAN_METHOD(Name); + static NAN_METHOD(Resolve); + static void ResolveWork(uv_work_t* req); static void ResolveAfterWork(uv_work_t* req); @@ -63,9 +66,11 @@ class GitReference : public ObjectWrap { const git_reference * ref; Persistent callback; }; - static Handle SetSymbolicTarget(const Arguments& args); - static Handle setTarget(const Arguments& args); - static Handle Rename(const Arguments& args); + + static NAN_METHOD(SetSymbolicTarget); + static NAN_METHOD(setTarget); + static NAN_METHOD(Rename); + static void RenameWork(uv_work_t* req); static void RenameAfterWork(uv_work_t* req); @@ -82,7 +87,8 @@ class GitReference : public ObjectWrap { int force; Persistent callback; }; - static Handle Delete(const Arguments& args); + static NAN_METHOD(Delete); + static void DeleteWork(uv_work_t* req); static void DeleteAfterWork(uv_work_t* req); @@ -94,10 +100,11 @@ class GitReference : public ObjectWrap { git_reference * ref; Persistent callback; }; - static Handle IsBranch(const Arguments& args); - static Handle IsRemote(const Arguments& args); - static Handle Peel(const Arguments& args); - static Handle IsValidName(const Arguments& args); + static NAN_METHOD(IsBranch); + static NAN_METHOD(IsRemote); + static NAN_METHOD(Peel); + static NAN_METHOD(IsValidName); + git_reference *raw; }; diff --git a/include/remote.h b/include/remote.h index 81fd1ac68..bf782f620 100644 --- a/include/remote.h +++ b/include/remote.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitRemote : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_remote *GetValue(); @@ -28,15 +30,14 @@ class GitRemote : public ObjectWrap { GitRemote(git_remote *raw); ~GitRemote(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle Name(const Arguments& args); - static Handle Url(const Arguments& args); - static Handle PushUrl(const Arguments& args); - static Handle SetUrl(const Arguments& args); - static Handle SetPushUrl(const Arguments& args); - static Handle Connect(const Arguments& args); + static NAN_METHOD(Name); + static NAN_METHOD(Url); + static NAN_METHOD(PushUrl); + static NAN_METHOD(SetUrl); + static NAN_METHOD(SetPushUrl); + static NAN_METHOD(Connect); static void ConnectWork(uv_work_t* req); static void ConnectAfterWork(uv_work_t* req); @@ -50,7 +51,7 @@ class GitRemote : public ObjectWrap { git_direction direction; Persistent callback; }; - static Handle Download(const Arguments& args); + static NAN_METHOD(Download); static void DownloadWork(uv_work_t* req); static void DownloadAfterWork(uv_work_t* req); @@ -66,9 +67,9 @@ class GitRemote : public ObjectWrap { void * payload; Persistent callback; }; - static Handle Connected(const Arguments& args); - static Handle Stop(const Arguments& args); - static Handle Disconnect(const Arguments& args); + static NAN_METHOD(Connected); + static NAN_METHOD(Stop); + static NAN_METHOD(Disconnect); static void DisconnectWork(uv_work_t* req); static void DisconnectAfterWork(uv_work_t* req); @@ -80,13 +81,13 @@ class GitRemote : public ObjectWrap { git_remote * remote; Persistent callback; }; - static Handle UpdateTips(const Arguments& args); - static Handle ValidUrl(const Arguments& args); - static Handle SupportedUrl(const Arguments& args); - static Handle CheckCert(const Arguments& args); - static Handle UpdateFetchhead(const Arguments& args); - static Handle SetUpdateFetchhead(const Arguments& args); - static Handle IsValidName(const Arguments& args); + static NAN_METHOD(UpdateTips); + static NAN_METHOD(ValidUrl); + static NAN_METHOD(SupportedUrl); + static NAN_METHOD(CheckCert); + static NAN_METHOD(UpdateFetchhead); + static NAN_METHOD(SetUpdateFetchhead); + static NAN_METHOD(IsValidName); git_remote *raw; }; diff --git a/include/repo.h b/include/repo.h index 8f10f3427..a5ad14adf 100755 --- a/include/repo.h +++ b/include/repo.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitRepo : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_repository *GetValue(); @@ -28,10 +30,10 @@ class GitRepo : public ObjectWrap { GitRepo(git_repository *raw); ~GitRepo(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Open); - static Handle Open(const Arguments& args); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -44,7 +46,7 @@ class GitRepo : public ObjectWrap { const char * path; Persistent callback; }; - static Handle Init(const Arguments& args); + static NAN_METHOD(Init); static void InitWork(uv_work_t* req); static void InitAfterWork(uv_work_t* req); @@ -59,10 +61,10 @@ class GitRepo : public ObjectWrap { unsigned is_bare; Persistent callback; }; - static Handle Path(const Arguments& args); - static Handle Workdir(const Arguments& args); - static Handle Odb(const Arguments& args); - static Handle openIndex(const Arguments& args); + static NAN_METHOD(Path); + static NAN_METHOD(Workdir); + static NAN_METHOD(Odb); + static NAN_METHOD(openIndex); static void openIndexWork(uv_work_t* req); static void openIndexAfterWork(uv_work_t* req); @@ -75,7 +77,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static Handle GetBlob(const Arguments& args); + static NAN_METHOD(GetBlob); static void GetBlobWork(uv_work_t* req); static void GetBlobAfterWork(uv_work_t* req); @@ -90,7 +92,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle GetCommit(const Arguments& args); + static NAN_METHOD(GetCommit); static void GetCommitWork(uv_work_t* req); static void GetCommitAfterWork(uv_work_t* req); @@ -105,7 +107,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle CreateCommit(const Arguments& args); + static NAN_METHOD(CreateCommit); static void CreateCommitWork(uv_work_t* req); static void CreateCommitAfterWork(uv_work_t* req); @@ -134,7 +136,7 @@ class GitRepo : public ObjectWrap { const git_commit ** parents; Persistent callback; }; - static Handle GetObject(const Arguments& args); + static NAN_METHOD(GetObject); static void GetObjectWork(uv_work_t* req); static void GetObjectAfterWork(uv_work_t* req); @@ -151,7 +153,7 @@ class GitRepo : public ObjectWrap { git_otype type; Persistent callback; }; - static Handle GetReference(const Arguments& args); + static NAN_METHOD(GetReference); static void GetReferenceWork(uv_work_t* req); static void GetReferenceAfterWork(uv_work_t* req); @@ -166,9 +168,9 @@ class GitRepo : public ObjectWrap { const char * name; Persistent callback; }; - static Handle CreateSymbolicReference(const Arguments& args); - static Handle CreateReference(const Arguments& args); - static Handle AddRemote(const Arguments& args); + static NAN_METHOD(CreateSymbolicReference); + static NAN_METHOD(CreateReference); + static NAN_METHOD(AddRemote); static void AddRemoteWork(uv_work_t* req); static void AddRemoteAfterWork(uv_work_t* req); @@ -185,10 +187,10 @@ class GitRepo : public ObjectWrap { const char * url; Persistent callback; }; - static Handle CreateRevWalk(const Arguments& args); - static Handle GetSubmodule(const Arguments& args); - static Handle AddSubmodule(const Arguments& args); - static Handle GetTag(const Arguments& args); + static NAN_METHOD(CreateRevWalk); + static NAN_METHOD(GetSubmodule); + static NAN_METHOD(AddSubmodule); + static NAN_METHOD(GetTag); static void GetTagWork(uv_work_t* req); static void GetTagAfterWork(uv_work_t* req); @@ -203,7 +205,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle CreateTag(const Arguments& args); + static NAN_METHOD(CreateTag); static void CreateTagWork(uv_work_t* req); static void CreateTagAfterWork(uv_work_t* req); @@ -226,7 +228,7 @@ class GitRepo : public ObjectWrap { int force; Persistent callback; }; - static Handle CreateLightweightTag(const Arguments& args); + static NAN_METHOD(CreateLightweightTag); static void CreateLightweightTagWork(uv_work_t* req); static void CreateLightweightTagAfterWork(uv_work_t* req); @@ -245,7 +247,7 @@ class GitRepo : public ObjectWrap { int force; Persistent callback; }; - static Handle GetTree(const Arguments& args); + static NAN_METHOD(GetTree); static void GetTreeWork(uv_work_t* req); static void GetTreeAfterWork(uv_work_t* req); @@ -260,7 +262,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle ReloadSubmodules(const Arguments& args); + static NAN_METHOD(ReloadSubmodules); static void ReloadSubmodulesWork(uv_work_t* req); static void ReloadSubmodulesAfterWork(uv_work_t* req); @@ -272,7 +274,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static Handle Delete(const Arguments& args); + static NAN_METHOD(Delete); static void DeleteWork(uv_work_t* req); static void DeleteAfterWork(uv_work_t* req); @@ -286,7 +288,7 @@ class GitRepo : public ObjectWrap { const char * tag_name; Persistent callback; }; - static Handle GetReferences(const Arguments& args); + static NAN_METHOD(GetReferences); static void GetReferencesWork(uv_work_t* req); static void GetReferencesAfterWork(uv_work_t* req); @@ -301,7 +303,7 @@ class GitRepo : public ObjectWrap { unsigned int list_flags; Persistent callback; }; - static Handle CreateBlobFromBuffer(const Arguments& args); + static NAN_METHOD(CreateBlobFromBuffer); static void CreateBlobFromBufferWork(uv_work_t* req); static void CreateBlobFromBufferAfterWork(uv_work_t* req); @@ -318,7 +320,7 @@ class GitRepo : public ObjectWrap { size_t len; Persistent callback; }; - static Handle CreateBlobFromFile(const Arguments& args); + static NAN_METHOD(CreateBlobFromFile); static void CreateBlobFromFileWork(uv_work_t* req); static void CreateBlobFromFileAfterWork(uv_work_t* req); @@ -333,7 +335,7 @@ class GitRepo : public ObjectWrap { const char * path; Persistent callback; }; - static Handle GetRemotes(const Arguments& args); + static NAN_METHOD(GetRemotes); static void GetRemotesWork(uv_work_t* req); static void GetRemotesAfterWork(uv_work_t* req); @@ -346,7 +348,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static Handle Clone(const Arguments& args); + static NAN_METHOD(Clone); static void CloneWork(uv_work_t* req); static void CloneAfterWork(uv_work_t* req); @@ -363,7 +365,7 @@ class GitRepo : public ObjectWrap { const git_clone_options * options; Persistent callback; }; - static Handle GetRemote(const Arguments& args); + static NAN_METHOD(GetRemote); git_repository *raw; }; diff --git a/include/revwalk.h b/include/revwalk.h index c2096cc61..d6e6e6712 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitRevWalk : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_revwalk *GetValue(); @@ -28,11 +30,11 @@ class GitRevWalk : public ObjectWrap { GitRevWalk(git_revwalk *raw); ~GitRevWalk(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Reset); + static NAN_METHOD(Push); - static Handle Reset(const Arguments& args); - static Handle Push(const Arguments& args); static void PushWork(uv_work_t* req); static void PushAfterWork(uv_work_t* req); @@ -46,7 +48,7 @@ class GitRevWalk : public ObjectWrap { const git_oid * id; Persistent callback; }; - static Handle PushGlob(const Arguments& args); + static NAN_METHOD(PushGlob); static void PushGlobWork(uv_work_t* req); static void PushGlobAfterWork(uv_work_t* req); @@ -60,7 +62,7 @@ class GitRevWalk : public ObjectWrap { const char * glob; Persistent callback; }; - static Handle PushHead(const Arguments& args); + static NAN_METHOD(PushHead); static void PushHeadWork(uv_work_t* req); static void PushHeadAfterWork(uv_work_t* req); @@ -72,7 +74,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static Handle Hide(const Arguments& args); + static NAN_METHOD(Hide); static void HideWork(uv_work_t* req); static void HideAfterWork(uv_work_t* req); @@ -86,7 +88,7 @@ class GitRevWalk : public ObjectWrap { const git_oid * commit_id; Persistent callback; }; - static Handle HideGlob(const Arguments& args); + static NAN_METHOD(HideGlob); static void HideGlobWork(uv_work_t* req); static void HideGlobAfterWork(uv_work_t* req); @@ -100,7 +102,7 @@ class GitRevWalk : public ObjectWrap { const char * glob; Persistent callback; }; - static Handle HideHead(const Arguments& args); + static NAN_METHOD(HideHead); static void HideHeadWork(uv_work_t* req); static void HideHeadAfterWork(uv_work_t* req); @@ -112,7 +114,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static Handle PushRef(const Arguments& args); + static NAN_METHOD(PushRef); static void PushRefWork(uv_work_t* req); static void PushRefAfterWork(uv_work_t* req); @@ -126,7 +128,7 @@ class GitRevWalk : public ObjectWrap { const char * refname; Persistent callback; }; - static Handle HideRef(const Arguments& args); + static NAN_METHOD(HideRef); static void HideRefWork(uv_work_t* req); static void HideRefAfterWork(uv_work_t* req); @@ -140,7 +142,7 @@ class GitRevWalk : public ObjectWrap { const char * refname; Persistent callback; }; - static Handle Next(const Arguments& args); + static NAN_METHOD(Next); static void NextWork(uv_work_t* req); static void NextAfterWork(uv_work_t* req); @@ -153,7 +155,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static Handle Sorting(const Arguments& args); + static NAN_METHOD(Sorting); git_revwalk *raw; }; diff --git a/include/signature.h b/include/signature.h index 14d542c82..65ca2b139 100755 --- a/include/signature.h +++ b/include/signature.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitSignature : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_signature *GetValue(); @@ -28,14 +30,24 @@ class GitSignature : public ObjectWrap { GitSignature(git_signature *raw); ~GitSignature(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(Name); + static NAN_METHOD(Email); + static NAN_METHOD(Time); + + static NAN_METHOD(Create); + static NAN_METHOD(Now); + + + // static Handle New(const Arguments& args); - static Handle Name(const Arguments& args); - static Handle Email(const Arguments& args); - static Handle Time(const Arguments& args); + // static Handle Name(const Arguments& args); + // static Handle Email(const Arguments& args); + // static Handle Time(const Arguments& args); - static Handle Create(const Arguments& args); - static Handle Now(const Arguments& args); + // static Handle Create(const Arguments& args); + // static Handle Now(const Arguments& args); git_signature *raw; }; diff --git a/include/submodule.h b/include/submodule.h index f80d8ee3d..2895210b0 100644 --- a/include/submodule.h +++ b/include/submodule.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitSubmodule : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_submodule *GetValue(); @@ -28,10 +30,9 @@ class GitSubmodule : public ObjectWrap { GitSubmodule(git_submodule *raw); ~GitSubmodule(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle AddFinalize(const Arguments& args); + static NAN_METHOD(AddFinalize); static void AddFinalizeWork(uv_work_t* req); static void AddFinalizeAfterWork(uv_work_t* req); @@ -43,7 +44,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static Handle AddToIndex(const Arguments& args); + static NAN_METHOD(AddToIndex); static void AddToIndexWork(uv_work_t* req); static void AddToIndexAfterWork(uv_work_t* req); @@ -57,7 +58,7 @@ class GitSubmodule : public ObjectWrap { int write_index; Persistent callback; }; - static Handle Save(const Arguments& args); + static NAN_METHOD(Save); static void SaveWork(uv_work_t* req); static void SaveAfterWork(uv_work_t* req); @@ -69,13 +70,13 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static Handle Name(const Arguments& args); - static Handle Path(const Arguments& args); - static Handle Url(const Arguments& args); - static Handle SetUrl(const Arguments& args); - static Handle IndexId(const Arguments& args); - static Handle HeadId(const Arguments& args); - static Handle Init(const Arguments& args); + static NAN_METHOD(Name); + static NAN_METHOD(Path); + static NAN_METHOD(Url); + static NAN_METHOD(SetUrl); + static NAN_METHOD(IndexId); + static NAN_METHOD(HeadId); + static NAN_METHOD(Init); static void InitWork(uv_work_t* req); static void InitAfterWork(uv_work_t* req); @@ -89,7 +90,7 @@ class GitSubmodule : public ObjectWrap { int overwrite; Persistent callback; }; - static Handle Sync(const Arguments& args); + static NAN_METHOD(Sync); static void SyncWork(uv_work_t* req); static void SyncAfterWork(uv_work_t* req); @@ -101,7 +102,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static Handle Open(const Arguments& args); + static NAN_METHOD(Open); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -114,7 +115,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static Handle Reload(const Arguments& args); + static NAN_METHOD(Reload); static void ReloadWork(uv_work_t* req); static void ReloadAfterWork(uv_work_t* req); @@ -126,7 +127,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static Handle Status(const Arguments& args); + static NAN_METHOD(Status); static void StatusWork(uv_work_t* req); static void StatusAfterWork(uv_work_t* req); diff --git a/include/tag.h b/include/tag.h index f89ded8b1..eb1703fb4 100755 --- a/include/tag.h +++ b/include/tag.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitTag : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_tag *GetValue(); @@ -28,11 +30,10 @@ class GitTag : public ObjectWrap { GitTag(git_tag *raw); ~GitTag(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle Oid(const Arguments& args); - static Handle GetTarget(const Arguments& args); + static NAN_METHOD(Oid); + static NAN_METHOD(GetTarget); static void GetTargetWork(uv_work_t* req); static void GetTargetAfterWork(uv_work_t* req); @@ -45,12 +46,12 @@ class GitTag : public ObjectWrap { const git_tag * tag; Persistent callback; }; - static Handle TargetId(const Arguments& args); - static Handle TargetType(const Arguments& args); - static Handle Name(const Arguments& args); - static Handle Tagger(const Arguments& args); - static Handle Message(const Arguments& args); - static Handle Peel(const Arguments& args); + static NAN_METHOD(TargetId); + static NAN_METHOD(TargetType); + static NAN_METHOD(Name); + static NAN_METHOD(Tagger); + static NAN_METHOD(Message); + static NAN_METHOD(Peel); git_tag *raw; }; diff --git a/include/threads.h b/include/threads.h index 7a67b0295..4145ef0f7 100755 --- a/include/threads.h +++ b/include/threads.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,17 +19,15 @@ using namespace v8; class GitThreads : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); private: + static NAN_METHOD(New); - static Handle New(const Arguments& args); - - - static Handle Init(const Arguments& args); - static Handle Shutdown(const Arguments& args); + static NAN_METHOD(Init); + static NAN_METHOD(Shutdown); }; #endif diff --git a/include/time.h b/include/time.h index b742a88b0..9d0dce8fd 100644 --- a/include/time.h +++ b/include/time.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitTime : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_time *GetValue(); @@ -28,10 +30,15 @@ class GitTime : public ObjectWrap { GitTime(git_time *raw); ~GitTime(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + + static NAN_METHOD(Time); + static NAN_METHOD(Offset); + + // static Handle New(const Arguments& args); - static Handle Time(const Arguments& args); - static Handle Offset(const Arguments& args); + // static Handle Time(const Arguments& args); + // static Handle Offset(const Arguments& args); git_time *raw; }; diff --git a/include/tree.h b/include/tree.h index 5462a82b1..b77169fa5 100755 --- a/include/tree.h +++ b/include/tree.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitTree : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_tree *GetValue(); @@ -28,15 +30,15 @@ class GitTree : public ObjectWrap { GitTree(git_tree *raw); ~GitTree(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Oid); + static NAN_METHOD(Size); + static NAN_METHOD(EntryByName); + static NAN_METHOD(EntryByIndex); + static NAN_METHOD(EntryByOid); + static NAN_METHOD(GetEntry); - static Handle Oid(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle EntryByName(const Arguments& args); - static Handle EntryByIndex(const Arguments& args); - static Handle EntryByOid(const Arguments& args); - static Handle GetEntry(const Arguments& args); static void GetEntryWork(uv_work_t* req); static void GetEntryAfterWork(uv_work_t* req); @@ -51,8 +53,8 @@ class GitTree : public ObjectWrap { const char * path; Persistent callback; }; - static Handle Builder(const Arguments& args); - static Handle DiffTree(const Arguments& args); + static NAN_METHOD(Builder); + static NAN_METHOD(DiffTree); static void DiffTreeWork(uv_work_t* req); static void DiffTreeAfterWork(uv_work_t* req); @@ -71,7 +73,7 @@ class GitTree : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle DiffIndex(const Arguments& args); + static NAN_METHOD(DiffIndex); static void DiffIndexWork(uv_work_t* req); static void DiffIndexAfterWork(uv_work_t* req); @@ -90,7 +92,7 @@ class GitTree : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static Handle DiffWorkDir(const Arguments& args); + static NAN_METHOD(DiffWorkDir); static void DiffWorkDirWork(uv_work_t* req); static void DiffWorkDirAfterWork(uv_work_t* req); diff --git a/include/tree_builder.h b/include/tree_builder.h index 93d08a69f..f840deeee 100644 --- a/include/tree_builder.h +++ b/include/tree_builder.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitTreeBuilder : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_treebuilder *GetValue(); @@ -28,16 +30,15 @@ class GitTreeBuilder : public ObjectWrap { GitTreeBuilder(git_treebuilder *raw); ~GitTreeBuilder(); - static Handle New(const Arguments& args); - + static NAN_METHOD(New); - static Handle Create(const Arguments& args); - static Handle Clear(const Arguments& args); - static Handle Size(const Arguments& args); - static Handle Get(const Arguments& args); - static Handle Insert(const Arguments& args); - static Handle GitTreebuilderRemove(const Arguments& args); - static Handle Write(const Arguments& args); + static NAN_METHOD(Create); + static NAN_METHOD(Clear); + static NAN_METHOD(Size); + static NAN_METHOD(Get); + static NAN_METHOD(Insert); + static NAN_METHOD(GitTreebuilderRemove); + static NAN_METHOD(Write); static void WriteWork(uv_work_t* req); static void WriteAfterWork(uv_work_t* req); diff --git a/include/tree_entry.h b/include/tree_entry.h index 7c78ec1e9..0db8e56bc 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -9,6 +9,8 @@ #include #include +#include "nan.h" + #include "git2.h" using namespace node; @@ -17,7 +19,7 @@ using namespace v8; class GitTreeEntry : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); git_tree_entry *GetValue(); @@ -28,14 +30,14 @@ class GitTreeEntry : public ObjectWrap { GitTreeEntry(git_tree_entry *raw); ~GitTreeEntry(); - static Handle New(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(Name); + static NAN_METHOD(Oid); + static NAN_METHOD(Type); + static NAN_METHOD(filemode); + static NAN_METHOD(GetObject); - static Handle Name(const Arguments& args); - static Handle Oid(const Arguments& args); - static Handle Type(const Arguments& args); - static Handle filemode(const Arguments& args); - static Handle GetObject(const Arguments& args); static void GetObjectWork(uv_work_t* req); static void GetObjectAfterWork(uv_work_t* req); diff --git a/include/wrapper.h b/include/wrapper.h index 668a64465..5cb98063e 100644 --- a/include/wrapper.h +++ b/include/wrapper.h @@ -8,13 +8,15 @@ #include #include +#include "nan.h" + using namespace node; using namespace v8; class Wrapper : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize (Handle target); void *GetValue(); @@ -23,8 +25,8 @@ class Wrapper : public ObjectWrap { private: Wrapper(void *raw); - static Handle New(const Arguments& args); - static Handle ToBuffer(const Arguments& args); + static NAN_METHOD(New); + static NAN_METHOD(ToBuffer); void *raw; }; diff --git a/package.json b/package.json index e55d74acc..9b9572202 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "request": "2.9.x", "node-gyp": "~0.8.2", "tar": "0.1.17", - "fs-extra": "0.6.0" + "fs-extra": "0.6.0", + "nan": "0.8.0" }, "devDependencies": { "nodeunit": "", diff --git a/src/base.cc b/src/base.cc index bd6db11b5..940be289f 100755 --- a/src/base.cc +++ b/src/base.cc @@ -43,7 +43,7 @@ #include "../include/clone_options.h" extern "C" void init(Handle target) { - HandleScope scope; + NanScope(); Wrapper::Initialize(target); diff --git a/src/blob.cc b/src/blob.cc index bc6068608..25f82bafd 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -27,40 +27,42 @@ GitBlob::~GitBlob() { } void GitBlob::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Blob")); + tpl->SetClassName(NanSymbol("Blob")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "content", Content); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); NODE_SET_PROTOTYPE_METHOD(tpl, "isBinary", IsBinary); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Blob"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Blob"), tpl->GetFunction()); } -Handle GitBlob::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitBlob::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_blob is required."))); + return NanThrowError(String::New("git_blob is required.")); } - GitBlob* object = new GitBlob((git_blob *) External::Unwrap(args[0])); + GitBlob* object = new GitBlob((git_blob *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitBlob::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitBlob::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_blob *GitBlob::GetValue() { @@ -71,9 +73,8 @@ git_blob *GitBlob::GetValue() { /** * @return {Oid} result */ -Handle GitBlob::Oid(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitBlob::Oid) { + NanScope(); const git_oid * result = git_blob_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -88,15 +89,14 @@ Handle GitBlob::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Wrapper} result */ -Handle GitBlob::Content(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitBlob::Content) { + NanScope(); const void * result = git_blob_rawcontent( ObjectWrap::Unwrap(args.This())->GetValue() @@ -108,15 +108,14 @@ Handle GitBlob::Content(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitBlob::Size(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitBlob::Size) { + NanScope(); git_off_t result = git_blob_rawsize( ObjectWrap::Unwrap(args.This())->GetValue() @@ -124,15 +123,14 @@ Handle GitBlob::Size(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Boolean} result */ -Handle GitBlob::IsBinary(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitBlob::IsBinary) { + NanScope(); int result = git_blob_is_binary( ObjectWrap::Unwrap(args.This())->GetValue() @@ -140,7 +138,7 @@ Handle GitBlob::IsBinary(const Arguments& args) { Handle to; to = Boolean::New(result); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitBlob::constructor_template; +Persistent GitBlob::constructor_template; diff --git a/src/branch.cc b/src/branch.cc index cd6c94c64..13f8e0fb8 100644 --- a/src/branch.cc +++ b/src/branch.cc @@ -23,12 +23,12 @@ Branch::~Branch() { } void Branch::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Branch")); + tpl->SetClassName(NanSymbol("Branch")); NODE_SET_METHOD(tpl, "create", Create); NODE_SET_METHOD(tpl, "delete", Delete); @@ -42,9 +42,8 @@ void Branch::Initialize(Handle target) { NODE_SET_METHOD(tpl, "isHead", IsHead); NODE_SET_METHOD(tpl, "remoteName", RemoteName); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Branch"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Branch"), tpl->GetFunction()); } Handle Branch::New(const Arguments& args) { diff --git a/src/clone_options.cc b/src/clone_options.cc index 3f4b058c5..b01c980a4 100644 --- a/src/clone_options.cc +++ b/src/clone_options.cc @@ -23,36 +23,38 @@ GitCloneOptions::~GitCloneOptions() { } void GitCloneOptions::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("CloneOptions")); + tpl->SetClassName(NanSymbol("CloneOptions")); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("CloneOptions"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("CloneOptions"), tpl->GetFunction()); } -Handle GitCloneOptions::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCloneOptions::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_clone_options is required."))); + return NanThrowError(String::New("git_clone_options is required.")); } - GitCloneOptions* object = new GitCloneOptions((git_clone_options *) External::Unwrap(args[0])); + GitCloneOptions* object = new GitCloneOptions((git_clone_options *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitCloneOptions::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitCloneOptions::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_clone_options *GitCloneOptions::GetValue() { @@ -60,4 +62,4 @@ git_clone_options *GitCloneOptions::GetValue() { } -Persistent GitCloneOptions::constructor_template; +Persistent GitCloneOptions::constructor_template; diff --git a/src/commit.cc b/src/commit.cc index a969aaa07..4f66a43fa 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -27,12 +27,12 @@ GitCommit::~GitCommit() { } void GitCommit::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Commit")); + tpl->SetClassName(NanSymbol("Commit")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "messageEncoding", MessageEncoding); @@ -46,28 +46,30 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "parentId", ParentId); NODE_SET_PROTOTYPE_METHOD(tpl, "nthGenAncestor", NthGenAncestor); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Commit"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Commit"), tpl->GetFunction()); } -Handle GitCommit::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_commit is required."))); + return NanThrowError(String::New("git_commit is required.")); } - GitCommit* object = new GitCommit((git_commit *) External::Unwrap(args[0])); + GitCommit* object = new GitCommit((git_commit *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitCommit::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitCommit::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_commit *GitCommit::GetValue() { @@ -78,8 +80,8 @@ git_commit *GitCommit::GetValue() { /** * @return {Oid} result */ -Handle GitCommit::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::Oid) { + NanScope(); const git_oid * result = git_commit_id( @@ -95,14 +97,14 @@ Handle GitCommit::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitCommit::MessageEncoding(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::MessageEncoding) { + NanScope(); const char * result = git_commit_message_encoding( @@ -111,14 +113,14 @@ Handle GitCommit::MessageEncoding(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitCommit::Message(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::Message) { + NanScope(); const char * result = git_commit_message( @@ -127,14 +129,14 @@ Handle GitCommit::Message(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitCommit::Time(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::Time) { + NanScope(); git_time_t result = git_commit_time( @@ -143,15 +145,14 @@ Handle GitCommit::Time(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitCommit::Offset(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitCommit::Offset) { + NanScope(); int result = git_commit_time_offset( ObjectWrap::Unwrap(args.This())->GetValue() @@ -159,14 +160,14 @@ Handle GitCommit::Offset(const Arguments& args) { Handle to; to = Integer::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Signature} result */ -Handle GitCommit::Committer(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::Committer) { + NanScope(); const git_signature * result = git_commit_committer( @@ -182,14 +183,14 @@ Handle GitCommit::Committer(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Signature} result */ -Handle GitCommit::Author(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::Author) { + NanScope(); const git_signature * result = git_commit_author( @@ -205,14 +206,14 @@ Handle GitCommit::Author(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Oid} result */ -Handle GitCommit::TreeId(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::TreeId) { + NanScope(); const git_oid * result = git_commit_tree_id( @@ -228,14 +229,14 @@ Handle GitCommit::TreeId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitCommit::ParentCount(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::ParentCount) { + NanScope(); unsigned int result = git_commit_parentcount( @@ -244,17 +245,17 @@ Handle GitCommit::ParentCount(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {Number} n * @return {Oid} result */ -Handle GitCommit::ParentId(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::ParentId) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number n is required."))); + return NanThrowError(String::New("Number n is required.")); } unsigned int from_n; @@ -274,17 +275,17 @@ Handle GitCommit::ParentId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {Number} n * @return {Commit} ancestor */ -Handle GitCommit::NthGenAncestor(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitCommit::NthGenAncestor) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number n is required."))); + return NanThrowError(String::New("Number n is required.")); } git_commit * ancestor = 0; @@ -298,19 +299,19 @@ Handle GitCommit::NthGenAncestor(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } Handle to; if (ancestor != NULL) { - to = GitCommit::New((void *)ancestor); + to = GitCommit::New(ancestor); } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitCommit::constructor_template; +Persistent GitCommit::constructor_template; diff --git a/src/delta.cc b/src/delta.cc index 7b45d35f9..1cb4e9d68 100644 --- a/src/delta.cc +++ b/src/delta.cc @@ -24,13 +24,12 @@ GitDelta::~GitDelta() { } void GitDelta::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Delta")); - + tpl->SetClassName(NanSymbol("Delta")); NODE_SET_PROTOTYPE_METHOD(tpl, "oldFile", OldFile); NODE_SET_PROTOTYPE_METHOD(tpl, "newFile", NewFile); @@ -38,36 +37,38 @@ void GitDelta::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "similarity", Similarity); NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Delta"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Delta"), tpl->GetFunction()); } -Handle GitDelta::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_delta is required."))); + return NanThrowError(String::New("git_diff_delta is required.")); } - GitDelta* object = new GitDelta((git_diff_delta *) External::Unwrap(args[0])); + GitDelta* object = new GitDelta((git_diff_delta *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitDelta::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDelta::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_delta *GitDelta::GetValue() { return this->raw; } - -Handle GitDelta::OldFile(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::OldFile) { + NanScope(); Handle to; git_diff_file *old_file = @@ -81,11 +82,11 @@ Handle GitDelta::OldFile(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitDelta::NewFile(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::NewFile) { + NanScope(); Handle to; git_diff_file *new_file = @@ -99,40 +100,40 @@ Handle GitDelta::NewFile(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitDelta::Status(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::Status) { + NanScope(); Handle to; git_delta_t status = ObjectWrap::Unwrap(args.This())->GetValue()->status; to = Integer::New(status); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDelta::Similarity(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::Similarity) { + NanScope(); Handle to; uint32_t similarity = ObjectWrap::Unwrap(args.This())->GetValue()->similarity; to = Integer::New(similarity); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDelta::Flags(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDelta::Flags) { + NanScope(); Handle to; uint32_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitDelta::constructor_template; +Persistent GitDelta::constructor_template; diff --git a/src/diff.cc b/src/diff.cc index 2573941ef..70fad85b6 100644 --- a/src/diff.cc +++ b/src/diff.cc @@ -24,12 +24,12 @@ GitDiff::~GitDiff() { } void GitDiff::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Diff")); + tpl->SetClassName(NanSymbol("Diff")); NODE_SET_METHOD(tpl, "treeToTree", TreeToTree); NODE_SET_METHOD(tpl, "treeToIndex", TreeToIndex); @@ -42,9 +42,8 @@ void GitDiff::Initialize(Handle target) { NODE_SET_METHOD(tpl, "numDeltasOfType", NumDeltasOfType); NODE_SET_PROTOTYPE_METHOD(tpl, "getPatch", GetPatch); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Diff"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Diff"), tpl->GetFunction()); } Handle GitDiff::New(const Arguments& args) { diff --git a/src/diff_file.cc b/src/diff_file.cc index c96d4c8be..6877b632d 100644 --- a/src/diff_file.cc +++ b/src/diff_file.cc @@ -24,13 +24,12 @@ GitDiffFile::~GitDiffFile() { } void GitDiffFile::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("DiffFile")); - + tpl->SetClassName(NanSymbol("DiffFile")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path); @@ -38,36 +37,38 @@ void GitDiffFile::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags); NODE_SET_PROTOTYPE_METHOD(tpl, "mode", Mode); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("DiffFile"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("DiffFile"), tpl->GetFunction()); } -Handle GitDiffFile::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_file is required."))); + return NanThrowError(String::New("git_diff_file is required.")); } - GitDiffFile* object = new GitDiffFile((git_diff_file *) External::Unwrap(args[0])); + GitDiffFile* object = new GitDiffFile((git_diff_file *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitDiffFile::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDiffFile::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_file *GitDiffFile::GetValue() { return this->raw; } - -Handle GitDiffFile::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::Oid) { + NanScope(); Handle to; git_oid *oid = @@ -81,51 +82,51 @@ Handle GitDiffFile::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffFile::Path(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::Path) { + NanScope(); Handle to; const char * path = ObjectWrap::Unwrap(args.This())->GetValue()->path; to = String::New(path); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffFile::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::Size) { + NanScope(); Handle to; git_off_t size = ObjectWrap::Unwrap(args.This())->GetValue()->size; to = Integer::New(size); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffFile::Flags(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::Flags) { + NanScope(); Handle to; uint32_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffFile::Mode(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFile::Mode) { + NanScope(); Handle to; uint16_t mode = ObjectWrap::Unwrap(args.This())->GetValue()->mode; to = Integer::New(mode); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitDiffFile::constructor_template; +Persistent GitDiffFile::constructor_template; diff --git a/src/diff_find_options.cc b/src/diff_find_options.cc index f6fd85756..c08151a6e 100644 --- a/src/diff_find_options.cc +++ b/src/diff_find_options.cc @@ -23,36 +23,39 @@ GitDiffFindOptions::~GitDiffFindOptions() { } void GitDiffFindOptions::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("DiffFindOptions")); + tpl->SetClassName(NanSymbol("DiffFindOptions")); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("DiffFindOptions"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("DiffFindOptions"), tpl->GetFunction()); } -Handle GitDiffFindOptions::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffFindOptions::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_find_options is required."))); + return NanThrowError(String::New("git_diff_find_options is required.")); } - GitDiffFindOptions* object = new GitDiffFindOptions((git_diff_find_options *) External::Unwrap(args[0])); + GitDiffFindOptions* object = new GitDiffFindOptions((git_diff_find_options *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } + Handle GitDiffFindOptions::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDiffFindOptions::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_find_options *GitDiffFindOptions::GetValue() { @@ -60,4 +63,4 @@ git_diff_find_options *GitDiffFindOptions::GetValue() { } -Persistent GitDiffFindOptions::constructor_template; +Persistent GitDiffFindOptions::constructor_template; diff --git a/src/diff_list.cc b/src/diff_list.cc index 2ef784398..d6239d813 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -30,12 +30,12 @@ GitDiffList::~GitDiffList() { } void GitDiffList::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("DiffList")); + tpl->SetClassName(NanSymbol("DiffList")); NODE_SET_PROTOTYPE_METHOD(tpl, "merge", Merge); NODE_SET_PROTOTYPE_METHOD(tpl, "findSimilar", FindSimilar); @@ -44,27 +44,30 @@ void GitDiffList::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "patch", Patch); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("DiffList"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("DiffList"), tpl->GetFunction()); } -Handle GitDiffList::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_list is required."))); + return NanThrowError(String::New("git_diff_list is required.")); } - GitDiffList* object = new GitDiffList((git_diff_list *) External::Unwrap(args[0])); + GitDiffList* object = new GitDiffList((git_diff_list *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitDiffList::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDiffList::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_list *GitDiffList::GetValue() { @@ -75,10 +78,10 @@ git_diff_list *GitDiffList::GetValue() { /** * @param {DiffList} from */ -Handle GitDiffList::Merge(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::Merge) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffList from is required."))); + return NanThrowError(String::New("DiffList from is required.")); } const git_diff_list * from_from; @@ -90,22 +93,22 @@ Handle GitDiffList::Merge(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {DiffFindOptions} options */ -Handle GitDiffList::FindSimilar(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::FindSimilar) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffFindOptions options is required."))); + return NanThrowError(String::New("DiffFindOptions options is required.")); } git_diff_find_options * from_options; @@ -117,20 +120,20 @@ Handle GitDiffList::FindSimilar(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @return {Number} result */ -Handle GitDiffList::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::Size) { + NanScope(); size_t result = git_diff_num_deltas( @@ -139,7 +142,7 @@ Handle GitDiffList::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** @@ -147,13 +150,13 @@ Handle GitDiffList::Size(const Arguments& args) { * @param {Number} type * @return {Number} result */ -Handle GitDiffList::NumDeltasOfType(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::NumDeltasOfType) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffList diff is required."))); + return NanThrowError(String::New("DiffList diff is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); + return NanThrowError(String::New("Number type is required.")); } git_diff_list * from_diff; @@ -168,7 +171,7 @@ Handle GitDiffList::NumDeltasOfType(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** @@ -176,10 +179,10 @@ Handle GitDiffList::NumDeltasOfType(const Arguments& args) { * @return {Patch} patch_out * @return {Delta} delta_out */ -Handle GitDiffList::Patch(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffList::Patch) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number idx is required."))); + return NanThrowError(String::New("Number idx is required.")); } git_diff_patch * patch_out = 0; @@ -195,9 +198,9 @@ Handle GitDiffList::Patch(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -220,7 +223,7 @@ Handle GitDiffList::Patch(const Arguments& args) { } toReturn->Set(String::NewSymbol("delta"), to); - return scope.Close(toReturn); + NanReturnValue(toReturn); } -Persistent GitDiffList::constructor_template; +Persistent GitDiffList::constructor_template; diff --git a/src/diff_options.cc b/src/diff_options.cc index dad3fd108..24407f98f 100644 --- a/src/diff_options.cc +++ b/src/diff_options.cc @@ -23,36 +23,38 @@ GitDiffOptions::~GitDiffOptions() { } void GitDiffOptions::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("DiffOptions")); + tpl->SetClassName(NanSymbol("DiffOptions")); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("DiffOptions"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("DiffOptions"), tpl->GetFunction()); } -Handle GitDiffOptions::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffOptions::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_options is required."))); + return NanThrowError(String::New("git_diff_options is required.")); } - GitDiffOptions* object = new GitDiffOptions((git_diff_options *) External::Unwrap(args[0])); + GitDiffOptions* object = new GitDiffOptions((git_diff_options *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitDiffOptions::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDiffOptions::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_options *GitDiffOptions::GetValue() { @@ -60,4 +62,4 @@ git_diff_options *GitDiffOptions::GetValue() { } -Persistent GitDiffOptions::constructor_template; +Persistent GitDiffOptions::constructor_template; diff --git a/src/diff_range.cc b/src/diff_range.cc index cacbd49b5..e91cefef1 100644 --- a/src/diff_range.cc +++ b/src/diff_range.cc @@ -23,89 +23,90 @@ GitDiffRange::~GitDiffRange() { } void GitDiffRange::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("DiffRange")); - + tpl->SetClassName(NanSymbol("DiffRange")); NODE_SET_PROTOTYPE_METHOD(tpl, "oldStart", OldStart); NODE_SET_PROTOTYPE_METHOD(tpl, "oldLines", OldLines); NODE_SET_PROTOTYPE_METHOD(tpl, "newStart", NewStart); NODE_SET_PROTOTYPE_METHOD(tpl, "newLines", NewLines); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("DiffRange"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("DiffRange"), tpl->GetFunction()); } -Handle GitDiffRange::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffRange::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_range is required."))); + return NanThrowError(String::New("git_diff_range is required.")); } - GitDiffRange* object = new GitDiffRange((git_diff_range *) External::Unwrap(args[0])); + GitDiffRange* object = new GitDiffRange((git_diff_range *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitDiffRange::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitDiffRange::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_range *GitDiffRange::GetValue() { return this->raw; } - -Handle GitDiffRange::OldStart(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffRange::OldStart) { + NanScope(); Handle to; int old_start = ObjectWrap::Unwrap(args.This())->GetValue()->old_start; to = Integer::New(old_start); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffRange::OldLines(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffRange::OldLines) { + NanScope(); Handle to; int old_lines = ObjectWrap::Unwrap(args.This())->GetValue()->old_lines; to = Integer::New(old_lines); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffRange::NewStart(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffRange::NewStart) { + NanScope(); Handle to; int new_start = ObjectWrap::Unwrap(args.This())->GetValue()->new_start; to = Integer::New(new_start); - return scope.Close(to); + NanReturnValue(to); } -Handle GitDiffRange::NewLines(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitDiffRange::NewLines) { + NanScope(); Handle to; int new_lines = ObjectWrap::Unwrap(args.This())->GetValue()->new_lines; to = Integer::New(new_lines); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitDiffRange::constructor_template; +Persistent GitDiffRange::constructor_template; diff --git a/src/index.cc b/src/index.cc index e0a800d15..205afbc82 100644 --- a/src/index.cc +++ b/src/index.cc @@ -29,12 +29,12 @@ GitIndex::~GitIndex() { } void GitIndex::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Index")); + tpl->SetClassName(NanSymbol("Index")); NODE_SET_METHOD(tpl, "open", Open); NODE_SET_PROTOTYPE_METHOD(tpl, "read", Read); @@ -54,28 +54,30 @@ void GitIndex::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "hasConflicts", HasConflicts); NODE_SET_METHOD(tpl, "indexToWorkdir", IndexToWorkdir); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Index"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Index"), tpl->GetFunction()); } -Handle GitIndex::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_index is required."))); + return NanThrowError(String::New("git_index is required.")); } - GitIndex* object = new GitIndex((git_index *) External::Unwrap(args[0])); + GitIndex* object = new GitIndex((git_index *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitIndex::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitIndex::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_index *GitIndex::GetValue() { @@ -89,30 +91,30 @@ git_index *GitIndex::GetValue() { * @param {String} index_path * @param {Index} callback */ -Handle GitIndex::Open(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Open) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String index_path is required."))); + return NanThrowError(String::New("String index_path is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } OpenBaton* baton = new OpenBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->index_pathReference = Persistent::New(args[0]); - const char * from_index_path; - String::Utf8Value index_path(args[0]->ToString()); - from_index_path = strdup(*index_path); - baton->index_path = from_index_path; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->index_pathReference, args[0]); + const char * from_index_path; + String::Utf8Value index_path(args[0]->ToString()); + from_index_path = strdup(*index_path); + baton->index_path = from_index_path; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::OpenWork(uv_work_t *req) { @@ -128,7 +130,7 @@ void GitIndex::OpenWork(uv_work_t *req) { } void GitIndex::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -141,21 +143,21 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -172,24 +174,24 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { /** */ -Handle GitIndex::Read(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Read) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ReadBaton* baton = new ReadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->indexReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->indexReference, args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReadWork, (uv_after_work_cb)ReadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::ReadWork(uv_work_t *req) { @@ -204,28 +206,28 @@ void GitIndex::ReadWork(uv_work_t *req) { } void GitIndex::ReadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -241,24 +243,24 @@ void GitIndex::ReadAfterWork(uv_work_t *req) { /** */ -Handle GitIndex::Write(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Write) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } WriteBaton* baton = new WriteBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->indexReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->indexReference, args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::WriteWork(uv_work_t *req) { @@ -273,28 +275,28 @@ void GitIndex::WriteWork(uv_work_t *req) { } void GitIndex::WriteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -311,31 +313,31 @@ void GitIndex::WriteAfterWork(uv_work_t *req) { /** * @param {Tree} tree */ -Handle GitIndex::ReadTree(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::ReadTree) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Tree tree is required."))); + return NanThrowError(String::New("Tree tree is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ReadTreeBaton* baton = new ReadTreeBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->indexReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->indexReference, args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->treeReference = Persistent::New(args[0]); - const git_tree * from_tree; - from_tree = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->tree = from_tree; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->treeReference, args[0]); + const git_tree * from_tree; + from_tree = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->tree = from_tree; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, ReadTreeWork, (uv_after_work_cb)ReadTreeAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::ReadTreeWork(uv_work_t *req) { @@ -351,30 +353,30 @@ void GitIndex::ReadTreeWork(uv_work_t *req) { } void GitIndex::ReadTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReadTreeBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -390,11 +392,11 @@ void GitIndex::ReadTreeAfterWork(uv_work_t *req) { /** * @param {Oid} callback */ -Handle GitIndex::WriteTree(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::WriteTree) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } WriteTreeBaton* baton = new WriteTreeBaton; @@ -402,13 +404,13 @@ Handle GitIndex::WriteTree(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - baton->indexReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->indexReference, args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, WriteTreeWork, (uv_after_work_cb)WriteTreeAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::WriteTreeWork(uv_work_t *req) { @@ -424,7 +426,7 @@ void GitIndex::WriteTreeWork(uv_work_t *req) { } void GitIndex::WriteTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -437,24 +439,24 @@ void GitIndex::WriteTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - free(baton->out); - } + free(baton->out); + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -467,8 +469,8 @@ void GitIndex::WriteTreeAfterWork(uv_work_t *req) { /** * @return {Number} result */ -Handle GitIndex::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Size) { + NanScope(); size_t result = git_index_entrycount( @@ -477,30 +479,30 @@ Handle GitIndex::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** */ -Handle GitIndex::Clear(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Clear) { + NanScope(); git_index_clear( ObjectWrap::Unwrap(args.This())->GetValue() ); - return Undefined(); + NanReturnUndefined(); } /** * @param {Number} n * @return {IndexEntry} result */ -Handle GitIndex::Entry(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Entry) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number n is required."))); + return NanThrowError(String::New("Number n is required.")); } size_t from_n; @@ -520,20 +522,20 @@ Handle GitIndex::Entry(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} path * @param {Number} stage */ -Handle GitIndex::Remove(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Remove) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number stage is required."))); + return NanThrowError(String::New("Number stage is required.")); } const char * from_path; @@ -550,26 +552,26 @@ Handle GitIndex::Remove(const Arguments& args) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {String} dir * @param {Number} stage */ -Handle GitIndex::RemoveDirectory(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::RemoveDirectory) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String dir is required."))); + return NanThrowError(String::New("String dir is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number stage is required."))); + return NanThrowError(String::New("Number stage is required.")); } const char * from_dir; @@ -586,13 +588,13 @@ Handle GitIndex::RemoveDirectory(const Arguments& args) { free((void *)from_dir); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -600,32 +602,32 @@ Handle GitIndex::RemoveDirectory(const Arguments& args) { /** * @param {String} path */ -Handle GitIndex::AddBypath(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::AddBypath) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } AddBypathBaton* baton = new AddBypathBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->indexReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->indexReference, args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->pathReference = Persistent::New(args[0]); - const char * from_path; - String::Utf8Value path(args[0]->ToString()); - from_path = strdup(*path); - baton->path = from_path; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->pathReference, args[0]); + const char * from_path; + String::Utf8Value path(args[0]->ToString()); + from_path = strdup(*path); + baton->path = from_path; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, AddBypathWork, (uv_after_work_cb)AddBypathAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::AddBypathWork(uv_work_t *req) { @@ -641,28 +643,28 @@ void GitIndex::AddBypathWork(uv_work_t *req) { } void GitIndex::AddBypathAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); AddBypathBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -679,10 +681,10 @@ void GitIndex::AddBypathAfterWork(uv_work_t *req) { /** * @param {String} path */ -Handle GitIndex::RemoveBypath(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::RemoveBypath) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } const char * from_path; @@ -696,23 +698,23 @@ Handle GitIndex::RemoveBypath(const Arguments& args) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {String} path * @return {Number} at_pos */ -Handle GitIndex::Find(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::Find) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } size_t at_pos = 0; @@ -729,16 +731,16 @@ Handle GitIndex::Find(const Arguments& args) { Handle to; to = Uint32::New(at_pos); - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} path */ -Handle GitIndex::ConflictRemove(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::ConflictRemove) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } const char * from_path; @@ -752,33 +754,33 @@ Handle GitIndex::ConflictRemove(const Arguments& args) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitIndex::ConflictCleanup(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::ConflictCleanup) { + NanScope(); git_index_conflict_cleanup( ObjectWrap::Unwrap(args.This())->GetValue() ); - return Undefined(); + NanReturnUndefined(); } /** * @return {Number} result */ -Handle GitIndex::HasConflicts(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::HasConflicts) { + NanScope(); int result = git_index_has_conflicts( @@ -787,7 +789,7 @@ Handle GitIndex::HasConflicts(const Arguments& args) { Handle to; to = Int32::New(result); - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -798,45 +800,45 @@ Handle GitIndex::HasConflicts(const Arguments& args) { * @param {DiffOptions} opts * @param {DiffList} callback */ -Handle GitIndex::IndexToWorkdir(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndex::IndexToWorkdir) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } IndexToWorkdirBaton* baton = new IndexToWorkdirBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->indexReference = Persistent::New(args[1]); - git_index * from_index; - if (args[1]->IsObject()) { - from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - } else { - from_index = 0; - } - baton->index = from_index; - baton->optsReference = Persistent::New(args[2]); - const git_diff_options * from_opts; - if (args[2]->IsObject()) { - from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - } else { - from_opts = 0; - } - baton->opts = from_opts; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->indexReference, args[1]); + git_index * from_index; + if (args[1]->IsObject()) { + from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_index = 0; + } + baton->index = from_index; + NanAssignPersistent(Value, baton->optsReference, args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, IndexToWorkdirWork, (uv_after_work_cb)IndexToWorkdirAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitIndex::IndexToWorkdirWork(uv_work_t *req) { @@ -854,7 +856,7 @@ void GitIndex::IndexToWorkdirWork(uv_work_t *req) { } void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); IndexToWorkdirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -867,21 +869,21 @@ void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -895,4 +897,4 @@ void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { delete baton; } -Persistent GitIndex::constructor_template; +Persistent GitIndex::constructor_template; diff --git a/src/index_entry.cc b/src/index_entry.cc index 933ffafda..7ce9f583b 100644 --- a/src/index_entry.cc +++ b/src/index_entry.cc @@ -25,13 +25,12 @@ GitIndexEntry::~GitIndexEntry() { } void GitIndexEntry::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("IndexEntry")); - + tpl->SetClassName(NanSymbol("IndexEntry")); NODE_SET_PROTOTYPE_METHOD(tpl, "ctime", Ctime); NODE_SET_PROTOTYPE_METHOD(tpl, "mtime", Mtime); @@ -46,36 +45,38 @@ void GitIndexEntry::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "flags_extended", FlagsExtended); NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("IndexEntry"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("IndexEntry"), tpl->GetFunction()); } -Handle GitIndexEntry::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_index_entry is required."))); + return NanThrowError(String::New("git_index_entry is required.")); } - GitIndexEntry* object = new GitIndexEntry((git_index_entry *) External::Unwrap(args[0])); + GitIndexEntry* object = new GitIndexEntry((git_index_entry *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitIndexEntry::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitIndexEntry::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_index_entry *GitIndexEntry::GetValue() { return this->raw; } - -Handle GitIndexEntry::Ctime(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Ctime) { + NanScope(); Handle to; git_index_time *ctime = @@ -89,11 +90,11 @@ Handle GitIndexEntry::Ctime(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Mtime(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Mtime) { + NanScope(); Handle to; git_index_time *mtime = @@ -107,77 +108,77 @@ Handle GitIndexEntry::Mtime(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Dev(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Dev) { + NanScope(); Handle to; unsigned int dev = ObjectWrap::Unwrap(args.This())->GetValue()->dev; to = Uint32::New(dev); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Ino(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Ino) { + NanScope(); Handle to; unsigned int ino = ObjectWrap::Unwrap(args.This())->GetValue()->ino; to = Uint32::New(ino); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Mode(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Mode) { + NanScope(); Handle to; uint16_t mode = ObjectWrap::Unwrap(args.This())->GetValue()->mode; to = Integer::New(mode); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Uid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Uid) { + NanScope(); Handle to; unsigned int uid = ObjectWrap::Unwrap(args.This())->GetValue()->uid; to = Uint32::New(uid); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::gid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::gid) { + NanScope(); Handle to; unsigned int gid = ObjectWrap::Unwrap(args.This())->GetValue()->gid; to = Uint32::New(gid); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::FileSize(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::FileSize) { + NanScope(); Handle to; unsigned int file_size = ObjectWrap::Unwrap(args.This())->GetValue()->file_size; to = Uint32::New(file_size); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Oid) { + NanScope(); Handle to; git_oid *oid = @@ -191,40 +192,40 @@ Handle GitIndexEntry::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Flags(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Flags) { + NanScope(); Handle to; uint16_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::FlagsExtended(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::FlagsExtended) { + NanScope(); Handle to; uint16_t flags_extended = ObjectWrap::Unwrap(args.This())->GetValue()->flags_extended; to = Integer::New(flags_extended); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexEntry::Path(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexEntry::Path) { + NanScope(); Handle to; char * path = ObjectWrap::Unwrap(args.This())->GetValue()->path; to = String::New(path); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitIndexEntry::constructor_template; +Persistent GitIndexEntry::constructor_template; diff --git a/src/index_time.cc b/src/index_time.cc index 5501bd61a..d44ac3ede 100644 --- a/src/index_time.cc +++ b/src/index_time.cc @@ -23,65 +23,66 @@ GitIndexTime::~GitIndexTime() { } void GitIndexTime::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("IndexTime")); - + tpl->SetClassName(NanSymbol("IndexTime")); NODE_SET_PROTOTYPE_METHOD(tpl, "seconds", Seconds); NODE_SET_PROTOTYPE_METHOD(tpl, "nanoseconds", Nanoseconds); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("IndexTime"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("IndexTime"), tpl->GetFunction()); } -Handle GitIndexTime::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexTime::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_index_time is required."))); + return NanThrowError(String::New("git_index_time is required.")); } - GitIndexTime* object = new GitIndexTime((git_index_time *) External::Unwrap(args[0])); + GitIndexTime* object = new GitIndexTime((git_index_time *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitIndexTime::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitIndexTime::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_index_time *GitIndexTime::GetValue() { return this->raw; } - -Handle GitIndexTime::Seconds(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexTime::Seconds) { + NanScope(); Handle to; git_time_t seconds = ObjectWrap::Unwrap(args.This())->GetValue()->seconds; to = Uint32::New(seconds); - return scope.Close(to); + NanReturnValue(to); } -Handle GitIndexTime::Nanoseconds(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitIndexTime::Nanoseconds) { + NanScope(); Handle to; unsigned int nanoseconds = ObjectWrap::Unwrap(args.This())->GetValue()->nanoseconds; to = Uint32::New(nanoseconds); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitIndexTime::constructor_template; +Persistent GitIndexTime::constructor_template; diff --git a/src/object.cc b/src/object.cc index a881eb29b..d9991c310 100644 --- a/src/object.cc +++ b/src/object.cc @@ -25,39 +25,41 @@ GitObject::~GitObject() { } void GitObject::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Object")); + tpl->SetClassName(NanSymbol("Object")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Object"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Object"), tpl->GetFunction()); } -Handle GitObject::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitObject::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_object is required."))); + return NanThrowError(String::New("git_object is required.")); } - GitObject* object = new GitObject((git_object *) External::Unwrap(args[0])); + GitObject* object = new GitObject((git_object *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitObject::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitObject::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_object *GitObject::GetValue() { @@ -68,8 +70,8 @@ git_object *GitObject::GetValue() { /** * @return {Oid} result */ -Handle GitObject::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitObject::Oid) { + NanScope(); const git_oid * result = git_object_id( @@ -85,14 +87,14 @@ Handle GitObject::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitObject::Type(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitObject::Type) { + NanScope(); git_otype result = git_object_type( @@ -101,7 +103,7 @@ Handle GitObject::Type(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -110,31 +112,31 @@ Handle GitObject::Type(const Arguments& args) { * @param {Number} target_type * @param {Object} callback */ -Handle GitObject::Peel(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number target_type is required."))); +NAN_METHOD(GitObject::Peel) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsInt32()) { + return NanThrowError(String::New("Number target_type is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } PeelBaton* baton = new PeelBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->objectReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->objectReference, args.This()); baton->object = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->target_typeReference = Persistent::New(args[0]); - git_otype from_target_type; - from_target_type = (git_otype) args[0]->ToInt32()->Value(); - baton->target_type = from_target_type; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->target_typeReference, args[0]); + git_otype from_target_type; + from_target_type = (git_otype) args[0]->ToInt32()->Value(); + baton->target_type = from_target_type; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, PeelWork, (uv_after_work_cb)PeelAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitObject::PeelWork(uv_work_t *req) { @@ -151,7 +153,7 @@ void GitObject::PeelWork(uv_work_t *req) { } void GitObject::PeelAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PeelBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -164,23 +166,23 @@ void GitObject::PeelAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal< Value >(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -191,4 +193,4 @@ void GitObject::PeelAfterWork(uv_work_t *req) { delete baton; } -Persistent GitObject::constructor_template; +Persistent GitObject::constructor_template; diff --git a/src/odb.cc b/src/odb.cc index 27ef552be..d820b6d27 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -26,12 +26,12 @@ GitOdb::~GitOdb() { } void GitOdb::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Odb")); + tpl->SetClassName(NanSymbol("Odb")); NODE_SET_METHOD(tpl, "create()", Create); NODE_SET_METHOD(tpl, "open", Open); @@ -45,28 +45,30 @@ void GitOdb::Initialize(Handle target) { NODE_SET_METHOD(tpl, "hash", Hash); NODE_SET_METHOD(tpl, "hashfile", Hashfile); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Odb"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Odb"), tpl->GetFunction()); } -Handle GitOdb::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_odb is required."))); + return NanThrowError(String::New("git_odb is required.")); } - GitOdb* object = new GitOdb((git_odb *) External::Unwrap(args[0])); + GitOdb* object = new GitOdb((git_odb *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitOdb::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitOdb::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_odb *GitOdb::GetValue() { @@ -77,8 +79,8 @@ git_odb *GitOdb::GetValue() { /** * @return {Odb} out */ -Handle GitOdb::Create(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Create) { + NanScope(); git_odb * out = 0; @@ -87,9 +89,9 @@ Handle GitOdb::Create(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -99,17 +101,17 @@ Handle GitOdb::Create(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} objects_dir * @return {Odb} out */ -Handle GitOdb::Open(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Open) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String objects_dir is required."))); + return NanThrowError(String::New("String objects_dir is required.")); } git_odb * out = 0; @@ -124,9 +126,9 @@ Handle GitOdb::Open(const Arguments& args) { free((void *)from_objects_dir); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -136,16 +138,16 @@ Handle GitOdb::Open(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} path */ -Handle GitOdb::AddDiskAlternate(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::AddDiskAlternate) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } const char * from_path; @@ -159,13 +161,13 @@ Handle GitOdb::AddDiskAlternate(const Arguments& args) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -174,31 +176,31 @@ Handle GitOdb::AddDiskAlternate(const Arguments& args) { * @param {Oid} id * @param {OdbObject} callback */ -Handle GitOdb::Read(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Read) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ReadBaton* baton = new ReadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->dbReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->dbReference, args.This()); baton->db = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, ReadWork, (uv_after_work_cb)ReadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitOdb::ReadWork(uv_work_t *req) { @@ -215,7 +217,7 @@ void GitOdb::ReadWork(uv_work_t *req) { } void GitOdb::ReadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReadBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -228,21 +230,21 @@ void GitOdb::ReadAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -261,16 +263,16 @@ void GitOdb::ReadAfterWork(uv_work_t *req) { * @param {Number} len * @return {OdbObject} out */ -Handle GitOdb::ReadPrefix(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::ReadPrefix) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Odb db is required."))); + return NanThrowError(String::New("Odb db is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid short_id is required."))); + return NanThrowError(String::New("Oid short_id is required.")); } if (args.Length() == 2 || !args[2]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number len is required."))); + return NanThrowError(String::New("Number len is required.")); } git_odb_object * out = 0; @@ -289,9 +291,9 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -301,7 +303,7 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -310,13 +312,13 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { * @return {Number} len_out * @return {Number} type_out */ -Handle GitOdb::ReadHeader(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::ReadHeader) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Odb db is required."))); + return NanThrowError(String::New("Odb db is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } size_t len_out = 0; @@ -334,9 +336,9 @@ Handle GitOdb::ReadHeader(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -348,16 +350,16 @@ Handle GitOdb::ReadHeader(const Arguments& args) { to = Int32::New(type_out); toReturn->Set(String::NewSymbol("type_out"), to); - return scope.Close(toReturn); + NanReturnValue(toReturn); } /** * @param {Oid} id */ -Handle GitOdb::Exists(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Exists) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } const git_oid * from_id; @@ -369,19 +371,19 @@ Handle GitOdb::Exists(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitOdb::Refresh(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Refresh) { + NanScope(); int result = git_odb_refresh( @@ -389,13 +391,13 @@ Handle GitOdb::Refresh(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -406,20 +408,20 @@ Handle GitOdb::Refresh(const Arguments& args) { * @param {Number} type * @param {Oid} callback */ -Handle GitOdb::Write(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Write) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String data is required."))); + return NanThrowError(String::New("String data is required.")); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number len is required."))); + return NanThrowError(String::New("Number len is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); + return NanThrowError(String::New("Number type is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } WriteBaton* baton = new WriteBaton; @@ -427,26 +429,26 @@ Handle GitOdb::Write(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - baton->odbReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->odbReference, args.This()); baton->odb = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->dataReference = Persistent::New(args[0]); - const void * from_data; - String::Utf8Value data(args[0]->ToString()); - from_data = strdup(*data); - baton->data = from_data; - baton->lenReference = Persistent::New(args[1]); - size_t from_len; - from_len = (size_t) args[1]->ToUint32()->Value(); - baton->len = from_len; - baton->typeReference = Persistent::New(args[2]); - git_otype from_type; - from_type = (git_otype) args[2]->ToInt32()->Value(); - baton->type = from_type; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->dataReference, args[0]); + const void * from_data; + String::Utf8Value data(args[0]->ToString()); + from_data = strdup(*data); + baton->data = from_data; + NanAssignPersistent(Value, baton->lenReference, args[1]); + size_t from_len; + from_len = (size_t) args[1]->ToUint32()->Value(); + baton->len = from_len; + NanAssignPersistent(Value, baton->typeReference, args[2]); + git_otype from_type; + from_type = (git_otype) args[2]->ToInt32()->Value(); + baton->type = from_type; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitOdb::WriteWork(uv_work_t *req) { @@ -465,7 +467,7 @@ void GitOdb::WriteWork(uv_work_t *req) { } void GitOdb::WriteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -478,21 +480,21 @@ void GitOdb::WriteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -515,16 +517,16 @@ void GitOdb::WriteAfterWork(uv_work_t *req) { * @param {Number} type * @return {Oid} out */ -Handle GitOdb::Hash(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Hash) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Buffer data is required."))); + return NanThrowError(String::New("Buffer data is required.")); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number len is required."))); + return NanThrowError(String::New("Number len is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); + return NanThrowError(String::New("Number type is required.")); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); @@ -544,9 +546,9 @@ Handle GitOdb::Hash(const Arguments& args) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -556,7 +558,7 @@ Handle GitOdb::Hash(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -564,13 +566,13 @@ Handle GitOdb::Hash(const Arguments& args) { * @param {Number} type * @return {Oid} out */ -Handle GitOdb::Hashfile(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Hashfile) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); + return NanThrowError(String::New("Number type is required.")); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); @@ -589,9 +591,9 @@ Handle GitOdb::Hashfile(const Arguments& args) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -601,7 +603,7 @@ Handle GitOdb::Hashfile(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitOdb::constructor_template; +Persistent GitOdb::constructor_template; diff --git a/src/odb_object.cc b/src/odb_object.cc index 507d63736..7c8db710e 100644 --- a/src/odb_object.cc +++ b/src/odb_object.cc @@ -25,40 +25,42 @@ GitOdbObject::~GitOdbObject() { } void GitOdbObject::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("OdbObject")); + tpl->SetClassName(NanSymbol("OdbObject")); NODE_SET_PROTOTYPE_METHOD(tpl, "data", Data); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("OdbObject"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("OdbObject"), tpl->GetFunction()); } -Handle GitOdbObject::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdbObject::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_odb_object is required."))); + return NanThrowError(String::New("git_odb_object is required.")); } - GitOdbObject* object = new GitOdbObject((git_odb_object *) External::Unwrap(args[0])); + GitOdbObject* object = new GitOdbObject((git_odb_object *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitOdbObject::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitOdbObject::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_odb_object *GitOdbObject::GetValue() { @@ -69,8 +71,8 @@ git_odb_object *GitOdbObject::GetValue() { /** * @return {Wrapper} result */ -Handle GitOdbObject::Data(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdbObject::Data) { + NanScope(); const void * result = git_odb_object_data( @@ -83,14 +85,14 @@ Handle GitOdbObject::Data(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitOdbObject::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdbObject::Size) { + NanScope(); size_t result = git_odb_object_size( @@ -99,14 +101,14 @@ Handle GitOdbObject::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitOdbObject::Type(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdbObject::Type) { + NanScope(); git_otype result = git_odb_object_type( @@ -115,14 +117,14 @@ Handle GitOdbObject::Type(const Arguments& args) { Handle to; to = Int32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Oid} result */ -Handle GitOdbObject::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdbObject::Oid) { + NanScope(); const git_oid * result = git_odb_object_id( @@ -138,7 +140,7 @@ Handle GitOdbObject::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitOdbObject::constructor_template; +Persistent GitOdbObject::constructor_template; diff --git a/src/oid.cc b/src/oid.cc index 0f354998f..b00c1feb8 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -23,38 +23,40 @@ GitOid::~GitOid() { } void GitOid::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Oid")); + tpl->SetClassName(NanSymbol("Oid")); NODE_SET_METHOD(tpl, "fromString", FromString); NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Oid"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Oid"), tpl->GetFunction()); } -Handle GitOid::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOid::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_oid is required."))); + return NanThrowError(String::New("git_oid is required.")); } - GitOid* object = new GitOid((git_oid *) External::Unwrap(args[0])); + GitOid* object = new GitOid((git_oid *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitOid::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitOid::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_oid *GitOid::GetValue() { @@ -66,10 +68,10 @@ git_oid *GitOid::GetValue() { * @param {String} str * @return {Oid} out */ -Handle GitOid::FromString(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOid::FromString) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String str is required."))); + return NanThrowError(String::New("String str is required.")); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); @@ -85,9 +87,9 @@ Handle GitOid::FromString(const Arguments& args) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -97,14 +99,14 @@ Handle GitOid::FromString(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitOid::Sha(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOid::Sha) { + NanScope(); char * result = git_oid_allocfmt( @@ -114,7 +116,7 @@ Handle GitOid::Sha(const Arguments& args) { Handle to; to = String::New(result); free(result); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitOid::constructor_template; +Persistent GitOid::constructor_template; diff --git a/src/patch.cc b/src/patch.cc index 1ee267a99..36ba451de 100644 --- a/src/patch.cc +++ b/src/patch.cc @@ -25,12 +25,12 @@ GitPatch::~GitPatch() { } void GitPatch::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Patch")); + tpl->SetClassName(NanSymbol("Patch")); NODE_SET_PROTOTYPE_METHOD(tpl, "delta", Delta); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); @@ -40,28 +40,30 @@ void GitPatch::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "line", Line); NODE_SET_METHOD(tpl, "toString", ToString); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Patch"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Patch"), tpl->GetFunction()); } -Handle GitPatch::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_diff_patch is required."))); + return NanThrowError(String::New("git_diff_patch is required.")); } - GitPatch* object = new GitPatch((git_diff_patch *) External::Unwrap(args[0])); + GitPatch* object = new GitPatch((git_diff_patch *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitPatch::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitPatch::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_diff_patch *GitPatch::GetValue() { @@ -72,8 +74,8 @@ git_diff_patch *GitPatch::GetValue() { /** * @return {Delta} result */ -Handle GitPatch::Delta(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Delta) { + NanScope(); const git_diff_delta * result = git_diff_patch_delta( @@ -89,14 +91,14 @@ Handle GitPatch::Delta(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitPatch::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Size) { + NanScope(); size_t result = git_diff_patch_num_hunks( @@ -105,7 +107,7 @@ Handle GitPatch::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** @@ -113,8 +115,8 @@ Handle GitPatch::Size(const Arguments& args) { * @return {Number} total_additions * @return {Number} total_deletions */ -Handle GitPatch::Stats(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Stats) { + NanScope(); size_t total_context = 0; size_t total_additions = 0; @@ -128,9 +130,9 @@ Handle GitPatch::Stats(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -145,7 +147,7 @@ Handle GitPatch::Stats(const Arguments& args) { to = Integer::New(total_deletions); toReturn->Set(String::NewSymbol("total_deletions"), to); - return scope.Close(toReturn); + NanReturnValue(toReturn); } /** @@ -155,10 +157,10 @@ Handle GitPatch::Stats(const Arguments& args) { * @return {Number} header_len * @return {Number} lines_in_hunk */ -Handle GitPatch::Hunk(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Hunk) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); + return NanThrowError(String::New("Number hunk_idx is required.")); } const git_diff_range * range = 0; @@ -178,9 +180,9 @@ Handle GitPatch::Hunk(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -205,17 +207,17 @@ Handle GitPatch::Hunk(const Arguments& args) { to = Uint32::New(lines_in_hunk); toReturn->Set(String::NewSymbol("lines"), to); - return scope.Close(toReturn); + NanReturnValue(toReturn); } /** * @param {Number} hunk_idx * @return {Number} result */ -Handle GitPatch::Lines(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Lines) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); + return NanThrowError(String::New("Number hunk_idx is required.")); } size_t from_hunk_idx; @@ -228,7 +230,7 @@ Handle GitPatch::Lines(const Arguments& args) { Handle to; to = Int32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** @@ -240,13 +242,13 @@ Handle GitPatch::Lines(const Arguments& args) { * @return {Number} old_lineno * @return {Number} new_lineno */ -Handle GitPatch::Line(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::Line) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); + return NanThrowError(String::New("Number hunk_idx is required.")); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number line_of_hunk is required."))); + return NanThrowError(String::New("Number line_of_hunk is required.")); } char line_origin = 0; @@ -271,9 +273,9 @@ Handle GitPatch::Line(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -294,14 +296,14 @@ Handle GitPatch::Line(const Arguments& args) { to = Int32::New(new_lineno); toReturn->Set(String::NewSymbol("newLineNumber"), to); - return scope.Close(toReturn); + NanReturnValue(toReturn); } /** * @return {String} string */ -Handle GitPatch::ToString(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitPatch::ToString) { + NanScope(); char * string = 0; @@ -311,16 +313,16 @@ Handle GitPatch::ToString(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } Handle to; to = String::New(string); free(string); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitPatch::constructor_template; +Persistent GitPatch::constructor_template; diff --git a/src/refdb.cc b/src/refdb.cc index d1b344d76..5f5074420 100644 --- a/src/refdb.cc +++ b/src/refdb.cc @@ -23,36 +23,38 @@ GitRefDb::~GitRefDb() { } void GitRefDb::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("RefDb")); + tpl->SetClassName(NanSymbol("RefDb")); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("RefDb"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("RefDb"), tpl->GetFunction()); } -Handle GitRefDb::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRefDb::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_refdb is required."))); + return NanThrowError(String::New("git_refdb is required.")); } - GitRefDb* object = new GitRefDb((git_refdb *) External::Unwrap(args[0])); + GitRefDb* object = new GitRefDb((git_refdb *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitRefDb::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitRefDb::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_refdb *GitRefDb::GetValue() { @@ -60,4 +62,4 @@ git_refdb *GitRefDb::GetValue() { } -Persistent GitRefDb::constructor_template; +Persistent GitRefDb::constructor_template; diff --git a/src/reference.cc b/src/reference.cc index 1bf677a98..4f1957410 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -26,12 +26,12 @@ GitReference::~GitReference() { } void GitReference::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Reference")); + tpl->SetClassName(NanSymbol("Reference")); NODE_SET_METHOD(tpl, "oidForName", OidForName); NODE_SET_PROTOTYPE_METHOD(tpl, "target", Target); @@ -48,28 +48,30 @@ void GitReference::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); NODE_SET_METHOD(tpl, "isValidName", IsValidName); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Reference"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Reference"), tpl->GetFunction()); } -Handle GitReference::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitReference::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_reference is required."))); + return NanThrowError(String::New("git_reference is required.")); } - GitReference* object = new GitReference((git_reference *) External::Unwrap(args[0])); + GitReference* object = new GitReference((git_reference *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitReference::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitReference::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_reference *GitReference::GetValue() { @@ -84,17 +86,18 @@ git_reference *GitReference::GetValue() { * @param {String} name * @param {Oid} callback */ -Handle GitReference::OidForName(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); +NAN_METHOD(GitReference::OidForName) { + NanScope(); + + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } OidForNameBaton* baton = new OidForNameBaton; @@ -102,20 +105,21 @@ Handle GitReference::OidForName(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->nameReference = Persistent::New(args[1]); - const char * from_name; - String::Utf8Value name(args[1]->ToString()); - from_name = strdup(*name); - baton->name = from_name; - baton->callback = Persistent::New(Local::Cast(args[2])); + + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->nameReference, args[1]); + const char * from_name; + String::Utf8Value name(args[1]->ToString()); + from_name = strdup(*name); + baton->name = from_name; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, OidForNameWork, (uv_after_work_cb)OidForNameAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitReference::OidForNameWork(uv_work_t *req) { @@ -132,7 +136,7 @@ void GitReference::OidForNameWork(uv_work_t *req) { } void GitReference::OidForNameAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OidForNameBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -145,24 +149,25 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -177,9 +182,9 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) { /** * @return {Oid} result */ -Handle GitReference::Target(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitReference::Target) { + NanScope(); + const git_oid * result = git_reference_target( ObjectWrap::Unwrap(args.This())->GetValue() @@ -194,14 +199,14 @@ Handle GitReference::Target(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitReference::SymbolicTarget(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitReference::SymbolicTarget) { + NanScope(); const char * result = git_reference_symbolic_target( @@ -210,15 +215,15 @@ Handle GitReference::SymbolicTarget(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitReference::Type(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitReference::Type) { + NanScope(); + git_ref_t result = git_reference_type( ObjectWrap::Unwrap(args.This())->GetValue() @@ -226,15 +231,15 @@ Handle GitReference::Type(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitReference::Name(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitReference::Name) { + NanScope(); + const char * result = git_reference_name( ObjectWrap::Unwrap(args.This())->GetValue() @@ -242,7 +247,7 @@ Handle GitReference::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -250,24 +255,25 @@ Handle GitReference::Name(const Arguments& args) { /** * @param {Reference} callback */ -Handle GitReference::Resolve(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitReference::Resolve) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ResolveBaton* baton = new ResolveBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->refReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->refReference, args.This()); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ResolveWork, (uv_after_work_cb)ResolveAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitReference::ResolveWork(uv_work_t *req) { @@ -283,7 +289,7 @@ void GitReference::ResolveWork(uv_work_t *req) { } void GitReference::ResolveAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ResolveBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -296,23 +302,23 @@ void GitReference::ResolveAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -326,10 +332,10 @@ void GitReference::ResolveAfterWork(uv_work_t *req) { * @param {String} target * @return {Reference} out */ -Handle GitReference::SetSymbolicTarget(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String target is required."))); +NAN_METHOD(GitReference::SetSymbolicTarget) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String target is required.")); } git_reference * out = 0; @@ -345,9 +351,9 @@ Handle GitReference::SetSymbolicTarget(const Arguments& args) { free((void *)from_target); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -357,17 +363,17 @@ Handle GitReference::SetSymbolicTarget(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {Oid} id * @return {Reference} out */ -Handle GitReference::setTarget(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitReference::setTarget) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } git_reference * out = 0; @@ -381,9 +387,9 @@ Handle GitReference::setTarget(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -393,7 +399,7 @@ Handle GitReference::setTarget(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -403,39 +409,39 @@ Handle GitReference::setTarget(const Arguments& args) { * @param {Number} force * @param {Reference} callback */ -Handle GitReference::Rename(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String new_name is required."))); +NAN_METHOD(GitReference::Rename) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String new_name is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number force is required."))); + return NanThrowError(String::New("Number force is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } RenameBaton* baton = new RenameBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->refReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->refReference, args.This()); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->new_nameReference = Persistent::New(args[0]); - const char * from_new_name; - String::Utf8Value new_name(args[0]->ToString()); - from_new_name = strdup(*new_name); - baton->new_name = from_new_name; - baton->forceReference = Persistent::New(args[1]); - int from_force; - from_force = (int) args[1]->ToInt32()->Value(); - baton->force = from_force; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->new_nameReference, args[0]); + const char * from_new_name; + String::Utf8Value new_name(args[0]->ToString()); + from_new_name = strdup(*new_name); + baton->new_name = from_new_name; + NanAssignPersistent(Value, baton->forceReference, args[1]); + int from_force; + from_force = (int) args[1]->ToInt32()->Value(); + baton->force = from_force; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, RenameWork, (uv_after_work_cb)RenameAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitReference::RenameWork(uv_work_t *req) { @@ -453,36 +459,36 @@ void GitReference::RenameWork(uv_work_t *req) { } void GitReference::RenameAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); RenameBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { Handle to; - if (baton->out != NULL) { + if (baton->out != NULL) { to = GitReference::New((void *)baton->out); } else { to = Null(); } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -499,24 +505,24 @@ void GitReference::RenameAfterWork(uv_work_t *req) { /** */ -Handle GitReference::Delete(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitReference::Delete) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DeleteBaton* baton = new DeleteBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->refReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->refReference, Local::Cast(args.This())); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, DeleteWork, (uv_after_work_cb)DeleteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitReference::DeleteWork(uv_work_t *req) { @@ -531,30 +537,30 @@ void GitReference::DeleteWork(uv_work_t *req) { } void GitReference::DeleteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DeleteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -566,28 +572,27 @@ void GitReference::DeleteAfterWork(uv_work_t *req) { /** */ -Handle GitReference::IsBranch(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitReference::IsBranch) { + NanScope(); int result = git_reference_is_branch( ObjectWrap::Unwrap(args.This())->GetValue() ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitReference::IsRemote(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitReference::IsRemote) { + NanScope(); int result = git_reference_is_remote( @@ -595,23 +600,23 @@ Handle GitReference::IsRemote(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {Number} type * @return {Object} out */ -Handle GitReference::Peel(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); +NAN_METHOD(GitReference::Peel) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsInt32()) { + return NanThrowError(String::New("Number type is required.")); } git_object * out = 0; @@ -625,9 +630,9 @@ Handle GitReference::Peel(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -637,16 +642,16 @@ Handle GitReference::Peel(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} refname */ -Handle GitReference::IsValidName(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String refname is required."))); +NAN_METHOD(GitReference::IsValidName) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String refname is required.")); } const char * from_refname; @@ -659,13 +664,13 @@ Handle GitReference::IsValidName(const Arguments& args) { free((void *)from_refname); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } -Persistent GitReference::constructor_template; +Persistent GitReference::constructor_template; diff --git a/src/remote.cc b/src/remote.cc index 73f0cd81d..7945b9ee5 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -24,12 +24,12 @@ GitRemote::~GitRemote() { } void GitRemote::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Remote")); + tpl->SetClassName(NanSymbol("Remote")); NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); NODE_SET_PROTOTYPE_METHOD(tpl, "url", Url); @@ -50,27 +50,30 @@ void GitRemote::Initialize(Handle target) { NODE_SET_METHOD(tpl, "isValidName", IsValidName); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Remote"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Remote"), tpl->GetFunction()); } -Handle GitRemote::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_remote is required."))); + return NanThrowError(String::New("git_remote is required.")); } - GitRemote* object = new GitRemote((git_remote *) External::Unwrap(args[0])); + GitRemote* object = new GitRemote((git_remote *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitRemote::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitRemote::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_remote *GitRemote::GetValue() { @@ -81,8 +84,8 @@ git_remote *GitRemote::GetValue() { /** * @return {String} result */ -Handle GitRemote::Name(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Name) { + NanScope(); const char * result = git_remote_name( @@ -91,14 +94,14 @@ Handle GitRemote::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitRemote::Url(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Url) { + NanScope(); const char * result = git_remote_url( @@ -107,14 +110,14 @@ Handle GitRemote::Url(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitRemote::PushUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::PushUrl) { + NanScope(); const char * result = git_remote_pushurl( @@ -123,16 +126,16 @@ Handle GitRemote::PushUrl(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} url */ -Handle GitRemote::SetUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::SetUrl) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } const char* from_url; @@ -146,22 +149,22 @@ Handle GitRemote::SetUrl(const Arguments& args) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {String} url */ -Handle GitRemote::SetPushUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::SetPushUrl) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } const char* from_url; @@ -175,13 +178,13 @@ Handle GitRemote::SetPushUrl(const Arguments& args) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -189,31 +192,31 @@ Handle GitRemote::SetPushUrl(const Arguments& args) { /** * @param {Number} direction */ -Handle GitRemote::Connect(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Connect) { + NanScope(); if (args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Number direction is required."))); + return NanThrowError(String::New("Number direction is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ConnectBaton* baton = new ConnectBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->remoteReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->remoteReference, args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->directionReference = Persistent::New(args[0]); - git_direction from_direction; - from_direction = (git_direction) args[0]->ToNumber()->Value(); - baton->direction = from_direction; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->directionReference, args[0]); + git_direction from_direction; + from_direction = (git_direction) args[0]->ToNumber()->Value(); + baton->direction = from_direction; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, ConnectWork, (uv_after_work_cb)ConnectAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRemote::ConnectWork(uv_work_t *req) { @@ -229,28 +232,28 @@ void GitRemote::ConnectWork(uv_work_t *req) { } void GitRemote::ConnectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ConnectBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -269,33 +272,34 @@ void GitRemote::ConnectAfterWork(uv_work_t *req) { * @param {Function} progress_cb * @param {void} payload */ -Handle GitRemote::Download(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Download) { + NanScope(); if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DownloadBaton* baton = new DownloadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->remoteReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->remoteReference, args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->progress_cbReference = Persistent::New(args[0]); - git_transfer_progress_callback from_progress_cb; - if (args[0]->IsFunction()) { - Persistent::New(Local::Cast(args[0])); - } else { - from_progress_cb = 0; - } - baton->progress_cb = from_progress_cb; - baton->payloadReference = Persistent::New(args[1]); - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->progress_cbReference, args[0]); + git_transfer_progress_callback from_progress_cb; + if (!args[0]->IsFunction()) { + //TODO Make progress callback work + //NanAssignPersistent(Function, baton->progress_cb, Local::Cast(args[0])); + } else { + from_progress_cb = 0; + } + baton->progress_cb = from_progress_cb; + NanAssignPersistent(Value, baton->payloadReference, args[1]); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, DownloadWork, (uv_after_work_cb)DownloadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRemote::DownloadWork(uv_work_t *req) { @@ -312,28 +316,28 @@ void GitRemote::DownloadWork(uv_work_t *req) { } void GitRemote::DownloadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DownloadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -349,8 +353,8 @@ void GitRemote::DownloadAfterWork(uv_work_t *req) { /** */ -Handle GitRemote::Connected(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Connected) { + NanScope(); int result = git_remote_connected( @@ -358,50 +362,50 @@ Handle GitRemote::Connected(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitRemote::Stop(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Stop) { + NanScope(); git_remote_stop( ObjectWrap::Unwrap(args.This())->GetValue() ); - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" /** */ -Handle GitRemote::Disconnect(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::Disconnect) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DisconnectBaton* baton = new DisconnectBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->remoteReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->remoteReference, args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, DisconnectWork, (uv_after_work_cb)DisconnectAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRemote::DisconnectWork(uv_work_t *req) { @@ -412,28 +416,28 @@ void GitRemote::DisconnectWork(uv_work_t *req) { } void GitRemote::DisconnectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DisconnectBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -447,8 +451,8 @@ void GitRemote::DisconnectAfterWork(uv_work_t *req) { /** */ -Handle GitRemote::UpdateTips(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::UpdateTips) { + NanScope(); int result = git_remote_update_tips( @@ -456,22 +460,22 @@ Handle GitRemote::UpdateTips(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {String} url */ -Handle GitRemote::ValidUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::ValidUrl) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } const char * from_url; @@ -484,22 +488,22 @@ Handle GitRemote::ValidUrl(const Arguments& args) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {String} url */ -Handle GitRemote::SupportedUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::SupportedUrl) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } const char* from_url; @@ -512,22 +516,22 @@ Handle GitRemote::SupportedUrl(const Arguments& args) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {Number} check */ -Handle GitRemote::CheckCert(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::CheckCert) { + NanScope(); if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number check is required."))); + return NanThrowError(String::New("Number check is required.")); } int from_check; @@ -538,13 +542,13 @@ Handle GitRemote::CheckCert(const Arguments& args) { , from_check ); - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitRemote::UpdateFetchhead(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::UpdateFetchhead) { + NanScope(); int result = git_remote_update_fetchhead( @@ -552,22 +556,22 @@ Handle GitRemote::UpdateFetchhead(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @param {Number} value */ -Handle GitRemote::SetUpdateFetchhead(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::SetUpdateFetchhead) { + NanScope(); if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number value is required."))); + return NanThrowError(String::New("Number value is required.")); } int from_value; @@ -578,16 +582,16 @@ Handle GitRemote::SetUpdateFetchhead(const Arguments& args) { , from_value ); - return Undefined(); + NanReturnUndefined(); } /** * @param {String} remote_name */ -Handle GitRemote::IsValidName(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRemote::IsValidName) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String remote_name is required."))); + return NanThrowError(String::New("String remote_name is required.")); } const char * from_remote_name; @@ -600,13 +604,13 @@ Handle GitRemote::IsValidName(const Arguments& args) { free((void *)from_remote_name); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } -Persistent GitRemote::constructor_template; +Persistent GitRemote::constructor_template; diff --git a/src/repo.cc b/src/repo.cc index e8ce988a0..279252df2 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -39,7 +39,7 @@ GitRepo::~GitRepo() { } void GitRepo::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); @@ -76,28 +76,32 @@ void GitRepo::Initialize(Handle target) { NODE_SET_METHOD(tpl, "clone", Clone); NODE_SET_PROTOTYPE_METHOD(tpl, "getRemote", GetRemote); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Repo"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Repo"), tpl->GetFunction()); } -Handle GitRepo::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_repository is required."))); + return NanThrowError(String::New("git_repository is required.")); } - GitRepo* object = new GitRepo((git_repository *) External::Unwrap(args[0])); + GitRepo* object = new GitRepo((git_repository *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitRepo::New(void *raw) { - HandleScope scope; + NanScope(); + Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitRepo::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + + return scope.Close(instance); } git_repository *GitRepo::GetValue() { @@ -111,30 +115,30 @@ git_repository *GitRepo::GetValue() { * @param {String} path * @param {Repository} callback */ -Handle GitRepo::Open(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::Open) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } OpenBaton* baton = new OpenBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->pathReference = Persistent::New(args[0]); - const char * from_path; - String::Utf8Value path(args[0]->ToString()); - from_path = strdup(*path); - baton->path = from_path; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->pathReference, args[0]); + const char * from_path; + String::Utf8Value path(args[0]->ToString()); + from_path = strdup(*path); + baton->path = from_path; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::OpenWork(uv_work_t *req) { @@ -150,7 +154,7 @@ void GitRepo::OpenWork(uv_work_t *req) { } void GitRepo::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -163,23 +167,23 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -197,37 +201,37 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { * @param {Boolean} is_bare * @param {Repository} callback */ -Handle GitRepo::Init(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); +NAN_METHOD(GitRepo::Init) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsBoolean()) { - return ThrowException(Exception::Error(String::New("Boolean is_bare is required."))); + return NanThrowError(String::New("Boolean is_bare is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } InitBaton* baton = new InitBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->pathReference = Persistent::New(args[0]); - const char * from_path; - String::Utf8Value path(args[0]->ToString()); - from_path = strdup(*path); - baton->path = from_path; - baton->is_bareReference = Persistent::New(args[1]); - unsigned from_is_bare; - from_is_bare = (unsigned) args[1]->ToBoolean()->Value(); - baton->is_bare = from_is_bare; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->pathReference, args[0]); + const char * from_path; + String::Utf8Value path(args[0]->ToString()); + from_path = strdup(*path); + baton->path = from_path; + NanAssignPersistent(Value, baton->is_bareReference, args[1]); + unsigned from_is_bare; + from_is_bare = (unsigned) args[1]->ToBoolean()->Value(); + baton->is_bare = from_is_bare; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, InitWork, (uv_after_work_cb)InitAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::InitWork(uv_work_t *req) { @@ -244,7 +248,7 @@ void GitRepo::InitWork(uv_work_t *req) { } void GitRepo::InitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); InitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -257,23 +261,23 @@ void GitRepo::InitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -288,8 +292,8 @@ void GitRepo::InitAfterWork(uv_work_t *req) { /** * @return {String} result */ -Handle GitRepo::Path(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::Path) { + NanScope(); const char * result = git_repository_path( @@ -298,14 +302,14 @@ Handle GitRepo::Path(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitRepo::Workdir(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::Workdir) { + NanScope(); const char * result = git_repository_workdir( @@ -314,14 +318,14 @@ Handle GitRepo::Workdir(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Odb} out */ -Handle GitRepo::Odb(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::Odb) { + NanScope(); git_odb * out = 0; @@ -331,9 +335,9 @@ Handle GitRepo::Odb(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -343,7 +347,7 @@ Handle GitRepo::Odb(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -351,24 +355,24 @@ Handle GitRepo::Odb(const Arguments& args) { /** * @param {Index} callback */ -Handle GitRepo::openIndex(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::openIndex) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } openIndexBaton* baton = new openIndexBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, openIndexWork, (uv_after_work_cb)openIndexAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::openIndexWork(uv_work_t *req) { @@ -384,7 +388,7 @@ void GitRepo::openIndexWork(uv_work_t *req) { } void GitRepo::openIndexAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); openIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -397,23 +401,23 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -429,31 +433,31 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Blob} callback */ -Handle GitRepo::GetBlob(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitRepo::GetBlob) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetBlobBaton* baton = new GetBlobBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetBlobWork, (uv_after_work_cb)GetBlobAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetBlobWork(uv_work_t *req) { @@ -470,7 +474,7 @@ void GitRepo::GetBlobWork(uv_work_t *req) { } void GitRepo::GetBlobAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetBlobBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -483,21 +487,21 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -516,31 +520,31 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Commit} callback */ -Handle GitRepo::GetCommit(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitRepo::GetCommit) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetCommitBaton* baton = new GetCommitBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetCommitWork, (uv_after_work_cb)GetCommitAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetCommitWork(uv_work_t *req) { @@ -557,7 +561,7 @@ void GitRepo::GetCommitWork(uv_work_t *req) { } void GitRepo::GetCommitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -570,23 +574,23 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -610,29 +614,29 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { * @param {Array} parents * @param {Oid} callback */ -Handle GitRepo::CreateCommit(const Arguments& args) { - HandleScope scope; - if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Signature author is required."))); +NAN_METHOD(GitRepo::CreateCommit) { + NanScope(); + if (args.Length() == 1 || !args[1]->IsObject()) { + return NanThrowError(String::New("Signature author is required.")); } if (args.Length() == 2 || !args[2]->IsObject()) { - return ThrowException(Exception::Error(String::New("Signature committer is required."))); + return NanThrowError(String::New("Signature committer is required.")); } if (args.Length() == 4 || !args[4]->IsString()) { - return ThrowException(Exception::Error(String::New("String message is required."))); + return NanThrowError(String::New("String message is required.")); } if (args.Length() == 5 || !args[5]->IsObject()) { - return ThrowException(Exception::Error(String::New("Tree tree is required."))); + return NanThrowError(String::New("Tree tree is required.")); } if (args.Length() == 6 || !args[6]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number parent_count is required."))); + return NanThrowError(String::New("Number parent_count is required.")); } if (args.Length() == 7 || !args[7]->IsObject()) { - return ThrowException(Exception::Error(String::New("Array parents is required."))); + return NanThrowError(String::New("Array parents is required.")); } if (args.Length() == 8 || !args[8]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CreateCommitBaton* baton = new CreateCommitBaton; @@ -640,61 +644,60 @@ Handle GitRepo::CreateCommit(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->update_refReference = Persistent::New(args[0]); - const char * from_update_ref; - if (args[0]->IsString()) { - String::Utf8Value update_ref(args[0]->ToString()); - from_update_ref = strdup(*update_ref); - } else { - from_update_ref = 0; - } - baton->update_ref = from_update_ref; - baton->authorReference = Persistent::New(args[1]); - const git_signature * from_author; - from_author = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->author = from_author; - baton->committerReference = Persistent::New(args[2]); - const git_signature * from_committer; - from_committer = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - baton->committer = from_committer; - baton->message_encodingReference = Persistent::New(args[3]); - const char * from_message_encoding; - if (args[3]->IsString()) { - String::Utf8Value message_encoding(args[3]->ToString()); - from_message_encoding = strdup(*message_encoding); - } else { - from_message_encoding = 0; - } - baton->message_encoding = from_message_encoding; - baton->messageReference = Persistent::New(args[4]); - const char * from_message; - String::Utf8Value message(args[4]->ToString()); - from_message = strdup(*message); - baton->message = from_message; - baton->treeReference = Persistent::New(args[5]); - const git_tree * from_tree; - from_tree = ObjectWrap::Unwrap(args[5]->ToObject())->GetValue(); - baton->tree = from_tree; - baton->parent_countReference = Persistent::New(args[6]); - int from_parent_count; - from_parent_count = (int) args[6]->ToInt32()->Value(); - baton->parent_count = from_parent_count; - baton->parentsReference = Persistent::New(args[7]); - const git_commit ** from_parents; - Array *tmp_parents = Array::Cast(*args[7]); - from_parents = (const git_commit **)malloc(tmp_parents->Length() * sizeof(const git_commit *)); - for (unsigned int i = 0; i < tmp_parents->Length(); i++) { - - from_parents[i] = ObjectWrap::Unwrap(tmp_parents->Get(Number::New(static_cast(i)))->ToObject())->GetValue(); - } - baton->parents = from_parents; - baton->callback = Persistent::New(Local::Cast(args[8])); + NanAssignPersistent(Value, baton->update_refReference, args[0]); + const char * from_update_ref; + if (args[0]->IsString()) { + String::Utf8Value update_ref(args[0]->ToString()); + from_update_ref = strdup(*update_ref); + } else { + from_update_ref = 0; + } + baton->update_ref = from_update_ref; + NanAssignPersistent(Value, baton->authorReference, args[1]); + const git_signature * from_author; + from_author = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->author = from_author; + NanAssignPersistent(Value, baton->committerReference, args[2]); + const git_signature * from_committer; + from_committer = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + baton->committer = from_committer; + NanAssignPersistent(Value, baton->message_encodingReference, args[3]); + const char * from_message_encoding; + if (args[3]->IsString()) { + String::Utf8Value message_encoding(args[3]->ToString()); + from_message_encoding = strdup(*message_encoding); + } else { + from_message_encoding = 0; + } + baton->message_encoding = from_message_encoding; + NanAssignPersistent(Value, baton->messageReference, args[4]); + const char * from_message; + String::Utf8Value message(args[4]->ToString()); + from_message = strdup(*message); + baton->message = from_message; + NanAssignPersistent(Value, baton->treeReference, args[5]); + const git_tree * from_tree; + from_tree = ObjectWrap::Unwrap(args[5]->ToObject())->GetValue(); + baton->tree = from_tree; + NanAssignPersistent(Value, baton->parent_countReference, args[6]); + int from_parent_count; + from_parent_count = (int) args[6]->ToInt32()->Value(); + baton->parent_count = from_parent_count; + NanAssignPersistent(Value, baton->parentsReference, args[7]); + const git_commit ** from_parents; + Array *tmp_parents = Array::Cast(*args[7]); + from_parents = (const git_commit **)malloc(tmp_parents->Length() * sizeof(const git_commit *)); + for (unsigned int i = 0; i < tmp_parents->Length(); i++) { + from_parents[i] = ObjectWrap::Unwrap(tmp_parents->Get(Number::New(static_cast(i)))->ToObject())->GetValue(); + } + baton->parents = from_parents; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[8])); uv_queue_work(uv_default_loop(), &baton->request, CreateCommitWork, (uv_after_work_cb)CreateCommitAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CreateCommitWork(uv_work_t *req) { @@ -718,7 +721,7 @@ void GitRepo::CreateCommitWork(uv_work_t *req) { } void GitRepo::CreateCommitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -731,24 +734,24 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - free(baton->id); - } + free(baton->id); + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -777,38 +780,39 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { * @param {Number} type * @param {Object} callback */ -Handle GitRepo::GetObject(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitRepo::GetObject) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type is required."))); + return NanThrowError(String::New("Number type is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetObjectBaton* baton = new GetObjectBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->typeReference = Persistent::New(args[1]); - git_otype from_type; - from_type = (git_otype) args[1]->ToInt32()->Value(); - baton->type = from_type; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Value, baton->typeReference, args[1]); + + git_otype from_type; + from_type = (git_otype) args[1]->ToInt32()->Value(); + baton->type = from_type; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, GetObjectWork, (uv_after_work_cb)GetObjectAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetObjectWork(uv_work_t *req) { @@ -826,7 +830,7 @@ void GitRepo::GetObjectWork(uv_work_t *req) { } void GitRepo::GetObjectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -839,21 +843,21 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -873,32 +877,32 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { * @param {String} name * @param {Reference} callback */ -Handle GitRepo::GetReference(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::GetReference) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetReferenceBaton* baton = new GetReferenceBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->nameReference = Persistent::New(args[0]); - const char * from_name; - String::Utf8Value name(args[0]->ToString()); - from_name = strdup(*name); - baton->name = from_name; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->nameReference, args[0]); + const char * from_name; + String::Utf8Value name(args[0]->ToString()); + from_name = strdup(*name); + baton->name = from_name; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetReferenceWork, (uv_after_work_cb)GetReferenceAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetReferenceWork(uv_work_t *req) { @@ -915,7 +919,7 @@ void GitRepo::GetReferenceWork(uv_work_t *req) { } void GitRepo::GetReferenceAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetReferenceBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -928,21 +932,21 @@ void GitRepo::GetReferenceAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -962,16 +966,16 @@ void GitRepo::GetReferenceAfterWork(uv_work_t *req) { * @param {Number} force * @return {Reference} out */ -Handle GitRepo::CreateSymbolicReference(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::CreateSymbolicReference) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String target is required."))); + return NanThrowError(String::New("String target is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number force is required."))); + return NanThrowError(String::New("Number force is required.")); } git_reference * out = 0; @@ -995,9 +999,9 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { free((void *)from_target); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -1007,7 +1011,7 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -1016,16 +1020,16 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { * @param {Number} force * @return {Reference} out */ -Handle GitRepo::CreateReference(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::CreateReference) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number force is required."))); + return NanThrowError(String::New("Number force is required.")); } git_reference * out = 0; @@ -1047,9 +1051,9 @@ Handle GitRepo::CreateReference(const Arguments& args) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -1059,7 +1063,7 @@ Handle GitRepo::CreateReference(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -1069,40 +1073,40 @@ Handle GitRepo::CreateReference(const Arguments& args) { * @param {String} url * @param {Remote} callback */ -Handle GitRepo::AddRemote(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::AddRemote) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } AddRemoteBaton* baton = new AddRemoteBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->nameReference = Persistent::New(args[0]); - const char * from_name; - String::Utf8Value name(args[0]->ToString()); - from_name = strdup(*name); - baton->name = from_name; - baton->urlReference = Persistent::New(args[1]); - const char * from_url; - String::Utf8Value url(args[1]->ToString()); - from_url = strdup(*url); - baton->url = from_url; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->nameReference, args[0]); + const char * from_name; + String::Utf8Value name(args[0]->ToString()); + from_name = strdup(*name); + baton->name = from_name; + NanAssignPersistent(Value, baton->urlReference, args[1]); + const char * from_url; + String::Utf8Value url(args[1]->ToString()); + from_url = strdup(*url); + baton->url = from_url; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, AddRemoteWork, (uv_after_work_cb)AddRemoteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::AddRemoteWork(uv_work_t *req) { @@ -1120,7 +1124,7 @@ void GitRepo::AddRemoteWork(uv_work_t *req) { } void GitRepo::AddRemoteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); AddRemoteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1133,21 +1137,21 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1166,8 +1170,8 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { /** * @return {RevWalk} out */ -Handle GitRepo::CreateRevWalk(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::CreateRevWalk) { + NanScope(); git_revwalk * out = 0; @@ -1177,9 +1181,9 @@ Handle GitRepo::CreateRevWalk(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -1189,17 +1193,17 @@ Handle GitRepo::CreateRevWalk(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} name * @return {Submodule} submodule */ -Handle GitRepo::GetSubmodule(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::GetSubmodule) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } git_submodule * submodule = 0; @@ -1215,9 +1219,9 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -1227,7 +1231,7 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -1236,16 +1240,16 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { * @param {Number} use_gitlink * @return {Submodule} submodule */ -Handle GitRepo::AddSubmodule(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); +NAN_METHOD(GitRepo::AddSubmodule) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String url is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number use_gitlink is required."))); + return NanThrowError(String::New("Number use_gitlink is required.")); } git_submodule * submodule = 0; @@ -1269,9 +1273,9 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -1281,7 +1285,7 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -1290,31 +1294,31 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { * @param {Oid} id * @param {Tag} callback */ -Handle GitRepo::GetTag(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitRepo::GetTag) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetTagBaton* baton = new GetTagBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetTagWork, (uv_after_work_cb)GetTagAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetTagWork(uv_work_t *req) { @@ -1331,7 +1335,7 @@ void GitRepo::GetTagWork(uv_work_t *req) { } void GitRepo::GetTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1344,21 +1348,21 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1381,26 +1385,26 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { * @param {Number} force * @param {Oid} callback */ -Handle GitRepo::CreateTag(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String tag_name is required."))); +NAN_METHOD(GitRepo::CreateTag) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String tag_name is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Object target is required."))); + return NanThrowError(String::New("Object target is required.")); } if (args.Length() == 2 || !args[2]->IsObject()) { - return ThrowException(Exception::Error(String::New("Signature tagger is required."))); + return NanThrowError(String::New("Signature tagger is required.")); } if (args.Length() == 3 || !args[3]->IsString()) { - return ThrowException(Exception::Error(String::New("String message is required."))); + return NanThrowError(String::New("String message is required.")); } if (args.Length() == 4 || !args[4]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number force is required."))); + return NanThrowError(String::New("Number force is required.")); } if (args.Length() == 5 || !args[5]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CreateTagBaton* baton = new CreateTagBaton; @@ -1408,35 +1412,35 @@ Handle GitRepo::CreateTag(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->tag_nameReference = Persistent::New(args[0]); - const char * from_tag_name; - String::Utf8Value tag_name(args[0]->ToString()); - from_tag_name = strdup(*tag_name); - baton->tag_name = from_tag_name; - baton->targetReference = Persistent::New(args[1]); - const git_object * from_target; - from_target = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->target = from_target; - baton->taggerReference = Persistent::New(args[2]); - const git_signature * from_tagger; - from_tagger = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - baton->tagger = from_tagger; - baton->messageReference = Persistent::New(args[3]); - const char * from_message; - String::Utf8Value message(args[3]->ToString()); - from_message = strdup(*message); - baton->message = from_message; - baton->forceReference = Persistent::New(args[4]); - int from_force; - from_force = (int) args[4]->ToInt32()->Value(); - baton->force = from_force; - baton->callback = Persistent::New(Local::Cast(args[5])); + NanAssignPersistent(Value, baton->tag_nameReference, args[0]); + const char * from_tag_name; + String::Utf8Value tag_name(args[0]->ToString()); + from_tag_name = strdup(*tag_name); + baton->tag_name = from_tag_name; + NanAssignPersistent(Value, baton->targetReference, args[1]); + const git_object * from_target; + from_target = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->target = from_target; + NanAssignPersistent(Value, baton->taggerReference, args[2]); + const git_signature * from_tagger; + from_tagger = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + baton->tagger = from_tagger; + NanAssignPersistent(Value, baton->messageReference, args[3]); + const char * from_message; + String::Utf8Value message(args[3]->ToString()); + from_message = strdup(*message); + baton->message = from_message; + NanAssignPersistent(Value, baton->forceReference, args[4]); + int from_force; + from_force = (int) args[4]->ToInt32()->Value(); + baton->force = from_force; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[5])); uv_queue_work(uv_default_loop(), &baton->request, CreateTagWork, (uv_after_work_cb)CreateTagAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CreateTagWork(uv_work_t *req) { @@ -1457,7 +1461,7 @@ void GitRepo::CreateTagWork(uv_work_t *req) { } void GitRepo::CreateTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1470,21 +1474,21 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -1512,20 +1516,20 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { * @param {Number} force * @param {Oid} callback */ -Handle GitRepo::CreateLightweightTag(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String tag_name is required."))); +NAN_METHOD(GitRepo::CreateLightweightTag) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String tag_name is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Object target is required."))); + return NanThrowError(String::New("Object target is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number force is required."))); + return NanThrowError(String::New("Number force is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CreateLightweightTagBaton* baton = new CreateLightweightTagBaton; @@ -1533,26 +1537,26 @@ Handle GitRepo::CreateLightweightTag(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->tag_nameReference = Persistent::New(args[0]); - const char * from_tag_name; - String::Utf8Value tag_name(args[0]->ToString()); - from_tag_name = strdup(*tag_name); - baton->tag_name = from_tag_name; - baton->targetReference = Persistent::New(args[1]); - const git_object * from_target; - from_target = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->target = from_target; - baton->forceReference = Persistent::New(args[2]); - int from_force; - from_force = (int) args[2]->ToInt32()->Value(); - baton->force = from_force; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->tag_nameReference, args[0]); + const char * from_tag_name; + String::Utf8Value tag_name(args[0]->ToString()); + from_tag_name = strdup(*tag_name); + baton->tag_name = from_tag_name; + NanAssignPersistent(Value, baton->targetReference, args[1]); + const git_object * from_target; + from_target = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->target = from_target; + NanAssignPersistent(Value, baton->forceReference, args[2]); + int from_force; + from_force = (int) args[2]->ToInt32()->Value(); + baton->force = from_force; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, CreateLightweightTagWork, (uv_after_work_cb)CreateLightweightTagAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CreateLightweightTagWork(uv_work_t *req) { @@ -1571,7 +1575,7 @@ void GitRepo::CreateLightweightTagWork(uv_work_t *req) { } void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateLightweightTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1584,21 +1588,21 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -1621,31 +1625,31 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Tree} callback */ -Handle GitRepo::GetTree(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); +NAN_METHOD(GitRepo::GetTree) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetTreeBaton* baton = new GetTreeBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetTreeWork, (uv_after_work_cb)GetTreeAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetTreeWork(uv_work_t *req) { @@ -1662,7 +1666,7 @@ void GitRepo::GetTreeWork(uv_work_t *req) { } void GitRepo::GetTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1675,21 +1679,21 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1706,24 +1710,24 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { /** */ -Handle GitRepo::ReloadSubmodules(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::ReloadSubmodules) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ReloadSubmodulesBaton* baton = new ReloadSubmodulesBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReloadSubmodulesWork, (uv_after_work_cb)ReloadSubmodulesAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { @@ -1738,28 +1742,28 @@ void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { } void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReloadSubmodulesBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1776,32 +1780,32 @@ void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { /** * @param {String} tag_name */ -Handle GitRepo::Delete(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String tag_name is required."))); +NAN_METHOD(GitRepo::Delete) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String tag_name is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DeleteBaton* baton = new DeleteBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->tag_nameReference = Persistent::New(args[0]); - const char * from_tag_name; - String::Utf8Value tag_name(args[0]->ToString()); - from_tag_name = strdup(*tag_name); - baton->tag_name = from_tag_name; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->tag_nameReference, args[0]); + const char * from_tag_name; + String::Utf8Value tag_name(args[0]->ToString()); + from_tag_name = strdup(*tag_name); + baton->tag_name = from_tag_name; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, DeleteWork, (uv_after_work_cb)DeleteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::DeleteWork(uv_work_t *req) { @@ -1817,28 +1821,28 @@ void GitRepo::DeleteWork(uv_work_t *req) { } void GitRepo::DeleteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DeleteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1858,11 +1862,11 @@ void GitRepo::DeleteAfterWork(uv_work_t *req) { * @param {Number} list_flags * @param {Array} callback */ -Handle GitRepo::GetReferences(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::GetReferences) { + NanScope(); if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetReferencesBaton* baton = new GetReferencesBaton; @@ -1870,21 +1874,21 @@ Handle GitRepo::GetReferences(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->array = (git_strarray *)malloc(sizeof(git_strarray )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->list_flagsReference = Persistent::New(args[0]); - unsigned int from_list_flags; - if (args[0]->IsUint32()) { - from_list_flags = (unsigned int) args[0]->ToUint32()->Value(); - } else { - from_list_flags = 0; - } - baton->list_flags = from_list_flags; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->list_flagsReference, args[0]); + unsigned int from_list_flags; + if (args[0]->IsUint32()) { + from_list_flags = (unsigned int) args[0]->ToUint32()->Value(); + } else { + from_list_flags = 0; + } + baton->list_flags = from_list_flags; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetReferencesWork, (uv_after_work_cb)GetReferencesAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetReferencesWork(uv_work_t *req) { @@ -1901,7 +1905,7 @@ void GitRepo::GetReferencesWork(uv_work_t *req) { } void GitRepo::GetReferencesAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetReferencesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1915,21 +1919,21 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { to = tmpArray; Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->array); } @@ -1952,17 +1956,17 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { * @param {Number} len * @param {Oid} callback */ -Handle GitRepo::CreateBlobFromBuffer(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Buffer buffer is required."))); +NAN_METHOD(GitRepo::CreateBlobFromBuffer) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Buffer buffer is required.")); } if (args.Length() == 1 || !args[1]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Number len is required."))); + return NanThrowError(String::New("Number len is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CreateBlobFromBufferBaton* baton = new CreateBlobFromBufferBaton; @@ -1970,21 +1974,21 @@ Handle GitRepo::CreateBlobFromBuffer(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->bufferReference = Persistent::New(args[0]); - const void * from_buffer; - from_buffer = Buffer::Data(args[0]->ToObject()); - baton->buffer = from_buffer; - baton->lenReference = Persistent::New(args[1]); - size_t from_len; - from_len = (size_t) args[1]->ToNumber()->Value(); - baton->len = from_len; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->bufferReference, args[0]); + const void * from_buffer; + from_buffer = Buffer::Data(args[0]->ToObject()); + baton->buffer = from_buffer; + NanAssignPersistent(Value, baton->lenReference, args[1]); + size_t from_len; + from_len = (size_t) args[1]->ToNumber()->Value(); + baton->len = from_len; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, CreateBlobFromBufferWork, (uv_after_work_cb)CreateBlobFromBufferAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { @@ -2002,7 +2006,7 @@ void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { } void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateBlobFromBufferBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2015,21 +2019,21 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -2050,14 +2054,14 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { * @param {String} path * @param {Oid} callback */ -Handle GitRepo::CreateBlobFromFile(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); +NAN_METHOD(GitRepo::CreateBlobFromFile) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CreateBlobFromFileBaton* baton = new CreateBlobFromFileBaton; @@ -2065,18 +2069,18 @@ Handle GitRepo::CreateBlobFromFile(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->pathReference = Persistent::New(args[0]); - const char * from_path; - String::Utf8Value path(args[0]->ToString()); - from_path = strdup(*path); - baton->path = from_path; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->pathReference, args[0]); + const char * from_path; + String::Utf8Value path(args[0]->ToString()); + from_path = strdup(*path); + baton->path = from_path; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, CreateBlobFromFileWork, (uv_after_work_cb)CreateBlobFromFileAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { @@ -2093,7 +2097,7 @@ void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { } void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateBlobFromFileBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2106,21 +2110,21 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->id); } @@ -2140,11 +2144,11 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { /** * @param {Array} callback */ -Handle GitRepo::GetRemotes(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRepo::GetRemotes) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetRemotesBaton* baton = new GetRemotesBaton; @@ -2152,13 +2156,13 @@ Handle GitRepo::GetRemotes(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->out = (git_strarray *)malloc(sizeof(git_strarray )); - baton->repoReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, GetRemotesWork, (uv_after_work_cb)GetRemotesAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::GetRemotesWork(uv_work_t *req) { @@ -2174,7 +2178,7 @@ void GitRepo::GetRemotesWork(uv_work_t *req) { } void GitRepo::GetRemotesAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetRemotesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2188,21 +2192,21 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { to = tmpArray; Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -2225,46 +2229,46 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { * @param {CloneOptions} options * @param {Repository} callback */ -Handle GitRepo::Clone(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); +NAN_METHOD(GitRepo::Clone) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String url is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String local_path is required."))); + return NanThrowError(String::New("String local_path is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } CloneBaton* baton = new CloneBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->urlReference = Persistent::New(args[0]); - const char * from_url; - String::Utf8Value url(args[0]->ToString()); - from_url = strdup(*url); - baton->url = from_url; - baton->local_pathReference = Persistent::New(args[1]); - const char * from_local_path; - String::Utf8Value local_path(args[1]->ToString()); - from_local_path = strdup(*local_path); - baton->local_path = from_local_path; - baton->optionsReference = Persistent::New(args[2]); - const git_clone_options * from_options; - if (args[2]->IsObject()) { - from_options = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - } else { - from_options = 0; - } - baton->options = from_options; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->urlReference, args[0]); + const char * from_url; + String::Utf8Value url(args[0]->ToString()); + from_url = strdup(*url); + baton->url = from_url; + NanAssignPersistent(Value, baton->local_pathReference, args[1]); + const char * from_local_path; + String::Utf8Value local_path(args[1]->ToString()); + from_local_path = strdup(*local_path); + baton->local_path = from_local_path; + NanAssignPersistent(Value, baton->optionsReference, args[2]); + const git_clone_options * from_options; + if (args[2]->IsObject()) { + from_options = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_options = 0; + } + baton->options = from_options; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, CloneWork, (uv_after_work_cb)CloneAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRepo::CloneWork(uv_work_t *req) { @@ -2282,7 +2286,7 @@ void GitRepo::CloneWork(uv_work_t *req) { } void GitRepo::CloneAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CloneBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2295,23 +2299,23 @@ void GitRepo::CloneAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -2329,16 +2333,16 @@ void GitRepo::CloneAfterWork(uv_work_t *req) { * @param {String} name * @return {Remote} out */ -Handle GitRepo::GetRemote(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitRepo::GetRemote) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } git_remote * out = 0; const char * from_name; - String::Utf8Value name(args[0]->ToString()); - from_name = strdup(*name); + String::Utf8Value name(args[0]->ToString()); + from_name = strdup(*name); int result = git_remote_load( &out @@ -2348,9 +2352,9 @@ Handle GitRepo::GetRemote(const Arguments& args) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -2360,7 +2364,7 @@ Handle GitRepo::GetRemote(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitRepo::constructor_template; +Persistent GitRepo::constructor_template; diff --git a/src/revwalk.cc b/src/revwalk.cc index bdb4ce47d..63751cf04 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -25,12 +25,12 @@ GitRevWalk::~GitRevWalk() { } void GitRevWalk::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("RevWalk")); + tpl->SetClassName(NanSymbol("RevWalk")); NODE_SET_PROTOTYPE_METHOD(tpl, "reset", Reset); NODE_SET_PROTOTYPE_METHOD(tpl, "push", Push); @@ -45,27 +45,29 @@ void GitRevWalk::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "sorting", Sorting); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("RevWalk"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("RevWalk"), tpl->GetFunction()); } - -Handle GitRevWalk::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_revwalk is required."))); + return NanThrowError(String::New("git_revwalk is required.")); } - GitRevWalk* object = new GitRevWalk((git_revwalk *) External::Unwrap(args[0])); + GitRevWalk* object = new GitRevWalk((git_revwalk *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitRevWalk::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitRevWalk::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_revwalk *GitRevWalk::GetValue() { @@ -75,15 +77,15 @@ git_revwalk *GitRevWalk::GetValue() { /** */ -Handle GitRevWalk::Reset(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::Reset) { + NanScope(); git_revwalk_reset( ObjectWrap::Unwrap(args.This())->GetValue() ); - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -91,31 +93,31 @@ Handle GitRevWalk::Reset(const Arguments& args) { /** * @param {Oid} id */ -Handle GitRevWalk::Push(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::Push) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } PushBaton* baton = new PushBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->idReference = Persistent::New(args[0]); - const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->id = from_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->idReference, args[0]); + const git_oid * from_id; + from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->id = from_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, PushWork, (uv_after_work_cb)PushAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::PushWork(uv_work_t *req) { @@ -131,28 +133,28 @@ void GitRevWalk::PushWork(uv_work_t *req) { } void GitRevWalk::PushAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PushBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -170,32 +172,32 @@ void GitRevWalk::PushAfterWork(uv_work_t *req) { /** * @param {String} glob */ -Handle GitRevWalk::PushGlob(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String glob is required."))); +NAN_METHOD(GitRevWalk::PushGlob) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String glob is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } PushGlobBaton* baton = new PushGlobBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->globReference = Persistent::New(args[0]); - const char * from_glob; - String::Utf8Value glob(args[0]->ToString()); - from_glob = strdup(*glob); - baton->glob = from_glob; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->globReference, args[0]); + const char * from_glob; + String::Utf8Value glob(args[0]->ToString()); + from_glob = strdup(*glob); + baton->glob = from_glob; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, PushGlobWork, (uv_after_work_cb)PushGlobAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::PushGlobWork(uv_work_t *req) { @@ -211,28 +213,28 @@ void GitRevWalk::PushGlobWork(uv_work_t *req) { } void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PushGlobBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -250,24 +252,24 @@ void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { /** */ -Handle GitRevWalk::PushHead(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::PushHead) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } PushHeadBaton* baton = new PushHeadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, PushHeadWork, (uv_after_work_cb)PushHeadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::PushHeadWork(uv_work_t *req) { @@ -282,28 +284,28 @@ void GitRevWalk::PushHeadWork(uv_work_t *req) { } void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PushHeadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -320,31 +322,31 @@ void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { /** * @param {Oid} commit_id */ -Handle GitRevWalk::Hide(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid commit_id is required."))); +NAN_METHOD(GitRevWalk::Hide) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Oid commit_id is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } HideBaton* baton = new HideBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->commit_idReference = Persistent::New(args[0]); - const git_oid * from_commit_id; - from_commit_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->commit_id = from_commit_id; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->commit_idReference, args[0]); + const git_oid * from_commit_id; + from_commit_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->commit_id = from_commit_id; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, HideWork, (uv_after_work_cb)HideAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::HideWork(uv_work_t *req) { @@ -360,28 +362,28 @@ void GitRevWalk::HideWork(uv_work_t *req) { } void GitRevWalk::HideAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); HideBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -399,32 +401,32 @@ void GitRevWalk::HideAfterWork(uv_work_t *req) { /** * @param {String} glob */ -Handle GitRevWalk::HideGlob(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String glob is required."))); +NAN_METHOD(GitRevWalk::HideGlob) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String glob is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } HideGlobBaton* baton = new HideGlobBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->globReference = Persistent::New(args[0]); - const char * from_glob; - String::Utf8Value glob(args[0]->ToString()); - from_glob = strdup(*glob); - baton->glob = from_glob; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->globReference, args[0]); + const char * from_glob; + String::Utf8Value glob(args[0]->ToString()); + from_glob = strdup(*glob); + baton->glob = from_glob; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, HideGlobWork, (uv_after_work_cb)HideGlobAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::HideGlobWork(uv_work_t *req) { @@ -440,28 +442,28 @@ void GitRevWalk::HideGlobWork(uv_work_t *req) { } void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); HideGlobBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -479,24 +481,24 @@ void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { /** */ -Handle GitRevWalk::HideHead(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::HideHead) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } HideHeadBaton* baton = new HideHeadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, HideHeadWork, (uv_after_work_cb)HideHeadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::HideHeadWork(uv_work_t *req) { @@ -511,30 +513,30 @@ void GitRevWalk::HideHeadWork(uv_work_t *req) { } void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); HideHeadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -549,32 +551,32 @@ void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { /** * @param {String} refname */ -Handle GitRevWalk::PushRef(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String refname is required."))); +NAN_METHOD(GitRevWalk::PushRef) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String refname is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } PushRefBaton* baton = new PushRefBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->refnameReference = Persistent::New(args[0]); - const char * from_refname; - String::Utf8Value refname(args[0]->ToString()); - from_refname = strdup(*refname); - baton->refname = from_refname; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->refnameReference, args[0]); + const char * from_refname; + String::Utf8Value refname(args[0]->ToString()); + from_refname = strdup(*refname); + baton->refname = from_refname; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, PushRefWork, (uv_after_work_cb)PushRefAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::PushRefWork(uv_work_t *req) { @@ -590,30 +592,30 @@ void GitRevWalk::PushRefWork(uv_work_t *req) { } void GitRevWalk::PushRefAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PushRefBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -630,32 +632,32 @@ void GitRevWalk::PushRefAfterWork(uv_work_t *req) { /** * @param {String} refname */ -Handle GitRevWalk::HideRef(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String refname is required."))); +NAN_METHOD(GitRevWalk::HideRef) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String refname is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } HideRefBaton* baton = new HideRefBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->refnameReference = Persistent::New(args[0]); - const char * from_refname; - String::Utf8Value refname(args[0]->ToString()); - from_refname = strdup(*refname); - baton->refname = from_refname; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->refnameReference, args[0]); + const char * from_refname; + String::Utf8Value refname(args[0]->ToString()); + from_refname = strdup(*refname); + baton->refname = from_refname; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, HideRefWork, (uv_after_work_cb)HideRefAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::HideRefWork(uv_work_t *req) { @@ -671,30 +673,30 @@ void GitRevWalk::HideRefWork(uv_work_t *req) { } void GitRevWalk::HideRefAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); HideRefBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -711,11 +713,11 @@ void GitRevWalk::HideRefAfterWork(uv_work_t *req) { /** * @param {Oid} callback */ -Handle GitRevWalk::Next(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitRevWalk::Next) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } NextBaton* baton = new NextBaton; @@ -723,13 +725,13 @@ Handle GitRevWalk::Next(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - baton->walkReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->walkReference, args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, NextWork, (uv_after_work_cb)NextAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitRevWalk::NextWork(uv_work_t *req) { @@ -745,7 +747,7 @@ void GitRevWalk::NextWork(uv_work_t *req) { } void GitRevWalk::NextAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); NextBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -758,21 +760,21 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -788,10 +790,10 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { /** * @param {Number} sort_mode */ -Handle GitRevWalk::Sorting(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number sort_mode is required."))); +NAN_METHOD(GitRevWalk::Sorting) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsUint32()) { + return NanThrowError(String::New("Number sort_mode is required.")); } unsigned int from_sort_mode; @@ -802,7 +804,7 @@ Handle GitRevWalk::Sorting(const Arguments& args) { , from_sort_mode ); - return Undefined(); + NanReturnUndefined(); } -Persistent GitRevWalk::constructor_template; +Persistent GitRevWalk::constructor_template; diff --git a/src/signature.cc b/src/signature.cc index 03ee935e5..aec9b1f3a 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -24,12 +24,12 @@ GitSignature::~GitSignature() { } void GitSignature::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Signature")); + tpl->SetClassName(NanSymbol("Signature")); NODE_SET_METHOD(tpl, "create", Create); NODE_SET_METHOD(tpl, "now", Now); @@ -38,27 +38,30 @@ void GitSignature::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "email", Email); NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Signature"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Signature"), tpl->GetFunction()); } -Handle GitSignature::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSignature::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_signature is required."))); + return NanThrowError(String::New("git_signature is required.")); } - GitSignature* object = new GitSignature((git_signature *) External::Unwrap(args[0])); + GitSignature* object = new GitSignature((git_signature *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitSignature::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitSignature::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_signature *GitSignature::GetValue() { @@ -73,19 +76,19 @@ git_signature *GitSignature::GetValue() { * @param {Number} offset * @return {Signature} out */ -Handle GitSignature::Create(const Arguments& args) { - HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); +NAN_METHOD(GitSignature::Create) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String email is required."))); + return NanThrowError(String::New("String email is required.")); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number time is required."))); + return NanThrowError(String::New("Number time is required.")); } if (args.Length() == 3 || !args[3]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number offset is required."))); + return NanThrowError(String::New("Number offset is required.")); } git_signature * out = 0; @@ -111,9 +114,9 @@ Handle GitSignature::Create(const Arguments& args) { free((void *)from_email); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -123,7 +126,7 @@ Handle GitSignature::Create(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -131,13 +134,13 @@ Handle GitSignature::Create(const Arguments& args) { * @param {String} email * @return {Signature} out */ -Handle GitSignature::Now(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSignature::Now) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String name is required."))); + return NanThrowError(String::New("String name is required.")); } if (args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("String email is required."))); + return NanThrowError(String::New("String email is required.")); } git_signature * out = 0; @@ -157,9 +160,9 @@ Handle GitSignature::Now(const Arguments& args) { free((void *)from_email); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -169,33 +172,32 @@ Handle GitSignature::Now(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } - -Handle GitSignature::Name(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSignature::Name) { + NanScope(); Handle to; const char * name = ObjectWrap::Unwrap(args.This())->GetValue()->name; to = String::New(name); - return scope.Close(to); + NanReturnValue(to); } -Handle GitSignature::Email(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSignature::Email) { + NanScope(); Handle to; const char * email = ObjectWrap::Unwrap(args.This())->GetValue()->email; to = String::New(email); - return scope.Close(to); + NanReturnValue(to); } -Handle GitSignature::Time(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSignature::Time) { + NanScope(); Handle to; git_time *when = @@ -209,7 +211,7 @@ Handle GitSignature::Time(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitSignature::constructor_template; +Persistent GitSignature::constructor_template; diff --git a/src/submodule.cc b/src/submodule.cc index 8cddceb3e..367426317 100644 --- a/src/submodule.cc +++ b/src/submodule.cc @@ -25,12 +25,12 @@ GitSubmodule::~GitSubmodule() { } void GitSubmodule::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Submodule")); + tpl->SetClassName(NanSymbol("Submodule")); NODE_SET_PROTOTYPE_METHOD(tpl, "addFinalize", AddFinalize); NODE_SET_PROTOTYPE_METHOD(tpl, "addToIndex", AddToIndex); @@ -48,27 +48,30 @@ void GitSubmodule::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "status", Status); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Submodule"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Submodule"), tpl->GetFunction()); } -Handle GitSubmodule::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_submodule is required."))); + return NanThrowError(String::New("git_submodule is required.")); } - GitSubmodule* object = new GitSubmodule((git_submodule *) External::Unwrap(args[0])); + GitSubmodule* object = new GitSubmodule((git_submodule *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitSubmodule::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitSubmodule::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_submodule *GitSubmodule::GetValue() { @@ -80,24 +83,24 @@ git_submodule *GitSubmodule::GetValue() { /** */ -Handle GitSubmodule::AddFinalize(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::AddFinalize) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } AddFinalizeBaton* baton = new AddFinalizeBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, AddFinalizeWork, (uv_after_work_cb)AddFinalizeAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::AddFinalizeWork(uv_work_t *req) { @@ -112,28 +115,28 @@ void GitSubmodule::AddFinalizeWork(uv_work_t *req) { } void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); AddFinalizeBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -150,31 +153,31 @@ void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { /** * @param {Number} write_index */ -Handle GitSubmodule::AddToIndex(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::AddToIndex) { + NanScope(); if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number write_index is required."))); + return NanThrowError(String::New("Number write_index is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } AddToIndexBaton* baton = new AddToIndexBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->write_indexReference = Persistent::New(args[0]); - int from_write_index; - from_write_index = (int) args[0]->ToInt32()->Value(); - baton->write_index = from_write_index; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->write_indexReference, args[0]); + int from_write_index; + from_write_index = (int) args[0]->ToInt32()->Value(); + baton->write_index = from_write_index; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, AddToIndexWork, (uv_after_work_cb)AddToIndexAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::AddToIndexWork(uv_work_t *req) { @@ -190,28 +193,28 @@ void GitSubmodule::AddToIndexWork(uv_work_t *req) { } void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); AddToIndexBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -228,24 +231,24 @@ void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { /** */ -Handle GitSubmodule::Save(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Save) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } SaveBaton* baton = new SaveBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, SaveWork, (uv_after_work_cb)SaveAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::SaveWork(uv_work_t *req) { @@ -260,28 +263,28 @@ void GitSubmodule::SaveWork(uv_work_t *req) { } void GitSubmodule::SaveAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); SaveBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -296,8 +299,8 @@ void GitSubmodule::SaveAfterWork(uv_work_t *req) { /** * @return {String} result */ -Handle GitSubmodule::Name(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Name) { + NanScope(); const char * result = git_submodule_name( @@ -306,14 +309,14 @@ Handle GitSubmodule::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitSubmodule::Path(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Path) { + NanScope(); const char * result = git_submodule_path( @@ -322,14 +325,14 @@ Handle GitSubmodule::Path(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitSubmodule::Url(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Url) { + NanScope(); const char * result = git_submodule_url( @@ -338,16 +341,16 @@ Handle GitSubmodule::Url(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} url */ -Handle GitSubmodule::SetUrl(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::SetUrl) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String url is required."))); + return NanThrowError(String::New("String url is required.")); } const char * from_url; @@ -361,20 +364,20 @@ Handle GitSubmodule::SetUrl(const Arguments& args) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** * @return {Oid} result */ -Handle GitSubmodule::IndexId(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::IndexId) { + NanScope(); const git_oid * result = git_submodule_index_id( @@ -390,14 +393,14 @@ Handle GitSubmodule::IndexId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Oid} result */ -Handle GitSubmodule::HeadId(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::HeadId) { + NanScope(); const git_oid * result = git_submodule_head_id( @@ -413,7 +416,7 @@ Handle GitSubmodule::HeadId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -421,31 +424,31 @@ Handle GitSubmodule::HeadId(const Arguments& args) { /** * @param {Number} overwrite */ -Handle GitSubmodule::Init(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Init) { + NanScope(); if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number overwrite is required."))); + return NanThrowError(String::New("Number overwrite is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } InitBaton* baton = new InitBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->overwriteReference = Persistent::New(args[0]); - int from_overwrite; - from_overwrite = (int) args[0]->ToInt32()->Value(); - baton->overwrite = from_overwrite; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->overwriteReference, args[0]); + int from_overwrite; + from_overwrite = (int) args[0]->ToInt32()->Value(); + baton->overwrite = from_overwrite; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, InitWork, (uv_after_work_cb)InitAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::InitWork(uv_work_t *req) { @@ -461,28 +464,28 @@ void GitSubmodule::InitWork(uv_work_t *req) { } void GitSubmodule::InitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); InitBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -499,24 +502,24 @@ void GitSubmodule::InitAfterWork(uv_work_t *req) { /** */ -Handle GitSubmodule::Sync(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Sync) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } SyncBaton* baton = new SyncBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, SyncWork, (uv_after_work_cb)SyncAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::SyncWork(uv_work_t *req) { @@ -531,28 +534,28 @@ void GitSubmodule::SyncWork(uv_work_t *req) { } void GitSubmodule::SyncAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); SyncBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -569,24 +572,24 @@ void GitSubmodule::SyncAfterWork(uv_work_t *req) { /** * @param {Repository} callback */ -Handle GitSubmodule::Open(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Open) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } OpenBaton* baton = new OpenBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::OpenWork(uv_work_t *req) { @@ -602,7 +605,7 @@ void GitSubmodule::OpenWork(uv_work_t *req) { } void GitSubmodule::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -615,21 +618,21 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -645,24 +648,24 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { /** */ -Handle GitSubmodule::Reload(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Reload) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } ReloadBaton* baton = new ReloadBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReloadWork, (uv_after_work_cb)ReloadAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::ReloadWork(uv_work_t *req) { @@ -677,28 +680,28 @@ void GitSubmodule::ReloadWork(uv_work_t *req) { } void GitSubmodule::ReloadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReloadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -715,31 +718,31 @@ void GitSubmodule::ReloadAfterWork(uv_work_t *req) { /** * @param {Number} status */ -Handle GitSubmodule::Status(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitSubmodule::Status) { + NanScope(); if (args.Length() == 0 || !args[0]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number status is required."))); + return NanThrowError(String::New("Number status is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } StatusBaton* baton = new StatusBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->statusReference = Persistent::New(args[0]); - unsigned int * from_status; - from_status = (unsigned int *) args[0]->ToInt32()->Value(); - baton->status = from_status; - baton->submoduleReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->statusReference, args[0]); + unsigned int * from_status; + from_status = (unsigned int *) args[0]->ToInt32()->Value(); + baton->status = from_status; + NanAssignPersistent(Value, baton->submoduleReference, args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, StatusWork, (uv_after_work_cb)StatusAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitSubmodule::StatusWork(uv_work_t *req) { @@ -755,28 +758,28 @@ void GitSubmodule::StatusWork(uv_work_t *req) { } void GitSubmodule::StatusAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); StatusBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = Local::New(Undefined()); + Handle result = NanNewLocal(Undefined()); Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -789,4 +792,4 @@ void GitSubmodule::StatusAfterWork(uv_work_t *req) { delete baton; } -Persistent GitSubmodule::constructor_template; +Persistent GitSubmodule::constructor_template; diff --git a/src/tag.cc b/src/tag.cc index 08b099d41..4423559e6 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -27,12 +27,12 @@ GitTag::~GitTag() { } void GitTag::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Tag")); + tpl->SetClassName(NanSymbol("Tag")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "getTarget", GetTarget); @@ -44,27 +44,30 @@ void GitTag::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Tag"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Tag"), tpl->GetFunction()); } -Handle GitTag::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_tag is required."))); + return NanThrowError(String::New("git_tag is required.")); } - GitTag* object = new GitTag((git_tag *) External::Unwrap(args[0])); + GitTag* object = new GitTag((git_tag *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitTag::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitTag::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_tag *GitTag::GetValue() { @@ -75,8 +78,8 @@ git_tag *GitTag::GetValue() { /** * @return {Oid} result */ -Handle GitTag::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::Oid) { + NanScope(); const git_oid * result = git_tag_id( @@ -92,7 +95,7 @@ Handle GitTag::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -100,24 +103,24 @@ Handle GitTag::Oid(const Arguments& args) { /** * @param {Object} callback */ -Handle GitTag::GetTarget(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::GetTarget) { + NanScope(); if (args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetTargetBaton* baton = new GetTargetBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->tagReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->tagReference, args.This()); baton->tag = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[0])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, GetTargetWork, (uv_after_work_cb)GetTargetAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTag::GetTargetWork(uv_work_t *req) { @@ -133,7 +136,7 @@ void GitTag::GetTargetWork(uv_work_t *req) { } void GitTag::GetTargetAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTargetBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -146,21 +149,21 @@ void GitTag::GetTargetAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -175,9 +178,8 @@ void GitTag::GetTargetAfterWork(uv_work_t *req) { /** * @return {Oid} result */ -Handle GitTag::TargetId(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitTag::TargetId) { + NanScope(); const git_oid * result = git_tag_target_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -192,14 +194,14 @@ Handle GitTag::TargetId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitTag::TargetType(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::TargetType) { + NanScope(); git_otype result = git_tag_target_type( @@ -208,14 +210,14 @@ Handle GitTag::TargetType(const Arguments& args) { Handle to; to = Int32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitTag::Name(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::Name) { + NanScope(); const char * result = git_tag_name( @@ -224,14 +226,14 @@ Handle GitTag::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Signature} result */ -Handle GitTag::Tagger(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::Tagger) { + NanScope(); const git_signature * result = git_tag_tagger( @@ -247,14 +249,14 @@ Handle GitTag::Tagger(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {String} result */ -Handle GitTag::Message(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::Message) { + NanScope(); const char * result = git_tag_message( @@ -263,17 +265,17 @@ Handle GitTag::Message(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {Tag} tag * @return {Object} tag_target_out */ -Handle GitTag::Peel(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTag::Peel) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Tag tag is required."))); + return NanThrowError(String::New("Tag tag is required.")); } git_object * tag_target_out = 0; @@ -286,9 +288,9 @@ Handle GitTag::Peel(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -298,7 +300,7 @@ Handle GitTag::Peel(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } -Persistent GitTag::constructor_template; +Persistent GitTag::constructor_template; diff --git a/src/threads.cc b/src/threads.cc index 020600206..3aa2edaff 100755 --- a/src/threads.cc +++ b/src/threads.cc @@ -15,45 +15,47 @@ using namespace v8; using namespace node; void GitThreads::Initialize(Handle target) { - HandleScope scope; + NanScope(); - Persistent object = Persistent::New(Object::New()); + Persistent object; - object->Set(String::NewSymbol("init"), FunctionTemplate::New(Init)->GetFunction()); - object->Set(String::NewSymbol("shutdown"), FunctionTemplate::New(Shutdown)->GetFunction()); + NanAssignPersistent(Object, object, Object::New()); - target->Set(String::NewSymbol("Threads"), object); + NanPersistentToLocal(object)->Set(String::NewSymbol("init"), FunctionTemplate::New(Init)->GetFunction()); + NanPersistentToLocal(object)->Set(String::NewSymbol("shutdown"), FunctionTemplate::New(Shutdown)->GetFunction()); + + target->Set(String::NewSymbol("Threads"), NanPersistentToLocal(object)); } /** */ -Handle GitThreads::Init(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitThreads::Init) { + NanScope(); int result = git_threads_init( ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } /** */ -Handle GitThreads::Shutdown(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitThreads::Shutdown) { + NanScope(); git_threads_shutdown( ); - return Undefined(); + NanReturnUndefined(); } diff --git a/src/time.cc b/src/time.cc index b03a49c84..4196ec83e 100644 --- a/src/time.cc +++ b/src/time.cc @@ -23,65 +23,66 @@ GitTime::~GitTime() { } void GitTime::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Time")); - - + tpl->SetClassName(NanSymbol("Time")); + NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); NODE_SET_PROTOTYPE_METHOD(tpl, "offset", Offset); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Time"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Time"), tpl->GetFunction()); } -Handle GitTime::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTime::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_time is required."))); + return NanThrowError(String::New("git_time is required.")); } - GitTime* object = new GitTime((git_time *) External::Unwrap(args[0])); + GitTime* object = new GitTime((git_time *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitTime::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitTime::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_time *GitTime::GetValue() { return this->raw; } - -Handle GitTime::Time(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTime::Time) { + NanScope(); Handle to; git_time_t time = ObjectWrap::Unwrap(args.This())->GetValue()->time; to = Integer::New(time); - return scope.Close(to); + NanReturnValue(to); } -Handle GitTime::Offset(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTime::Offset) { + NanScope(); Handle to; int offset = ObjectWrap::Unwrap(args.This())->GetValue()->offset; to = Int32::New(offset); - return scope.Close(to); + NanReturnValue(to); } -Persistent GitTime::constructor_template; +Persistent GitTime::constructor_template; diff --git a/src/tree.cc b/src/tree.cc index 3808df4a3..6798183ae 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -30,13 +30,13 @@ GitTree::~GitTree() { } void GitTree::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Tree")); - + tpl->SetClassName(NanSymbol("Tree")); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); NODE_SET_PROTOTYPE_METHOD(tpl, "entryByName", EntryByName); @@ -48,28 +48,30 @@ void GitTree::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "diffIndex", DiffIndex); NODE_SET_PROTOTYPE_METHOD(tpl, "diffWorkDir", DiffWorkDir); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Tree"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Tree"), tpl->GetFunction()); } -Handle GitTree::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_tree is required."))); + return NanThrowError(String::New("git_tree is required.")); } - GitTree* object = new GitTree((git_tree *) External::Unwrap(args[0])); + GitTree* object = new GitTree((git_tree *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitTree::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitTree::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_tree *GitTree::GetValue() { @@ -80,9 +82,9 @@ git_tree *GitTree::GetValue() { /** * @return {Oid} result */ -Handle GitTree::Oid(const Arguments& args) { - HandleScope scope; - +NAN_METHOD(GitTree::Oid) { + NanScope(); + const git_oid * result = git_tree_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -97,14 +99,14 @@ Handle GitTree::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitTree::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::Size) { + NanScope(); size_t result = git_tree_entrycount( @@ -113,17 +115,17 @@ Handle GitTree::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} filename * @return {TreeEntry} result */ -Handle GitTree::EntryByName(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::EntryByName) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String filename is required."))); + return NanThrowError(String::New("String filename is required.")); } const char * from_filename; @@ -145,17 +147,17 @@ Handle GitTree::EntryByName(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {Number} idx * @return {TreeEntry} result */ -Handle GitTree::EntryByIndex(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::EntryByIndex) { + NanScope(); if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number idx is required."))); + return NanThrowError(String::New("Number idx is required.")); } size_t from_idx; @@ -175,17 +177,17 @@ Handle GitTree::EntryByIndex(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {Oid} oid * @return {TreeEntry} result */ -Handle GitTree::EntryByOid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::EntryByOid) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid oid is required."))); + return NanThrowError(String::New("Oid oid is required.")); } const git_oid * from_oid; @@ -205,7 +207,7 @@ Handle GitTree::EntryByOid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -214,32 +216,32 @@ Handle GitTree::EntryByOid(const Arguments& args) { * @param {String} path * @param {TreeEntry} callback */ -Handle GitTree::GetEntry(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::GetEntry) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String path is required."))); + return NanThrowError(String::New("String path is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetEntryBaton* baton = new GetEntryBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->rootReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->rootReference, args.This()); baton->root = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->pathReference = Persistent::New(args[0]); - const char * from_path; - String::Utf8Value path(args[0]->ToString()); - from_path = strdup(*path); - baton->path = from_path; - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Value, baton->pathReference, args[0]); + const char * from_path; + String::Utf8Value path(args[0]->ToString()); + from_path = strdup(*path); + baton->path = from_path; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetEntryWork, (uv_after_work_cb)GetEntryAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTree::GetEntryWork(uv_work_t *req) { @@ -256,7 +258,7 @@ void GitTree::GetEntryWork(uv_work_t *req) { } void GitTree::GetEntryAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetEntryBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -269,21 +271,21 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -300,8 +302,8 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { /** * @return {TreeBuilder} out */ -Handle GitTree::Builder(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::Builder) { + NanScope(); git_treebuilder * out = 0; @@ -311,9 +313,9 @@ Handle GitTree::Builder(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -323,7 +325,7 @@ Handle GitTree::Builder(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -334,46 +336,46 @@ Handle GitTree::Builder(const Arguments& args) { * @param {DiffOptions} opts * @param {DiffList} callback */ -Handle GitTree::DiffTree(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::DiffTree) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Tree new_tree is required."))); + return NanThrowError(String::New("Tree new_tree is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DiffTreeBaton* baton = new DiffTreeBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->old_treeReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->old_treeReference, args.This()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->new_treeReference = Persistent::New(args[1]); - git_tree * from_new_tree; - from_new_tree = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->new_tree = from_new_tree; - baton->optsReference = Persistent::New(args[2]); - const git_diff_options * from_opts; - if (args[2]->IsObject()) { - from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - } else { - from_opts = 0; - } - baton->opts = from_opts; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->new_treeReference, args[1]); + git_tree * from_new_tree; + from_new_tree = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->new_tree = from_new_tree; + NanAssignPersistent(Value, baton->optsReference, args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, DiffTreeWork, (uv_after_work_cb)DiffTreeAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTree::DiffTreeWork(uv_work_t *req) { @@ -392,7 +394,7 @@ void GitTree::DiffTreeWork(uv_work_t *req) { } void GitTree::DiffTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -405,21 +407,21 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -442,47 +444,47 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { * @param {DiffOptions} opts * @param {DiffList} callback */ -Handle GitTree::DiffIndex(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::DiffIndex) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DiffIndexBaton* baton = new DiffIndexBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->old_treeReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->old_treeReference, args.This()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->indexReference = Persistent::New(args[1]); - git_index * from_index; - if (args[1]->IsObject()) { - from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - } else { - from_index = 0; - } - baton->index = from_index; - baton->optsReference = Persistent::New(args[2]); - const git_diff_options * from_opts; - if (args[2]->IsObject()) { - from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - } else { - from_opts = 0; - } - baton->opts = from_opts; - baton->callback = Persistent::New(Local::Cast(args[3])); + NanAssignPersistent(Value, baton->indexReference, args[1]); + git_index * from_index; + if (args[1]->IsObject()) { + from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_index = 0; + } + baton->index = from_index; + NanAssignPersistent(Value, baton->optsReference, args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, DiffIndexWork, (uv_after_work_cb)DiffIndexAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTree::DiffIndexWork(uv_work_t *req) { @@ -501,7 +503,7 @@ void GitTree::DiffIndexWork(uv_work_t *req) { } void GitTree::DiffIndexAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -514,21 +516,21 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -550,39 +552,39 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { * @param {DiffOptions} opts * @param {DiffList} callback */ -Handle GitTree::DiffWorkDir(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTree::DiffWorkDir) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } DiffWorkDirBaton* baton = new DiffWorkDirBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->old_treeReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->old_treeReference, args.This()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->optsReference = Persistent::New(args[1]); - const git_diff_options * from_opts; - if (args[1]->IsObject()) { - from_opts = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - } else { - from_opts = 0; - } - baton->opts = from_opts; - baton->callback = Persistent::New(Local::Cast(args[2])); + NanAssignPersistent(Value, baton->optsReference, args[1]); + const git_diff_options * from_opts; + if (args[1]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + NanAssignPersistent(Function, baton->callback, Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, DiffWorkDirWork, (uv_after_work_cb)DiffWorkDirAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTree::DiffWorkDirWork(uv_work_t *req) { @@ -600,7 +602,7 @@ void GitTree::DiffWorkDirWork(uv_work_t *req) { } void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffWorkDirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -613,21 +615,21 @@ void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -641,4 +643,4 @@ void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { delete baton; } -Persistent GitTree::constructor_template; +Persistent GitTree::constructor_template; diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 294831776..59ccd63ba 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -30,13 +30,13 @@ GitTreeBuilder::~GitTreeBuilder() { } void GitTreeBuilder::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("TreeBuilder")); - + tpl->SetClassName(NanSymbol("TreeBuilder")); + NODE_SET_METHOD(tpl, "create", Create); NODE_SET_PROTOTYPE_METHOD(tpl, "clear", Clear); NODE_SET_METHOD(tpl, "size", Size); @@ -45,28 +45,30 @@ void GitTreeBuilder::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "gitTreebuilderRemove", GitTreebuilderRemove); NODE_SET_PROTOTYPE_METHOD(tpl, "write", Write); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("TreeBuilder"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("TreeBuilder"), tpl->GetFunction()); } -Handle GitTreeBuilder::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_treebuilder is required."))); + return NanThrowError(String::New("git_treebuilder is required.")); } - GitTreeBuilder* object = new GitTreeBuilder((git_treebuilder *) External::Unwrap(args[0])); + GitTreeBuilder* object = new GitTreeBuilder((git_treebuilder *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitTreeBuilder::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitTreeBuilder::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_treebuilder *GitTreeBuilder::GetValue() { @@ -78,8 +80,8 @@ git_treebuilder *GitTreeBuilder::GetValue() { * @param {Tree} source * @return {TreeBuilder} out */ -Handle GitTreeBuilder::Create(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Create) { + NanScope(); git_treebuilder * out = 0; const git_tree * from_source; @@ -95,9 +97,9 @@ Handle GitTreeBuilder::Create(const Arguments& args) { ); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -107,16 +109,16 @@ Handle GitTreeBuilder::Create(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {TreeBuilder} bld */ -Handle GitTreeBuilder::Clear(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Clear) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("TreeBuilder bld is required."))); + return NanThrowError(String::New("TreeBuilder bld is required.")); } git_treebuilder * from_bld; @@ -126,14 +128,14 @@ Handle GitTreeBuilder::Clear(const Arguments& args) { from_bld ); - return Undefined(); + NanReturnUndefined(); } /** * @return {Number} result */ -Handle GitTreeBuilder::Size(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Size) { + NanScope(); unsigned int result = git_treebuilder_entrycount( @@ -142,17 +144,17 @@ Handle GitTreeBuilder::Size(const Arguments& args) { Handle to; to = Uint32::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} filename * @return {TreeEntry} result */ -Handle GitTreeBuilder::Get(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Get) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String filename is required."))); + return NanThrowError(String::New("String filename is required.")); } const char * from_filename; @@ -174,7 +176,7 @@ Handle GitTreeBuilder::Get(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -183,16 +185,16 @@ Handle GitTreeBuilder::Get(const Arguments& args) { * @param {Number} filemode * @return {TreeEntry} out */ -Handle GitTreeBuilder::Insert(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Insert) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String filename is required."))); + return NanThrowError(String::New("String filename is required.")); } if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + return NanThrowError(String::New("Oid id is required.")); } if (args.Length() == 2 || !args[2]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Number filemode is required."))); + return NanThrowError(String::New("Number filemode is required.")); } const git_tree_entry * out = 0; @@ -214,9 +216,9 @@ Handle GitTreeBuilder::Insert(const Arguments& args) { free((void *)from_filename); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } @@ -229,16 +231,16 @@ Handle GitTreeBuilder::Insert(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @param {String} filename */ -Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::GitTreebuilderRemove) { + NanScope(); if (args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("String filename is required."))); + return NanThrowError(String::New("String filename is required.")); } const char * from_filename; @@ -252,13 +254,13 @@ Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) { free((void *)from_filename); if (result != GIT_OK) { if (giterr_last()) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); + return NanThrowError(String::New(giterr_last()->message)); } else { - return ThrowException(Exception::Error(String::New("Unkown Error"))); + return NanThrowError(String::New("Unkown Error")); } } - return Undefined(); + NanReturnUndefined(); } #include "../include/functions/copy.h" @@ -267,14 +269,14 @@ Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) { * @param {Repository} repo * @param {Oid} callback */ -Handle GitTreeBuilder::Write(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeBuilder::Write) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } WriteBaton* baton = new WriteBaton; @@ -282,17 +284,17 @@ Handle GitTreeBuilder::Write(const Arguments& args) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->bldReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->bldReference, args.This()); baton->bld = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTreeBuilder::WriteWork(uv_work_t *req) { @@ -309,7 +311,7 @@ void GitTreeBuilder::WriteWork(uv_work_t *req) { } void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -322,21 +324,21 @@ void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->id); } @@ -350,4 +352,4 @@ void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { delete baton; } -Persistent GitTreeBuilder::constructor_template; +Persistent GitTreeBuilder::constructor_template; diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 2d761e611..baa5a1966 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -26,41 +26,43 @@ GitTreeEntry::~GitTreeEntry() { } void GitTreeEntry::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("TreeEntry")); - + tpl->SetClassName(NanSymbol("TreeEntry")); + NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); NODE_SET_PROTOTYPE_METHOD(tpl, "filemode", filemode); NODE_SET_PROTOTYPE_METHOD(tpl, "getObject", GetObject); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("TreeEntry"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("TreeEntry"), tpl->GetFunction()); } -Handle GitTreeEntry::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("git_tree_entry is required."))); + return NanThrowError(String::New("git_tree_entry is required.")); } - GitTreeEntry* object = new GitTreeEntry((git_tree_entry *) External::Unwrap(args[0])); + GitTreeEntry* object = new GitTreeEntry((git_tree_entry *) External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle GitTreeEntry::New(void *raw) { - HandleScope scope; + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(GitTreeEntry::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } git_tree_entry *GitTreeEntry::GetValue() { @@ -71,8 +73,8 @@ git_tree_entry *GitTreeEntry::GetValue() { /** * @return {String} result */ -Handle GitTreeEntry::Name(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::Name) { + NanScope(); const char * result = git_tree_entry_name( @@ -81,14 +83,14 @@ Handle GitTreeEntry::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Oid} result */ -Handle GitTreeEntry::Oid(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::Oid) { + NanScope(); const git_oid * result = git_tree_entry_id( @@ -104,14 +106,14 @@ Handle GitTreeEntry::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitTreeEntry::Type(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::Type) { + NanScope(); git_otype result = git_tree_entry_type( @@ -120,14 +122,14 @@ Handle GitTreeEntry::Type(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } /** * @return {Number} result */ -Handle GitTreeEntry::filemode(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::filemode) { + NanScope(); git_filemode_t result = git_tree_entry_filemode( @@ -136,7 +138,7 @@ Handle GitTreeEntry::filemode(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } #include "../include/functions/copy.h" @@ -145,31 +147,31 @@ Handle GitTreeEntry::filemode(const Arguments& args) { * @param {Repository} repo * @param {Object} callback */ -Handle GitTreeEntry::GetObject(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitTreeEntry::GetObject) { + NanScope(); if (args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repository repo is required."))); + return NanThrowError(String::New("Repository repo is required.")); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + return NanThrowError(String::New("Callback is required and must be a Function.")); } GetObjectBaton* baton = new GetObjectBaton; baton->error_code = GIT_OK; baton->error = NULL; baton->request.data = baton; - baton->repoReference = Persistent::New(args[0]); - git_repository * from_repo; - from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); - baton->repo = from_repo; - baton->entryReference = Persistent::New(args.This()); + NanAssignPersistent(Value, baton->repoReference, args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + NanAssignPersistent(Value, baton->entryReference, args.This()); baton->entry = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->callback = Persistent::New(Local::Cast(args[1])); + NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetObjectWork, (uv_after_work_cb)GetObjectAfterWork); - return Undefined(); + NanReturnUndefined(); } void GitTreeEntry::GetObjectWork(uv_work_t *req) { @@ -186,7 +188,7 @@ void GitTreeEntry::GetObjectWork(uv_work_t *req) { } void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -199,21 +201,21 @@ void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - Local::New(Null()), + NanNewLocal(Null()), result }; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); + NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -226,4 +228,4 @@ void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { delete baton; } -Persistent GitTreeEntry::constructor_template; +Persistent GitTreeEntry::constructor_template; diff --git a/src/wrapper.cc b/src/wrapper.cc index 3849c37e1..f2d2463be 100644 --- a/src/wrapper.cc +++ b/src/wrapper.cc @@ -17,48 +17,50 @@ Wrapper::Wrapper(void *raw) { } void Wrapper::Initialize(Handle target) { - HandleScope scope; + NanScope(); Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Wrapper")); - + tpl->SetClassName(NanSymbol("Wrapper")); + NODE_SET_PROTOTYPE_METHOD(tpl, "toBuffer", ToBuffer); - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Wrapper"), constructor_template); + NanAssignPersistent(FunctionTemplate, constructor_template, tpl); + target->Set(String::NewSymbol("Wrapper"), tpl->GetFunction()); } -Handle Wrapper::New(const Arguments& args) { - HandleScope scope; +NAN_METHOD(Wrapper::New) { + NanScope(); if (args.Length() == 0 || !args[0]->IsExternal()) { - return ThrowException(Exception::Error(String::New("void * is required."))); + return NanThrowError(String::New("void * is required.")); } - Wrapper* object = new Wrapper(External::Unwrap(args[0])); + Wrapper* object = new Wrapper(External::Cast(*args[0])->Value()); object->Wrap(args.This()); - return scope.Close(args.This()); + NanReturnValue(args.This()); } Handle Wrapper::New(void *raw) { - HandleScope scope; - + NanScope(); Handle argv[1] = { External::New((void *)raw) }; - return scope.Close(Wrapper::constructor_template->NewInstance(1, argv)); + Local instance; + Local constructorHandle = NanPersistentToLocal(constructor_template); + instance = constructorHandle->GetFunction()->NewInstance(1, argv); + return scope.Close(instance); } void *Wrapper::GetValue() { return this->raw; } -Handle Wrapper::ToBuffer(const Arguments& args) { - HandleScope scope; +NAN_METHOD(Wrapper::ToBuffer) { + NanScope(); if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Number is required."))); + return NanThrowError(String::New("Number is required.")); } int len = args[0]->ToNumber()->Value(); @@ -71,8 +73,8 @@ Handle Wrapper::ToBuffer(const Arguments& args) { std::memcpy(node::Buffer::Data(nodeBuffer), ObjectWrap::Unwrap(args.This())->GetValue(), len); - return scope.Close(nodeBuffer); + NanReturnValue(nodeBuffer); } -Persistent Wrapper::constructor_template; +Persistent Wrapper::constructor_template; From 197c71b450a6adc2cef23f75579286e673b4b5b8 Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Sat, 1 Mar 2014 19:40:25 +0100 Subject: [PATCH 24/31] make travis test for node 0.10 & 0.11 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f6e2ee0ec..72727c9bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: node_js node_js: - 0.8 + - 0.10 + - 0.11.10 git: depth: 1000 From b33ad8c1dc6cb1313ae6dffb97bea96bd4c0655a Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Sat, 1 Mar 2014 19:53:35 +0100 Subject: [PATCH 25/31] add nan in include dirs --- binding.gyp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index bbc232773..17d1dc5f3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -41,7 +41,8 @@ 'include_dirs': [ 'vendor/libv8-convert', - 'vendor/libgit2/include' + 'vendor/libgit2/include', + " Date: Sat, 22 Mar 2014 20:19:38 -0400 Subject: [PATCH 26/31] Fixes error message. --- test/repo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/repo.js b/test/repo.js index 4608d0d38..70f3128dd 100644 --- a/test/repo.js +++ b/test/repo.js @@ -12,7 +12,7 @@ exports.openInvalidRepo = function(test){ // Test invalid repository git.Repo.open('repos/nonrepo', function(error, repository) { - test.equals(error.message, "Could not find repository from 'repos/nonrepo'"); + test.ok(error instanceof Error); test.done(); }); }; From 2a7afb19de6a572c5ed5b11d81a8141c10bff0c6 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sat, 22 Mar 2014 20:20:39 -0400 Subject: [PATCH 27/31] Be proactive about Node unstable, but do not fail. At the moment we fail the build if it does not pass in the latest Node unstable. This is undesirable since we only officially support stable versions. However it's nice to be proactive about this version: http://weblog.bocoup.com/proactive-nodejs-development/ --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 72727c9bc..abb240fe8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: node_js node_js: - 0.8 - 0.10 - - 0.11.10 git: - depth: 1000 + depth: 1 +matrix: + fast_finish: true + allow_failures: + - node_js: 0.11 From a97f3276d538dd1677294256e8ef84c4b1b217fb Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sat, 22 Mar 2014 20:22:10 -0400 Subject: [PATCH 28/31] Updated README to show the correct Travis-CI badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1c46e1c6..e7ce4aa29 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ nodegit > Node.js libgit2 bindings **v0.1.0** [![Build -Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/tbranyen/nodegit) +Status](https://travis-ci.org/nodegit/nodegit.png)](https://travis-ci.org/nodegit/nodegit) Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen), Michael Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen [@nk](http://twitter.com/nk), with help from From 6390d6037eedeb0b80a8ce04b9cec8ac202ac8c9 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sat, 22 Mar 2014 23:07:47 -0400 Subject: [PATCH 29/31] Use quotes around version otherwise Travis uses 0.1. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index abb240fe8..cbc54a12d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: - 0.8 - - 0.10 + - "0.10" git: depth: 1 matrix: fast_finish: true allow_failures: - - node_js: 0.11 + - node_js: "0.11" From b3fde651ad8d94c36c95e713d1d475e047aa2bf8 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sat, 22 Mar 2014 23:09:17 -0400 Subject: [PATCH 30/31] Avoid PRs failing the whole project. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index cbc54a12d..1ebe30d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ node_js: - "0.10" git: depth: 1 +branches: + only: + - master matrix: fast_finish: true allow_failures: From 235a86b278c22eac0c47a5c91e2ab8717b2ccba3 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Sun, 23 Mar 2014 16:21:49 -0400 Subject: [PATCH 31/31] Tagging 0.1.1 release. --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7ce4aa29..98bddce54 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ nodegit > Node.js libgit2 bindings -**v0.1.0** [![Build +**v0.1.1** [![Build Status](https://travis-ci.org/nodegit/nodegit.png)](https://travis-ci.org/nodegit/nodegit) Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen), Michael diff --git a/package.json b/package.json index 9b9572202..cb043e981 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2",