diff --git a/.gitignore b/.gitignore index 42cebca29..3c15360fc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /testing.js /out /test.git +/test/.reposCache +.idea diff --git a/.travis.yml b/.travis.yml index f6e2ee0ec..1ebe30d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,13 @@ language: node_js node_js: - 0.8 + - "0.10" git: - depth: 1000 + depth: 1 +branches: + only: + - master +matrix: + fast_finish: true + allow_failures: + - node_js: "0.11" diff --git a/README.md b/README.md index 462e22e18..98bddce54 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ nodegit > Node.js libgit2 bindings -**v0.1.0** [![Build -Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/tbranyen/nodegit) +**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 Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen [@nk](http://twitter.com/nk), with help from @@ -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`. @@ -34,6 +34,12 @@ $ npm run-script gen && npm install && npm test #### 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 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', + " #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/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/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 0416e4f5c..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,12 +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 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/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]; } 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; }; diff --git a/package.json b/package.json index ecdcec807..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", @@ -34,16 +34,18 @@ "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": "", "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/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 e633ffce6..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) { @@ -93,7 +92,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 +219,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 +270,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 +313,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 +344,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/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 43423dd35..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,20 +275,20 @@ 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 = NULL; + git_commit * ancestor = 0; unsigned int from_n; from_n = (unsigned int) args[0]->ToUint32()->Value(); @@ -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 37691b435..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,14 +179,14 @@ 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 = 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(); @@ -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")); } } @@ -211,13 +214,16 @@ 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(); } 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/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/src/index.cc b/src/index.cc index 725192951..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() { @@ -83,34 +85,36 @@ git_index *GitIndex::GetValue() { } +#include "../include/functions/copy.h" + /** * @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) { @@ -120,13 +124,13 @@ void GitIndex::OpenWork(uv_work_t *req) { baton->index_path ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitIndex::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -139,18 +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); } } @@ -163,26 +170,28 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -191,31 +200,34 @@ void GitIndex::ReadWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -227,26 +239,28 @@ void GitIndex::ReadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -255,31 +269,34 @@ void GitIndex::WriteWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -291,34 +308,36 @@ void GitIndex::WriteAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -328,33 +347,36 @@ void GitIndex::ReadTreeWork(uv_work_t *req) { baton->tree ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -365,14 +387,16 @@ void GitIndex::ReadTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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; @@ -380,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) { @@ -396,13 +420,13 @@ void GitIndex::WriteTreeWork(uv_work_t *req) { baton->index ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitIndex::WriteTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -415,21 +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); @@ -442,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( @@ -452,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; @@ -495,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; @@ -525,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; @@ -561,44 +588,46 @@ 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" + /** * @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) { @@ -608,31 +637,34 @@ void GitIndex::AddBypathWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -649,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; @@ -666,54 +698,49 @@ 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 {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()) { - return ThrowException(Exception::Error(String::New("String path is required."))); +NAN_METHOD(GitIndex::Find) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsString()) { + return NanThrowError(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); - return scope.Close(to); + to = Uint32::New(at_pos); + 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; @@ -727,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( @@ -762,52 +789,56 @@ Handle GitIndex::HasConflicts(const Arguments& args) { Handle to; to = Int32::New(result); - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Index} index * @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."))); - } - 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."))); + 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; - from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->index = from_index; - baton->optsReference = Persistent::New(args[2]); - const git_diff_options * from_opts; - from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - 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) { @@ -819,13 +850,13 @@ void GitIndex::IndexToWorkdirWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); IndexToWorkdirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -838,18 +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); } } @@ -863,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 4e94a9595..7ce9f583b 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; @@ -24,48 +25,58 @@ 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); + 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()); - 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 = @@ -79,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 = @@ -97,18 +108,124 @@ Handle GitIndexEntry::Mtime(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Dev) { + NanScope(); + Handle to; + + unsigned int dev = + ObjectWrap::Unwrap(args.This())->GetValue()->dev; + + to = Uint32::New(dev); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Ino) { + NanScope(); + Handle to; + + unsigned int ino = + ObjectWrap::Unwrap(args.This())->GetValue()->ino; + + to = Uint32::New(ino); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Mode) { + NanScope(); + Handle to; + + uint16_t mode = + ObjectWrap::Unwrap(args.This())->GetValue()->mode; + + to = Integer::New(mode); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Uid) { + NanScope(); + Handle to; + + unsigned int uid = + ObjectWrap::Unwrap(args.This())->GetValue()->uid; + + to = Uint32::New(uid); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::gid) { + NanScope(); + Handle to; + + unsigned int gid = + ObjectWrap::Unwrap(args.This())->GetValue()->gid; + + to = Uint32::New(gid); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::FileSize) { + NanScope(); + Handle to; + + unsigned int file_size = + ObjectWrap::Unwrap(args.This())->GetValue()->file_size; + + to = Uint32::New(file_size); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Oid) { + NanScope(); + 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(); + } + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::Flags) { + NanScope(); + Handle to; + + uint16_t flags = + ObjectWrap::Unwrap(args.This())->GetValue()->flags; + + to = Integer::New(flags); + NanReturnValue(to); +} + +NAN_METHOD(GitIndexEntry::FlagsExtended) { + NanScope(); + Handle to; + + uint16_t flags_extended = + ObjectWrap::Unwrap(args.This())->GetValue()->flags_extended; + + to = Integer::New(flags_extended); + 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 efb43047b..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,38 +103,40 @@ Handle GitObject::Type(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -143,13 +147,13 @@ void GitObject::PeelWork(uv_work_t *req) { baton->target_type ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitObject::PeelAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); PeelBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -162,20 +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); @@ -186,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 b02857571..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,19 +79,19 @@ git_odb *GitOdb::GetValue() { /** * @return {Odb} out */ -Handle GitOdb::Create(const Arguments& args) { - HandleScope scope; +NAN_METHOD(GitOdb::Create) { + NanScope(); - git_odb *out = NULL; + git_odb * out = 0; int result = git_odb_new( &out ); 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,20 +101,20 @@ 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 = NULL; + git_odb * out = 0; const char * from_objects_dir; String::Utf8Value objects_dir(args[0]->ToString()); from_objects_dir = strdup(*objects_dir); @@ -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,44 +161,46 @@ 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" + /** * @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) { @@ -207,13 +211,13 @@ void GitOdb::ReadWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitOdb::ReadAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ReadBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -226,18 +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); } } @@ -256,19 +263,19 @@ 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 = NULL; + git_odb_object * out = 0; git_odb * from_db; from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_short_id; @@ -284,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")); } } @@ -296,63 +303,63 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** - * @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()) { - return ThrowException(Exception::Error(String::New("Odb db is required."))); +NAN_METHOD(GitOdb::ReadHeader) { + NanScope(); + if (args.Length() == 0 || !args[0]->IsObject()) { + return NanThrowError(String::New("Odb db is required.")); } - if (args.Length() == 3 || !args[3]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid id is required."))); + if (args.Length() == 1 || !args[1]->IsObject()) { + return NanThrowError(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 ); 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(); + 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); + + 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; @@ -364,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( @@ -384,35 +391,37 @@ 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" + /** * @param {String} data * @param {Number} len * @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; @@ -420,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) { @@ -452,13 +461,13 @@ void GitOdb::WriteWork(uv_work_t *req) { baton->type ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitOdb::WriteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -471,18 +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); } @@ -505,19 +517,19 @@ 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 )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const void * from_data; from_data = Buffer::Data(args[0]->ToObject()); size_t from_len; @@ -534,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")); } } @@ -546,7 +558,7 @@ Handle GitOdb::Hash(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -554,16 +566,16 @@ 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 )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_path; String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); @@ -579,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")); } } @@ -591,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 fbd8ee4a2..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,13 +68,13 @@ 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 )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_str; String::Utf8Value str(args[0]->ToString()); from_str = strdup(*str); @@ -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 a28863254..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,12 +115,12 @@ 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 = 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 @@ -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,16 +157,16 @@ 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 = 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(); @@ -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,20 +242,20 @@ 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 = 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; @@ -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,16 +296,16 @@ 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 = NULL; + char * string = 0; int result = git_diff_patch_to_str( &string @@ -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 86258e948..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() { @@ -77,22 +79,25 @@ git_reference *GitReference::GetValue() { } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @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; @@ -100,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) { @@ -124,13 +130,13 @@ void GitReference::OidForNameWork(uv_work_t *req) { baton->name ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitReference::OidForNameAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OidForNameBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -143,21 +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); @@ -172,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() @@ -189,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( @@ -205,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() @@ -221,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() @@ -237,30 +247,33 @@ Handle GitReference::Name(const Arguments& args) { Handle to; to = String::New(result); - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -270,13 +283,13 @@ void GitReference::ResolveWork(uv_work_t *req) { baton->ref ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitReference::ResolveAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); ResolveBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -289,20 +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); @@ -316,13 +332,13 @@ 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 = NULL; + git_reference * out = 0; const char * from_target; String::Utf8Value target(args[0]->ToString()); from_target = strdup(*target); @@ -335,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")); } } @@ -347,20 +363,20 @@ 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 = NULL; + git_reference * out = 0; const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -371,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")); } } @@ -383,47 +399,49 @@ Handle GitReference::setTarget(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @param {String} new_name * @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) { @@ -435,39 +453,42 @@ void GitReference::RenameWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -480,26 +501,28 @@ void GitReference::RenameAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -508,33 +531,36 @@ void GitReference::DeleteWork(uv_work_t *req) { baton->ref ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -546,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( @@ -575,26 +600,26 @@ 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 = NULL; + git_object * out = 0; git_otype from_type; from_type = (git_otype) args[0]->ToInt32()->Value(); @@ -605,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")); } } @@ -617,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; @@ -639,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 3445111a0..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,43 +178,45 @@ 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" + /** * @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) { @@ -221,31 +226,34 @@ void GitRemote::ConnectWork(uv_work_t *req) { baton->direction ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -258,37 +266,40 @@ void GitRemote::ConnectAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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 = NULL; - } - 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) { @@ -299,31 +310,34 @@ void GitRemote::DownloadWork(uv_work_t *req) { baton->payload ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -339,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( @@ -348,48 +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) { @@ -400,25 +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); } } @@ -432,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( @@ -441,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; @@ -469,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; @@ -497,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; @@ -523,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( @@ -537,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; @@ -563,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; @@ -585,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 98e598050..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() { @@ -105,34 +109,36 @@ git_repository *GitRepo::GetValue() { } +#include "../include/functions/copy.h" + /** * @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) { @@ -142,13 +148,13 @@ void GitRepo::OpenWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -161,20 +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); @@ -185,42 +194,44 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} path * @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) { @@ -231,13 +242,13 @@ void GitRepo::InitWork(uv_work_t *req) { baton->is_bare ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::InitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); InitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -250,20 +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); @@ -278,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( @@ -288,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( @@ -304,16 +318,16 @@ 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 = NULL; + git_odb * out = 0; int result = git_repository_odb( &out @@ -321,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")); } } @@ -333,30 +347,32 @@ Handle GitRepo::Odb(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -366,13 +382,13 @@ void GitRepo::openIndexWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::openIndexAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); openIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -385,20 +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); @@ -408,35 +427,37 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -447,13 +468,13 @@ void GitRepo::GetBlobWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetBlobAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetBlobBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -466,18 +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); } } @@ -490,35 +514,37 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -529,13 +555,13 @@ void GitRepo::GetCommitWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetCommitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -548,20 +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); @@ -572,6 +601,8 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} update_ref * @param {Signature} author @@ -583,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; @@ -613,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 = NULL; - } - 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 = NULL; - } - 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) { @@ -685,13 +715,13 @@ void GitRepo::CreateCommitWork(uv_work_t *req) { baton->parents ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CreateCommitAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -704,21 +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); @@ -740,43 +773,46 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Oid} id * @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) { @@ -788,13 +824,13 @@ void GitRepo::GetObjectWork(uv_work_t *req) { baton->type ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetObjectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -807,18 +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); } } @@ -832,36 +871,38 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -872,13 +913,13 @@ void GitRepo::GetReferenceWork(uv_work_t *req) { baton->name ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetReferenceAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetReferenceBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -891,18 +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); } } @@ -922,19 +966,19 @@ 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 = NULL; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -955,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")); } } @@ -967,7 +1011,7 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -976,19 +1020,19 @@ 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 = NULL; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1007,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")); } } @@ -1019,48 +1063,50 @@ Handle GitRepo::CreateReference(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @param {String} name * @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) { @@ -1072,13 +1118,13 @@ void GitRepo::AddRemoteWork(uv_work_t *req) { baton->url ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::AddRemoteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); AddRemoteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1091,18 +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); } } @@ -1121,10 +1170,10 @@ 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 = NULL; + git_revwalk * out = 0; int result = git_revwalk_new( &out @@ -1132,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")); } } @@ -1144,20 +1193,20 @@ 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 = NULL; + git_submodule * submodule = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1170,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")); } } @@ -1182,7 +1231,7 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } /** @@ -1191,19 +1240,19 @@ 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 = NULL; + git_submodule * submodule = 0; const char * from_url; String::Utf8Value url(args[0]->ToString()); from_url = strdup(*url); @@ -1224,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")); } } @@ -1236,38 +1285,40 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -1278,13 +1329,13 @@ void GitRepo::GetTagWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1297,18 +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); } } @@ -1321,6 +1375,8 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} tag_name * @param {Object} target @@ -1329,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; @@ -1356,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) { @@ -1399,13 +1455,13 @@ void GitRepo::CreateTagWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CreateTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1418,18 +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); } @@ -1449,26 +1508,28 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} tag_name * @param {Object} target * @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; @@ -1476,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) { @@ -1508,13 +1569,13 @@ void GitRepo::CreateLightweightTagWork(uv_work_t *req) { baton->force ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateLightweightTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1527,18 +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); } @@ -1555,35 +1619,37 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -1594,13 +1660,13 @@ void GitRepo::GetTreeWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1613,18 +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); } } @@ -1637,26 +1706,28 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -1665,31 +1736,34 @@ void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -1701,35 +1775,37 @@ void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -1739,31 +1815,34 @@ void GitRepo::DeleteWork(uv_work_t *req) { baton->tag_name ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -1777,15 +1856,17 @@ void GitRepo::DeleteAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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; @@ -1793,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 = NULL; - } - 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) { @@ -1818,13 +1899,13 @@ void GitRepo::GetReferencesWork(uv_work_t *req) { baton->list_flags ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetReferencesAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetReferencesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1838,18 +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); } @@ -1865,22 +1949,24 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Buffer} buffer * @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; @@ -1888,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) { @@ -1914,13 +2000,13 @@ void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { baton->len ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateBlobFromBufferBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1933,18 +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); } @@ -1959,18 +2048,20 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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; @@ -1978,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) { @@ -2000,13 +2091,13 @@ void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CreateBlobFromFileBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2019,18 +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); } @@ -2045,14 +2139,16 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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; @@ -2060,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) { @@ -2076,13 +2172,13 @@ void GitRepo::GetRemotesWork(uv_work_t *req) { baton->repo ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::GetRemotesAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetRemotesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2096,18 +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); } @@ -2122,52 +2221,54 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {String} url * @param {String} local_path * @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 = NULL; - } - 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) { @@ -2179,13 +2280,13 @@ void GitRepo::CloneWork(uv_work_t *req) { baton->options ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRepo::CloneAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); CloneBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2198,20 +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); @@ -2229,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 = NULL; + 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 @@ -2248,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")); } } @@ -2260,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 ec5ff3c5d..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,45 +77,47 @@ 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" + /** * @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) { @@ -123,31 +127,34 @@ void GitRevWalk::PushWork(uv_work_t *req) { baton->id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -160,35 +167,37 @@ void GitRevWalk::PushAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -198,31 +207,34 @@ void GitRevWalk::PushGlobWork(uv_work_t *req) { baton->glob ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -236,26 +248,28 @@ void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -264,31 +278,34 @@ void GitRevWalk::PushHeadWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -300,34 +317,36 @@ void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -337,31 +356,34 @@ void GitRevWalk::HideWork(uv_work_t *req) { baton->commit_id ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -374,35 +396,37 @@ void GitRevWalk::HideAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -412,31 +436,34 @@ void GitRevWalk::HideGlobWork(uv_work_t *req) { baton->glob ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -450,26 +477,28 @@ void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -478,33 +507,36 @@ void GitRevWalk::HideHeadWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -514,35 +546,37 @@ void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -552,33 +586,36 @@ void GitRevWalk::PushRefWork(uv_work_t *req) { baton->refname ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -590,35 +627,37 @@ void GitRevWalk::PushRefAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -628,33 +667,36 @@ void GitRevWalk::HideRefWork(uv_work_t *req) { baton->refname ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); @@ -666,14 +708,16 @@ void GitRevWalk::HideRefAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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; @@ -681,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) { @@ -697,13 +741,13 @@ void GitRevWalk::NextWork(uv_work_t *req) { baton->walk ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitRevWalk::NextAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); NextBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -716,18 +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); } @@ -743,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; @@ -757,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 de0d84051..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,22 +76,22 @@ 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 = NULL; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -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,16 +134,16 @@ 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 = NULL; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -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 d6b968a0b..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() { @@ -76,26 +79,28 @@ git_submodule *GitSubmodule::GetValue() { } +#include "../include/functions/copy.h" + /** */ -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) { @@ -104,31 +109,34 @@ void GitSubmodule::AddFinalizeWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -140,34 +148,36 @@ void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -177,31 +187,34 @@ void GitSubmodule::AddToIndexWork(uv_work_t *req) { baton->write_index ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -214,26 +227,28 @@ void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -242,31 +257,34 @@ void GitSubmodule::SaveWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -281,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( @@ -291,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( @@ -307,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( @@ -323,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; @@ -346,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( @@ -375,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( @@ -398,37 +416,39 @@ Handle GitSubmodule::HeadId(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -438,31 +458,34 @@ void GitSubmodule::InitWork(uv_work_t *req) { baton->overwrite ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -475,26 +498,28 @@ void GitSubmodule::InitAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -503,31 +528,34 @@ void GitSubmodule::SyncWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -539,27 +567,29 @@ void GitSubmodule::SyncAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -569,13 +599,13 @@ void GitSubmodule::OpenWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitSubmodule::OpenAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -588,18 +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); } } @@ -611,26 +644,28 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** */ -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) { @@ -639,31 +674,34 @@ void GitSubmodule::ReloadWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -675,34 +713,36 @@ void GitSubmodule::ReloadAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @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) { @@ -712,31 +752,34 @@ void GitSubmodule::StatusWork(uv_work_t *req) { baton->submodule ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } 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); } } @@ -749,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 a0443dbb6..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,30 +95,32 @@ Handle GitTag::Oid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -125,13 +130,13 @@ void GitTag::GetTargetWork(uv_work_t *req) { baton->tag ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTag::GetTargetAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetTargetBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -144,18 +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); } } @@ -170,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() @@ -187,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( @@ -203,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( @@ -219,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( @@ -242,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( @@ -258,20 +265,20 @@ 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 = NULL; + git_object * tag_target_out = 0; const git_tag * from_tag; from_tag = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -281,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")); } } @@ -293,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 3e8eaa888..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,39 +207,41 @@ Handle GitTree::EntryByOid(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -248,13 +252,13 @@ void GitTree::GetEntryWork(uv_work_t *req) { baton->path ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTree::GetEntryAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetEntryBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -267,18 +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); } } @@ -295,10 +302,10 @@ 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 = NULL; + git_treebuilder * out = 0; int result = git_treebuilder_create( &out @@ -306,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")); } } @@ -318,55 +325,57 @@ Handle GitTree::Builder(const Arguments& args) { } else { to = Null(); } - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Tree} new_tree * @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 = NULL; - } - 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) { @@ -379,13 +388,13 @@ void GitTree::DiffTreeWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTree::DiffTreeAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -398,18 +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); } } @@ -424,51 +436,55 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @param {Index} index * @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."))); - } - 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."))); + 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; - from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - baton->index = from_index; - baton->optsReference = Persistent::New(args[2]); - const git_diff_options * from_opts; - from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); - 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) { @@ -481,13 +497,13 @@ void GitTree::DiffIndexWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTree::DiffIndexAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -500,18 +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); } } @@ -526,43 +545,46 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { delete baton; } +#include "../include/functions/copy.h" + /** * @param {Repository} repo * @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."))); - } - if (args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("DiffOptions opts 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; - from_opts = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); - 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) { @@ -574,13 +596,13 @@ void GitTree::DiffWorkDirWork(uv_work_t *req) { baton->opts ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); DiffWorkDirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -593,18 +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); } } @@ -618,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 798f8098a..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,15 +80,15 @@ 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 = 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( @@ -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,19 +185,19 @@ 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 = NULL; + const git_tree_entry * out = 0; const char * from_filename; String::Utf8Value filename(args[0]->ToString()); from_filename = strdup(*filename); @@ -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,27 +254,29 @@ 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" + /** * @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; @@ -280,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) { @@ -301,13 +305,13 @@ void GitTreeBuilder::WriteWork(uv_work_t *req) { baton->bld ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -320,18 +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); } @@ -345,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 a2f4aa7a6..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,38 +138,40 @@ Handle GitTreeEntry::filemode(const Arguments& args) { Handle to; to = Number::New(result); - return scope.Close(to); + NanReturnValue(to); } +#include "../include/functions/copy.h" + /** * @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) { @@ -178,13 +182,13 @@ void GitTreeEntry::GetObjectWork(uv_work_t *req) { baton->entry ); baton->error_code = result; - if (result != GIT_OK) { - baton->error = giterr_last(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } } void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { - HandleScope scope; + NanScope(); GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -197,18 +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); } } @@ -221,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 d513cb5ad..f2d2463be 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" @@ -16,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(); @@ -68,10 +71,10 @@ 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); + NanReturnValue(nodeBuffer); } -Persistent Wrapper::constructor_template; +Persistent Wrapper::constructor_template; diff --git a/templates/asyncFunction.cc.ejs b/templates/asyncFunction.cc.ejs index 1a4c98347..98ef78218 100644 --- a/templates/asyncFunction.cc.ejs +++ b/templates/asyncFunction.cc.ejs @@ -1,3 +1,5 @@ +#include "../include/functions/copy.h" + /** <% include doc.cc.ejs -%> */ @@ -56,8 +58,8 @@ 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(); + if (result != GIT_OK && giterr_last() != NULL) { + baton->error = git_error_dup(giterr_last()); } <% } else if (functionInfo.return.cType != "void") { -%> baton->result = result; @@ -99,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); } 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/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..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 %> = NULL; + <%- unPointer(arg.cType) %> <%- arg.name %> = <%- defaultValue(unPointer(arg.cType)) %>; <% } -%> <% } -%> <% 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..70f3128dd 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.ok(error instanceof Error); + 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); }); diff --git a/v0.18.0.json b/v0.18.0.json index 8c781448c..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, @@ -4142,7 +4143,8 @@ { "filename": "index_entry.h", "dependencies": [ - "../include/index_time.h" + "../include/index_time.h", + "../include/oid.h" ], "jsClassName": "IndexEntry", "cppClassName": "GitIndexEntry", @@ -4167,6 +4169,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", @@ -4858,6 +4933,7 @@ "args": [ { "name": "at_pos", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -5364,6 +5440,7 @@ "cType": "git_index *", "cppClassName": "GitIndex", "jsClassName": "Index", + "isOptional": true, "comment": "The index to diff from; repo index used if NULL." }, { @@ -5371,6 +5448,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ], @@ -6779,6 +6857,7 @@ "args": [ { "name": "len_out", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -6786,6 +6865,7 @@ }, { "name": "type_out", + "isReturn": true, "cType": "git_otype *", "cppClassName": "Int32", "jsClassName": "Number", @@ -16933,6 +17013,7 @@ "cType": "git_index *", "cppClassName": "GitIndex", "jsClassName": "Index", + "isOptional": true, "comment": "The index to diff with; repo index used if NULL." }, { @@ -16940,6 +17021,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ], @@ -16987,6 +17069,7 @@ "cType": "const git_diff_options *", "cppClassName": "GitDiffOptions", "jsClassName": "DiffOptions", + "isOptional": true, "comment": "Structure with options to influence diff or NULL for defaults." } ],