diff --git a/.gitignore b/.gitignore index 3c15360fc..be86e88da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,9 @@ -# Files -.DS_Store -/sftp-config.json +/build/* +!/build/codegen/ -# Directories -/build -/example/stress/test -/doc -!doc/Theme.css -/node_modules -/testing.js -/out -/test.git -/test/.reposCache -.idea +/doc/* +!/doc/Theme.css + +/node_modules/ +/vendor/libgit2/ +/test/repos/ diff --git a/.travis.yml b/.travis.yml index 1ebe30d0b..0604aaedf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - 0.8 - "0.10" + - 0.11 git: depth: 1 branches: @@ -10,4 +11,4 @@ branches: matrix: fast_finish: true allow_failures: - - node_js: "0.11" + - node_js: 0.11 diff --git a/LICENSE b/LICENSE index 80bc57cb1..8fe4c2f4c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 Tim Branyen +Copyright (c) 2014 Tim Branyen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 98bddce54..e9affb8fc 100644 --- a/README.md +++ b/README.md @@ -1,117 +1,198 @@ -nodegit -======= +NodeGit +------- -> Node.js libgit2 bindings +> Node bindings to the [libgit2](http://libgit2.github.com/) project. -**v0.1.1** [![Build -Status](https://travis-ci.org/nodegit/nodegit.png)](https://travis-ci.org/nodegit/nodegit) +[![Build +Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/nodegit/nodegit) +Build Status: Windows + +**Stable: 0.1.2** 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 -[awesome +Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen +[@nk](http://twitter.com/nk), with help from [awesome contributors](https://github.com/tbranyen/nodegit/contributors)! -API Documentation ------------------------- +## API Documentation. ## -Documentation may be found here: [`nodegit` documentation](http://www.nodegit.org/nodegit/). +http://www.nodegit.org/nodegit/ -Building and installing ------------------------ +## Building and Installing. ## -### Dependencies ### +Minimum dependencies: -To install `nodegit` you need `Node.js`, `python` and `cmake` (>=2.8). +* [Python 2](https://www.python.org/) +* [CMake >= 2.8](http://www.cmake.org/) -### Easy install (Recommended) ### -This will install and configure everything you need to use `nodegit`. +``` bash +npm install nodegit +``` -```` bash -$ npm run-script gen && npm install && npm test -```` +### Building manually: ### -### Mac OS X/Linux/Unix ### +If you wish to help contribute to nodegit it is useful to build locally. -#### Install `nodegit` by cloning source from GitHub and running `node install`: #### +``` bash +# Fetch this project. +git clone git://github.com/tbranyen/nodegit.git -```` bash -# Install system dependencies -$ brew install cmake libzip -$ npm install -g node-gyp -```` +# Enter the repository. +cd nodegit -```` bash -$ git clone git://github.com/tbranyen/nodegit.git -$ cd nodegit -$ npm run-script gen && npm install -```` +# Install the template engine, run the code generation script, and install. +npm install ejs && npm run codegen && npm install +``` -### Windows via Cygwin ### +If you encounter errors, you most likely have not configured the dependencies +correctly. -#### `nodegit` has been compiled and tested to work with the setup required to build and run `Node.js` itself. #### +### Installing dependencies: ### -Instructions on compiling `Node.js` on a Windows platform can be found here: -[https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows)](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29) +#### OS X #### -API Example Usage ------------------ +Using Brew: -Below are two examples. [There are several more](https://github.com/nodegit/nodegit/tree/master/example). +``` bash +brew install cmake libzip +``` -### Git Log Emulation ### +#### Linux #### -```JavaScript -var git = require('../'), - path = require('path'); +Using APT in Ubuntu: -git.Repo.open(path.resolve(__dirname, '/tmp/repo/.git'), function(error, repo) { - if (error) throw error; +``` bash +sudo apt-get install cmake libzip-dev build-essential +``` - repo.getMaster(function(error, branch) { - if (error) throw error; +Using Pacman in Arch Linux: - // History returns an event. - var history = branch.history(); +``` bash +sudo pacman -S cmake libzip base-devel +``` - // History emits 'commit' event for each commit in the branch's history - history.on('commit', function(commit) { - console.log('commit ' + commit.sha()); - console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>'); - console.log('Date:', commit.date()); - console.log('\n ' + commit.message()); - }); +#### Windows #### - // Don't forget to call `start()`! - history.start(); - }); -}); +For Windows users, you will have to install Visual Studio Express. You may +have to add a build flag to the installation process to successfully install. +Try first without, if the build fails, try again with the flag. + +*Allegedly the order in which you install Visual Studio could trigger this +error.* + +- [Download and install CMake](http://www.cmake.org/cmake/resources/software.html). +- [Download and install Python](https://www.python.org/download/windows) +- [Download and install VS Express](http://www.visualstudio.com/downloads/download-visual-studio-vs#d-express-windows-desktop) +``` bash +npm install nodegit --msvs_version=2013 +# Or whatever version you've installed. ``` -### Clone a repo and read a file ### +## API examples. ## + +### Cloning a repository and reading a file: ### + +``` javascript +var clone = require("nodegit").Repo.clone; -```JavaScript -git.Repo.clone("https://github.com/nodegit/nodegit.git", path, null, function(error, repo) { - if (error) throw error; +// Clone a given repository into a specific folder. +clone("https://github.com/nodegit/nodegit", "tmp", null, function(err, repo) { + if (err) { + throw err; + } - repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) { - if (error) throw error; + // Use a known commit sha from this repository. + var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"; - commit.getEntry('README.md', function(error, entry) { - if (error) throw error; + // Look up this known commit. + repo.getCommit(sha, function(err, commit) { + if (err) { + throw error; + } - entry.getBlob(function(error, blob) { - if (error) throw error; + // Look up a specific file within that commit. + commit.getEntry("README.md", function(err, entry) { + if (err) { + throw error; + } - console.log(entry.name(), entry.sha(), blob.size() + 'b'); - console.log('========================================================\n\n'); - var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n'); - console.log(firstTenLines); - console.log('...'); + // Get the blob contents from the file. + entry.getBlob(function(err, blob) { + if (err) { + throw err; + } + + // Show the name, sha, and filesize in byes. + console.log(entry.name() + entry.sha() + blob.size() + "b"); + + // Show a spacer. + console.log(Array(72).join("=") + "\n\n"); + + // Show the entire file. + console.log(String(blob)); }); }); }); }); ``` -[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/a81b20d9f61dbcdc7c68002c6a564b5b "githalytics.com")](http://githalytics.com/tbranyen/nodegit) +### Emulating git log: ### + +``` javascript +var open = require("nodegit").Repo.open; + +// Open the repository directory. +open("tmp", function(err, repo) { + if (err) { + throw err; + } + + // Open the master branch. + repo.getMaster(function(err, branch) { + if (err) { + throw err; + } + + // Create a new history event emitter. + var history = branch.history(); + + // Create a counter to only show up to 9 entries. + var count = 0; + + // Listen for commit events from the history. + history.on("commit", function(commit) { + // Disregard commits past 9. + if (++count >= 9) { + return; + } + + // Show the commit sha. + console.log("commit " + commit.sha()); + + // Store the author object. + var author = commit.author(); + + // Display author information. + console.log("Author:\t" + author.name() + " <", author.email() + ">"); + + // Show the commit date. + console.log("Date:\t" + commit.date()); + + // Give some space and show the message. + console.log("\n " + commit.message()); + }); + + // Start emitting events. + history.start(); + }); +}); +``` + +## Unit tests. ## + +You will need to build locally before running the tests. See above. + +``` bash +npm test +``` diff --git a/TODO b/TODO deleted file mode 100644 index 34afdf82b..000000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -- codegen documentation diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..5dfc10162 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,36 @@ +# appveyor file +# http://www.appveyor.com/docs/appveyor-yml +project_id: "e5a5q75l9yfhnfv2" + +# build version format +version: "{build}" + +# fix lineendings in Windows +init: + - git config --global core.autocrlf input + +# what combinations to test +environment: + matrix: + - nodejs_version: 0.11 + - nodejs_version: 0.10 + - nodejs_version: 0.8 + +matrix: + allow_failures: + - nodejs_version: 0.11 + +# Get the latest stable version of Node 0.STABLE.latest +install: + - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) + - cmd: SET PATH=C:\Program Files (x86)\MSBuild\12.0\bin\;%PATH% + - cmd: SET PATH=c:\python27;%PATH% + - cmd: npm install -g node-gyp + - npm install --msvs_version=2013 + +test_script: + - node --version + - npm --version + - cmd: npm test + +build: off diff --git a/binding.gyp b/binding.gyp index 17d1dc5f3..6233c2826 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,70 +1,80 @@ { - 'targets': [ - { - 'target_name': 'nodegit', - 'sources': [ - 'src/base.cc', - 'src/blob.cc', - 'src/commit.cc', - 'src/oid.cc', - 'src/reference.cc', - 'src/object.cc', - 'src/repo.cc', - 'src/index.cc', - 'src/index_entry.cc', - 'src/index_time.cc', - 'src/tag.cc', - 'src/revwalk.cc', - 'src/signature.cc', - 'src/time.cc', - 'src/tree.cc', - 'src/tree_builder.cc', - 'src/tree_entry.cc', - 'src/diff_find_options.cc', - 'src/diff_options.cc', - 'src/diff_list.cc', - 'src/patch.cc', - 'src/delta.cc', - 'src/diff_file.cc', - 'src/diff_range.cc', - 'src/threads.cc', - 'src/wrapper.cc', - 'src/refdb.cc', - 'src/odb_object.cc', - 'src/odb.cc', - 'src/submodule.cc', - 'src/remote.cc', - 'src/clone_options.cc', - 'src/functions/copy.cc', + "targets": [ + { + "target_name": "nodegit", - ], + "sources": [ + "src/base.cc", + "src/blob.cc", + "src/commit.cc", + "src/oid.cc", + "src/reference.cc", + "src/object.cc", + "src/repo.cc", + "src/index.cc", + "src/index_entry.cc", + "src/index_time.cc", + "src/tag.cc", + "src/revwalk.cc", + "src/signature.cc", + "src/time.cc", + "src/tree.cc", + "src/tree_builder.cc", + "src/tree_entry.cc", + "src/diff_find_options.cc", + "src/diff_options.cc", + "src/diff_list.cc", + "src/patch.cc", + "src/delta.cc", + "src/diff_file.cc", + "src/diff_range.cc", + "src/threads.cc", + "src/wrapper.cc", + "src/refdb.cc", + "src/odb_object.cc", + "src/odb.cc", + "src/submodule.cc", + "src/remote.cc", + "src/clone_options.cc", + "src/functions/copy.cc", + ], - 'include_dirs': [ - 'vendor/libv8-convert', - 'vendor/libgit2/include', - "::Initialize(Handle target) { -%> <% if (functionInfo.isAsync) { -%> -<% include templates/asyncFunction.cc.ejs -%> +<% include build/codegen/templates/asyncFunction.cc.ejs -%> <% } else { -%> -<% include templates/syncFunction.cc.ejs -%> +<% include build/codegen/templates/syncFunction.cc.ejs -%> <% } -%> <% } -%> <% } -%> -<% include templates/fields.cc.ejs -%> +<% include build/codegen/templates/fields.cc.ejs -%> <% if (typeof cType != 'undefined') { -%> Persistent <%- cppClassName %>::constructor_template; diff --git a/templates/convertFromV8.cc.ejs b/build/codegen/templates/convertFromV8.cc.ejs similarity index 90% rename from templates/convertFromV8.cc.ejs rename to build/codegen/templates/convertFromV8.cc.ejs index 58f238533..d1a442e34 100644 --- a/templates/convertFromV8.cc.ejs +++ b/build/codegen/templates/convertFromV8.cc.ejs @@ -20,7 +20,7 @@ <% } else if (arg.cppClassName == 'Buffer') { -%> from_<%- arg.name %> = Buffer::Data(args[<%- jsArg %>]->ToObject()); <% } else if (isV8Value(arg.cppClassName)) { -%> - from_<%- arg.name %> = (<%- arg.cType %>) args[<%- jsArg %>]->To<%- arg.cppClassName %>()->Value(); + from_<%- arg.name %> = (<%- arg.cType %>) <%- arg.additionalCast %> <%- arg.cast %> args[<%- jsArg %>]->To<%- arg.cppClassName %>()->Value(); <% } else { -%> from_<%- arg.name %> = ObjectWrap::Unwrap<<%- arg.cppClassName %>>(args[<%- jsArg %>]->ToObject())->GetValue(); <% } -%> @@ -29,4 +29,4 @@ from_<%- arg.name %> = 0; } <% } -%> -<% } -%> \ No newline at end of file +<% } -%> diff --git a/templates/convertToV8.cc.ejs b/build/codegen/templates/convertToV8.cc.ejs similarity index 100% rename from templates/convertToV8.cc.ejs rename to build/codegen/templates/convertToV8.cc.ejs diff --git a/templates/doc.cc.ejs b/build/codegen/templates/doc.cc.ejs similarity index 100% rename from templates/doc.cc.ejs rename to build/codegen/templates/doc.cc.ejs diff --git a/templates/fields.cc.ejs b/build/codegen/templates/fields.cc.ejs similarity index 100% rename from templates/fields.cc.ejs rename to build/codegen/templates/fields.cc.ejs diff --git a/templates/guardArguments.cc.ejs b/build/codegen/templates/guardArguments.cc.ejs similarity index 100% rename from templates/guardArguments.cc.ejs rename to build/codegen/templates/guardArguments.cc.ejs diff --git a/templates/header.h.ejs b/build/codegen/templates/header.h.ejs similarity index 100% rename from templates/header.h.ejs rename to build/codegen/templates/header.h.ejs diff --git a/templates/syncFunction.cc.ejs b/build/codegen/templates/syncFunction.cc.ejs similarity index 100% rename from templates/syncFunction.cc.ejs rename to build/codegen/templates/syncFunction.cc.ejs diff --git a/v0.18.0.json b/build/codegen/v0.18.0.json similarity index 99% rename from v0.18.0.json rename to build/codegen/v0.18.0.json index 58127837d..1671d2a81 100644 --- a/v0.18.0.json +++ b/build/codegen/v0.18.0.json @@ -10380,7 +10380,8 @@ "cType": "git_direction", "cppClassName": "Number", "jsClassName": "Number", - "comment": "GIT_DIRECTION_FETCH if you want to fetch or GIT_DIRECTION_PUSH if you want to push" + "comment": "GIT_DIRECTION_FETCH if you want to fetch or GIT_DIRECTION_PUSH if you want to push", + "additionalCast": "(int)" } ], "isAsync": true, @@ -17283,7 +17284,8 @@ "cType": "git_filemode_t", "cppClassName": "Number", "jsClassName": "Number", - "comment": "Folder attributes of the entry. This parameter must be valued with one of the following entries: 0040000, 0100644, 0100755, 0120000 or 0160000." + "comment": "Folder attributes of the entry. This parameter must be valued with one of the following entries: 0040000, 0100644, 0100755, 0120000 or 0160000.", + "additionalCast": "(int)" } ], "isAsync": false, diff --git a/example/apps/git_profanity_check.js b/example/apps/git_profanity_check.js index 618eb7a66..7f0674849 100644 --- a/example/apps/git_profanity_check.js +++ b/example/apps/git_profanity_check.js @@ -1,40 +1,66 @@ #!/usr/bin/env node +// vim: ft=javascript -// Copyright 2011, Tim Branyen @tbranyen +// Copyright 2011-2014, Tim Branyen @tbranyen // Dual licensed under the MIT and GPL licenses. -// Script to detect cursewords in commit messages and provide the -// offending commit sha's. -// vim: ft=javascript +// Script to detect cursewords in commit messages and provide the offending +// commit sha's. +// +// Usage: +// +// node git_profanity_check some/repo/.git +// var git = require('../../'); -var curses = ['add', 'swears', 'here'], - path = '../../.git', - branchName = 'master', - reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); - +var curses = ['put', 'curse', 'words', 'here']; +var path = './.git'; +var branch = 'master'; +var reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); +// Default path is `.git`. if (process.argv.length < 3) { - console.log('No git path passed as argument, defaulting to ./.git'); -} else { + console.log('No path passed as argument, defaulting to .git.'); +} +// Otherwise defaults. +else { path = process.argv[2]; + // Set repo branch if (process.argv.length < 4) { - console.log('No repo branchName passed as argument, defaulting to master'); - } else { - branchName = process.argv[3]; + console.log('No branch passed as argument, defaulting to master.'); + } + else { + branch = process.argv[3]; } } -git.Repo.open(path, function(error, repo) { - if (error) throw error; +// Open repository. +git.Repo.open(path, function(err, repo) { + if (err) { + throw new Error(err); + } - repo.getBranch(branchName, function(error, branch) { - if (error) throw error; + // Open branch, default to master. + repo.getBranch(branch, function(err, branch) { + if (err) { + throw new Error(err); + } + // Iterate history var history = branch.history(); + + // Iterate over every commit message and test for words. history.on('commit', function(commit) { - if (reCurse.test(commit.message())) - console.log('Curse detected in commit', commit.sha(), 'message', commit.message()); - }).start(); + var message = commit.message(); + + if (reCurse.test(message)) { + console.log('Curse detected in commit', commit.sha()); + console.log('=> ', message); + return; + } + }); + + // Start history iteration. + history.start(); }); }); diff --git a/gen.js b/gen.js deleted file mode 100644 index d05c6d7ad..000000000 --- a/gen.js +++ /dev/null @@ -1,17 +0,0 @@ -var fs = require('fs'), - ejs = require('ejs'), - path = require('path'); - -var idefs = JSON.parse(fs.readFileSync('v0.18.0.json')), - classTemplate = ejs.compile(fs.readFileSync(path.resolve("./templates/class.cc.ejs")).toString(), {filename: 'class.cc'}), - headerTemplate = ejs.compile(fs.readFileSync(path.resolve("./templates/header.h.ejs")).toString(), {filename: 'header.h'}); - -for (var i in idefs) { - var idef = idefs[i]; - if (idef.ignore) continue; - - fs.writeFileSync( - path.resolve("./include/" + idef.filename), headerTemplate(idef)); - fs.writeFileSync( - path.resolve("./src/" + path.basename(idef.filename, '.h') + '.cc'), classTemplate(idef)); -} diff --git a/include/blob.h b/include/blob.h index 94f3537bd..561338354 100755 --- a/include/blob.h +++ b/include/blob.h @@ -8,7 +8,6 @@ #include #include #include -#include "nan.h" #include "git2.h" @@ -18,7 +17,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(); @@ -29,12 +28,13 @@ class GitBlob : public ObjectWrap { GitBlob(git_blob *raw); ~GitBlob(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(Oid); - static NAN_METHOD(Content); - static NAN_METHOD(Size); - static NAN_METHOD(IsBinary); + + static Handle Oid(const Arguments& args); + static Handle Content(const Arguments& args); + static Handle Size(const Arguments& args); + static Handle IsBinary(const Arguments& args); git_blob *raw; }; diff --git a/include/branch.h b/include/branch.h index 67b4eb373..bfbf9bcdb 100644 --- a/include/branch.h +++ b/include/branch.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,19 +28,20 @@ class Branch : public ObjectWrap { Branch(git_branch *raw); ~Branch(); - 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); + 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); git_branch *raw; }; diff --git a/include/clone_options.h b/include/clone_options.h index 42db7e0c8..14da5daad 100644 --- a/include/clone_options.h +++ b/include/clone_options.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,7 +28,8 @@ class GitCloneOptions : public ObjectWrap { GitCloneOptions(git_clone_options *raw); ~GitCloneOptions(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + git_clone_options *raw; }; diff --git a/include/commit.h b/include/commit.h index a02ed9f77..6f69f5889 100755 --- a/include/commit.h +++ b/include/commit.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,19 +28,20 @@ class GitCommit : public ObjectWrap { GitCommit(git_commit *raw); ~GitCommit(); - 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); + 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); git_commit *raw; }; diff --git a/include/delta.h b/include/delta.h index d46511b9c..e06f6283c 100644 --- a/include/delta.h +++ b/include/delta.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,13 +28,13 @@ class GitDelta : public ObjectWrap { GitDelta(git_diff_delta *raw); ~GitDelta(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(OldFile); - static NAN_METHOD(NewFile); - static NAN_METHOD(Status); - static NAN_METHOD(Similarity); - static NAN_METHOD(Flags); + 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); git_diff_delta *raw; }; diff --git a/include/diff_file.h b/include/diff_file.h index adb50ab42..f7f8210d0 100644 --- a/include/diff_file.h +++ b/include/diff_file.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,13 +28,13 @@ class GitDiffFile : public ObjectWrap { GitDiffFile(git_diff_file *raw); ~GitDiffFile(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(Oid); - static NAN_METHOD(Path); - static NAN_METHOD(Size); - static NAN_METHOD(Flags); - static NAN_METHOD(Mode); + 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); git_diff_file *raw; }; diff --git a/include/diff_find_options.h b/include/diff_find_options.h index d76efe975..3500d1b23 100644 --- a/include/diff_find_options.h +++ b/include/diff_find_options.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,7 +28,8 @@ class GitDiffFindOptions : public ObjectWrap { GitDiffFindOptions(git_diff_find_options *raw); ~GitDiffFindOptions(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + git_diff_find_options *raw; }; diff --git a/include/diff_list.h b/include/diff_list.h index 04c604766..185a00e56 100644 --- a/include/diff_list.h +++ b/include/diff_list.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -29,15 +27,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 292269763..6dd93a0b8 100644 --- a/include/diff_options.h +++ b/include/diff_options.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,7 +28,8 @@ class GitDiffOptions : public ObjectWrap { GitDiffOptions(git_diff_options *raw); ~GitDiffOptions(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + git_diff_options *raw; }; diff --git a/include/diff_range.h b/include/diff_range.h index 7df5b8042..bb44337b4 100644 --- a/include/diff_range.h +++ b/include/diff_range.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,12 +28,12 @@ class GitDiffRange : public ObjectWrap { GitDiffRange(git_diff_range *raw); ~GitDiffRange(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(OldStart); - static NAN_METHOD(OldLines); - static NAN_METHOD(NewStart); - static NAN_METHOD(NewLines); + static Handle OldStart(const Arguments& args); + static Handle OldLines(const Arguments& args); + static Handle NewStart(const Arguments& args); + static Handle NewLines(const Arguments& args); git_diff_range *raw; }; diff --git a/include/index.h b/include/index.h index 4edafefec..e634d7ea0 100755 --- a/include/index.h +++ b/include/index.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,9 +28,10 @@ class GitIndex : public ObjectWrap { GitIndex(git_index *raw); ~GitIndex(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + - static NAN_METHOD(Open); + static Handle Open(const Arguments& args); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -45,7 +44,7 @@ class GitIndex : public ObjectWrap { const char * index_path; Persistent callback; }; - static NAN_METHOD(Read); + static Handle Read(const Arguments& args); static void ReadWork(uv_work_t* req); static void ReadAfterWork(uv_work_t* req); @@ -57,7 +56,7 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - static NAN_METHOD(Write); + static Handle Write(const Arguments& args); static void WriteWork(uv_work_t* req); static void WriteAfterWork(uv_work_t* req); @@ -69,7 +68,7 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - static NAN_METHOD(ReadTree); + static Handle ReadTree(const Arguments& args); static void ReadTreeWork(uv_work_t* req); static void ReadTreeAfterWork(uv_work_t* req); @@ -83,7 +82,7 @@ class GitIndex : public ObjectWrap { const git_tree * tree; Persistent callback; }; - static NAN_METHOD(WriteTree); + static Handle WriteTree(const Arguments& args); static void WriteTreeWork(uv_work_t* req); static void WriteTreeAfterWork(uv_work_t* req); @@ -96,12 +95,12 @@ class GitIndex : public ObjectWrap { git_index * index; Persistent callback; }; - 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 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 void AddBypathWork(uv_work_t* req); static void AddBypathAfterWork(uv_work_t* req); @@ -115,12 +114,12 @@ class GitIndex : public ObjectWrap { const char * path; Persistent callback; }; - 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 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 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 8e3ea5072..7bf5fc6a8 100644 --- a/include/index_entry.h +++ b/include/index_entry.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,21 +28,21 @@ class GitIndexEntry : public ObjectWrap { GitIndexEntry(git_index_entry *raw); ~GitIndexEntry(); - 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); - + static Handle New(const Arguments& args); + + static Handle Ctime(const Arguments& args); + static Handle Mtime(const Arguments& args); + static Handle Dev(const Arguments& args); + static Handle Ino(const Arguments& args); + static Handle Mode(const Arguments& args); + static Handle Uid(const Arguments& args); + static Handle gid(const Arguments& args); + static Handle FileSize(const Arguments& args); + static Handle Oid(const Arguments& args); + static Handle Flags(const Arguments& args); + static Handle FlagsExtended(const Arguments& args); + static Handle Path(const Arguments& args); + git_index_entry *raw; }; diff --git a/include/index_time.h b/include/index_time.h index ad8dc49a5..765ce6cc7 100644 --- a/include/index_time.h +++ b/include/index_time.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,10 +28,11 @@ class GitIndexTime : public ObjectWrap { GitIndexTime(git_index_time *raw); ~GitIndexTime(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + + static Handle Seconds(const Arguments& args); + static Handle Nanoseconds(const Arguments& args); - static NAN_METHOD(Seconds); - static NAN_METHOD(Nanoseconds); git_index_time *raw; }; diff --git a/include/object.h b/include/object.h index e4188ed83..6ab9d3537 100644 --- a/include/object.h +++ b/include/object.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,12 +28,12 @@ class GitObject : public ObjectWrap { GitObject(git_object *raw); ~GitObject(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - 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 5dbde3946..6ed9913d9 100644 --- a/include/odb.h +++ b/include/odb.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,13 +28,13 @@ class GitOdb : public ObjectWrap { GitOdb(git_odb *raw); ~GitOdb(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - 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); @@ -51,11 +49,11 @@ class GitOdb : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(ReadPrefix); - static NAN_METHOD(ReadHeader); - static NAN_METHOD(Exists); - static NAN_METHOD(Refresh); - static NAN_METHOD(Write); + 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 void WriteWork(uv_work_t* req); static void WriteAfterWork(uv_work_t* req); @@ -74,8 +72,8 @@ class GitOdb : public ObjectWrap { git_otype type; Persistent callback; }; - static NAN_METHOD(Hash); - static NAN_METHOD(Hashfile); + static Handle Hash(const Arguments& args); + static Handle Hashfile(const Arguments& args); git_odb *raw; }; diff --git a/include/odb_object.h b/include/odb_object.h index 54325a1fe..7938dfa49 100644 --- a/include/odb_object.h +++ b/include/odb_object.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,12 +28,13 @@ class GitOdbObject : public ObjectWrap { GitOdbObject(git_odb_object *raw); ~GitOdbObject(); - static NAN_METHOD(New); - - static NAN_METHOD(Data); - static NAN_METHOD(Size); - static NAN_METHOD(Type); - static NAN_METHOD(Oid); + 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); git_odb_object *raw; }; diff --git a/include/oid.h b/include/oid.h index 789b560ea..2ce3a9e5c 100755 --- a/include/oid.h +++ b/include/oid.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,11 +28,11 @@ class GitOid : public ObjectWrap { GitOid(git_oid *raw); ~GitOid(); - static NAN_METHOD(New); - - static NAN_METHOD(FromString); - static NAN_METHOD(Sha); - + static Handle New(const Arguments& args); + + + static Handle FromString(const Arguments& args); + static Handle Sha(const Arguments& args); git_oid *raw; }; diff --git a/include/patch.h b/include/patch.h index e5f445b41..7a4d408ff 100644 --- a/include/patch.h +++ b/include/patch.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,15 +28,16 @@ class GitPatch : public ObjectWrap { GitPatch(git_diff_patch *raw); ~GitPatch(); - static NAN_METHOD(New); + static Handle New(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); + 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); git_diff_patch *raw; }; diff --git a/include/refdb.h b/include/refdb.h index c5914e84f..51355028f 100644 --- a/include/refdb.h +++ b/include/refdb.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,7 +28,8 @@ class GitRefDb : public ObjectWrap { GitRefDb(git_refdb *raw); ~GitRefDb(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + git_refdb *raw; }; diff --git a/include/reference.h b/include/reference.h index 7aef82a2c..ae7d18ad4 100644 --- a/include/reference.h +++ b/include/reference.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,10 +28,10 @@ class GitReference : public ObjectWrap { GitReference(git_reference *raw); ~GitReference(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(OidForName); + static Handle OidForName(const Arguments& args); static void OidForNameWork(uv_work_t* req); static void OidForNameAfterWork(uv_work_t* req); @@ -48,12 +46,11 @@ class GitReference : public ObjectWrap { const char * name; Persistent callback; }; - static NAN_METHOD(Target); - static NAN_METHOD(SymbolicTarget); - static NAN_METHOD(Type); - static NAN_METHOD(Name); - static NAN_METHOD(Resolve); - + 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 void ResolveWork(uv_work_t* req); static void ResolveAfterWork(uv_work_t* req); @@ -66,11 +63,9 @@ class GitReference : public ObjectWrap { const git_reference * ref; Persistent callback; }; - - static NAN_METHOD(SetSymbolicTarget); - static NAN_METHOD(setTarget); - static NAN_METHOD(Rename); - + static Handle SetSymbolicTarget(const Arguments& args); + static Handle setTarget(const Arguments& args); + static Handle Rename(const Arguments& args); static void RenameWork(uv_work_t* req); static void RenameAfterWork(uv_work_t* req); @@ -87,8 +82,7 @@ class GitReference : public ObjectWrap { int force; Persistent callback; }; - static NAN_METHOD(Delete); - + static Handle Delete(const Arguments& args); static void DeleteWork(uv_work_t* req); static void DeleteAfterWork(uv_work_t* req); @@ -100,11 +94,10 @@ class GitReference : public ObjectWrap { git_reference * ref; Persistent callback; }; - static NAN_METHOD(IsBranch); - static NAN_METHOD(IsRemote); - static NAN_METHOD(Peel); - static NAN_METHOD(IsValidName); - + static Handle IsBranch(const Arguments& args); + static Handle IsRemote(const Arguments& args); + static Handle Peel(const Arguments& args); + static Handle IsValidName(const Arguments& args); git_reference *raw; }; diff --git a/include/remote.h b/include/remote.h index bf782f620..81fd1ac68 100644 --- a/include/remote.h +++ b/include/remote.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,14 +28,15 @@ class GitRemote : public ObjectWrap { GitRemote(git_remote *raw); ~GitRemote(); - static NAN_METHOD(New); + static Handle New(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 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 void ConnectWork(uv_work_t* req); static void ConnectAfterWork(uv_work_t* req); @@ -51,7 +50,7 @@ class GitRemote : public ObjectWrap { git_direction direction; Persistent callback; }; - static NAN_METHOD(Download); + static Handle Download(const Arguments& args); static void DownloadWork(uv_work_t* req); static void DownloadAfterWork(uv_work_t* req); @@ -67,9 +66,9 @@ class GitRemote : public ObjectWrap { void * payload; Persistent callback; }; - static NAN_METHOD(Connected); - static NAN_METHOD(Stop); - static NAN_METHOD(Disconnect); + static Handle Connected(const Arguments& args); + static Handle Stop(const Arguments& args); + static Handle Disconnect(const Arguments& args); static void DisconnectWork(uv_work_t* req); static void DisconnectAfterWork(uv_work_t* req); @@ -81,13 +80,13 @@ class GitRemote : public ObjectWrap { git_remote * remote; Persistent callback; }; - 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); + 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); git_remote *raw; }; diff --git a/include/repo.h b/include/repo.h index a5ad14adf..8f10f3427 100755 --- a/include/repo.h +++ b/include/repo.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,10 +28,10 @@ class GitRepo : public ObjectWrap { GitRepo(git_repository *raw); ~GitRepo(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - static NAN_METHOD(Open); + static Handle Open(const Arguments& args); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -46,7 +44,7 @@ class GitRepo : public ObjectWrap { const char * path; Persistent callback; }; - static NAN_METHOD(Init); + static Handle Init(const Arguments& args); static void InitWork(uv_work_t* req); static void InitAfterWork(uv_work_t* req); @@ -61,10 +59,10 @@ class GitRepo : public ObjectWrap { unsigned is_bare; Persistent callback; }; - static NAN_METHOD(Path); - static NAN_METHOD(Workdir); - static NAN_METHOD(Odb); - static NAN_METHOD(openIndex); + 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 void openIndexWork(uv_work_t* req); static void openIndexAfterWork(uv_work_t* req); @@ -77,7 +75,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static NAN_METHOD(GetBlob); + static Handle GetBlob(const Arguments& args); static void GetBlobWork(uv_work_t* req); static void GetBlobAfterWork(uv_work_t* req); @@ -92,7 +90,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(GetCommit); + static Handle GetCommit(const Arguments& args); static void GetCommitWork(uv_work_t* req); static void GetCommitAfterWork(uv_work_t* req); @@ -107,7 +105,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(CreateCommit); + static Handle CreateCommit(const Arguments& args); static void CreateCommitWork(uv_work_t* req); static void CreateCommitAfterWork(uv_work_t* req); @@ -136,7 +134,7 @@ class GitRepo : public ObjectWrap { const git_commit ** parents; Persistent callback; }; - static NAN_METHOD(GetObject); + static Handle GetObject(const Arguments& args); static void GetObjectWork(uv_work_t* req); static void GetObjectAfterWork(uv_work_t* req); @@ -153,7 +151,7 @@ class GitRepo : public ObjectWrap { git_otype type; Persistent callback; }; - static NAN_METHOD(GetReference); + static Handle GetReference(const Arguments& args); static void GetReferenceWork(uv_work_t* req); static void GetReferenceAfterWork(uv_work_t* req); @@ -168,9 +166,9 @@ class GitRepo : public ObjectWrap { const char * name; Persistent callback; }; - static NAN_METHOD(CreateSymbolicReference); - static NAN_METHOD(CreateReference); - static NAN_METHOD(AddRemote); + static Handle CreateSymbolicReference(const Arguments& args); + static Handle CreateReference(const Arguments& args); + static Handle AddRemote(const Arguments& args); static void AddRemoteWork(uv_work_t* req); static void AddRemoteAfterWork(uv_work_t* req); @@ -187,10 +185,10 @@ class GitRepo : public ObjectWrap { const char * url; Persistent callback; }; - static NAN_METHOD(CreateRevWalk); - static NAN_METHOD(GetSubmodule); - static NAN_METHOD(AddSubmodule); - static NAN_METHOD(GetTag); + 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 void GetTagWork(uv_work_t* req); static void GetTagAfterWork(uv_work_t* req); @@ -205,7 +203,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(CreateTag); + static Handle CreateTag(const Arguments& args); static void CreateTagWork(uv_work_t* req); static void CreateTagAfterWork(uv_work_t* req); @@ -228,7 +226,7 @@ class GitRepo : public ObjectWrap { int force; Persistent callback; }; - static NAN_METHOD(CreateLightweightTag); + static Handle CreateLightweightTag(const Arguments& args); static void CreateLightweightTagWork(uv_work_t* req); static void CreateLightweightTagAfterWork(uv_work_t* req); @@ -247,7 +245,7 @@ class GitRepo : public ObjectWrap { int force; Persistent callback; }; - static NAN_METHOD(GetTree); + static Handle GetTree(const Arguments& args); static void GetTreeWork(uv_work_t* req); static void GetTreeAfterWork(uv_work_t* req); @@ -262,7 +260,7 @@ class GitRepo : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(ReloadSubmodules); + static Handle ReloadSubmodules(const Arguments& args); static void ReloadSubmodulesWork(uv_work_t* req); static void ReloadSubmodulesAfterWork(uv_work_t* req); @@ -274,7 +272,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static NAN_METHOD(Delete); + static Handle Delete(const Arguments& args); static void DeleteWork(uv_work_t* req); static void DeleteAfterWork(uv_work_t* req); @@ -288,7 +286,7 @@ class GitRepo : public ObjectWrap { const char * tag_name; Persistent callback; }; - static NAN_METHOD(GetReferences); + static Handle GetReferences(const Arguments& args); static void GetReferencesWork(uv_work_t* req); static void GetReferencesAfterWork(uv_work_t* req); @@ -303,7 +301,7 @@ class GitRepo : public ObjectWrap { unsigned int list_flags; Persistent callback; }; - static NAN_METHOD(CreateBlobFromBuffer); + static Handle CreateBlobFromBuffer(const Arguments& args); static void CreateBlobFromBufferWork(uv_work_t* req); static void CreateBlobFromBufferAfterWork(uv_work_t* req); @@ -320,7 +318,7 @@ class GitRepo : public ObjectWrap { size_t len; Persistent callback; }; - static NAN_METHOD(CreateBlobFromFile); + static Handle CreateBlobFromFile(const Arguments& args); static void CreateBlobFromFileWork(uv_work_t* req); static void CreateBlobFromFileAfterWork(uv_work_t* req); @@ -335,7 +333,7 @@ class GitRepo : public ObjectWrap { const char * path; Persistent callback; }; - static NAN_METHOD(GetRemotes); + static Handle GetRemotes(const Arguments& args); static void GetRemotesWork(uv_work_t* req); static void GetRemotesAfterWork(uv_work_t* req); @@ -348,7 +346,7 @@ class GitRepo : public ObjectWrap { git_repository * repo; Persistent callback; }; - static NAN_METHOD(Clone); + static Handle Clone(const Arguments& args); static void CloneWork(uv_work_t* req); static void CloneAfterWork(uv_work_t* req); @@ -365,7 +363,7 @@ class GitRepo : public ObjectWrap { const git_clone_options * options; Persistent callback; }; - static NAN_METHOD(GetRemote); + static Handle GetRemote(const Arguments& args); git_repository *raw; }; diff --git a/include/revwalk.h b/include/revwalk.h index d6e6e6712..c2096cc61 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,11 +28,11 @@ class GitRevWalk : public ObjectWrap { GitRevWalk(git_revwalk *raw); ~GitRevWalk(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - 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); @@ -48,7 +46,7 @@ class GitRevWalk : public ObjectWrap { const git_oid * id; Persistent callback; }; - static NAN_METHOD(PushGlob); + static Handle PushGlob(const Arguments& args); static void PushGlobWork(uv_work_t* req); static void PushGlobAfterWork(uv_work_t* req); @@ -62,7 +60,7 @@ class GitRevWalk : public ObjectWrap { const char * glob; Persistent callback; }; - static NAN_METHOD(PushHead); + static Handle PushHead(const Arguments& args); static void PushHeadWork(uv_work_t* req); static void PushHeadAfterWork(uv_work_t* req); @@ -74,7 +72,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static NAN_METHOD(Hide); + static Handle Hide(const Arguments& args); static void HideWork(uv_work_t* req); static void HideAfterWork(uv_work_t* req); @@ -88,7 +86,7 @@ class GitRevWalk : public ObjectWrap { const git_oid * commit_id; Persistent callback; }; - static NAN_METHOD(HideGlob); + static Handle HideGlob(const Arguments& args); static void HideGlobWork(uv_work_t* req); static void HideGlobAfterWork(uv_work_t* req); @@ -102,7 +100,7 @@ class GitRevWalk : public ObjectWrap { const char * glob; Persistent callback; }; - static NAN_METHOD(HideHead); + static Handle HideHead(const Arguments& args); static void HideHeadWork(uv_work_t* req); static void HideHeadAfterWork(uv_work_t* req); @@ -114,7 +112,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static NAN_METHOD(PushRef); + static Handle PushRef(const Arguments& args); static void PushRefWork(uv_work_t* req); static void PushRefAfterWork(uv_work_t* req); @@ -128,7 +126,7 @@ class GitRevWalk : public ObjectWrap { const char * refname; Persistent callback; }; - static NAN_METHOD(HideRef); + static Handle HideRef(const Arguments& args); static void HideRefWork(uv_work_t* req); static void HideRefAfterWork(uv_work_t* req); @@ -142,7 +140,7 @@ class GitRevWalk : public ObjectWrap { const char * refname; Persistent callback; }; - static NAN_METHOD(Next); + static Handle Next(const Arguments& args); static void NextWork(uv_work_t* req); static void NextAfterWork(uv_work_t* req); @@ -155,7 +153,7 @@ class GitRevWalk : public ObjectWrap { git_revwalk * walk; Persistent callback; }; - static NAN_METHOD(Sorting); + static Handle Sorting(const Arguments& args); git_revwalk *raw; }; diff --git a/include/signature.h b/include/signature.h index 65ca2b139..14d542c82 100755 --- a/include/signature.h +++ b/include/signature.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,24 +28,14 @@ class GitSignature : public ObjectWrap { GitSignature(git_signature *raw); ~GitSignature(); - 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 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 2895210b0..f80d8ee3d 100644 --- a/include/submodule.h +++ b/include/submodule.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,9 +28,10 @@ class GitSubmodule : public ObjectWrap { GitSubmodule(git_submodule *raw); ~GitSubmodule(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + - static NAN_METHOD(AddFinalize); + static Handle AddFinalize(const Arguments& args); static void AddFinalizeWork(uv_work_t* req); static void AddFinalizeAfterWork(uv_work_t* req); @@ -44,7 +43,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static NAN_METHOD(AddToIndex); + static Handle AddToIndex(const Arguments& args); static void AddToIndexWork(uv_work_t* req); static void AddToIndexAfterWork(uv_work_t* req); @@ -58,7 +57,7 @@ class GitSubmodule : public ObjectWrap { int write_index; Persistent callback; }; - static NAN_METHOD(Save); + static Handle Save(const Arguments& args); static void SaveWork(uv_work_t* req); static void SaveAfterWork(uv_work_t* req); @@ -70,13 +69,13 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - 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 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 void InitWork(uv_work_t* req); static void InitAfterWork(uv_work_t* req); @@ -90,7 +89,7 @@ class GitSubmodule : public ObjectWrap { int overwrite; Persistent callback; }; - static NAN_METHOD(Sync); + static Handle Sync(const Arguments& args); static void SyncWork(uv_work_t* req); static void SyncAfterWork(uv_work_t* req); @@ -102,7 +101,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static NAN_METHOD(Open); + static Handle Open(const Arguments& args); static void OpenWork(uv_work_t* req); static void OpenAfterWork(uv_work_t* req); @@ -115,7 +114,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static NAN_METHOD(Reload); + static Handle Reload(const Arguments& args); static void ReloadWork(uv_work_t* req); static void ReloadAfterWork(uv_work_t* req); @@ -127,7 +126,7 @@ class GitSubmodule : public ObjectWrap { git_submodule * submodule; Persistent callback; }; - static NAN_METHOD(Status); + static Handle Status(const Arguments& args); 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 eb1703fb4..f89ded8b1 100755 --- a/include/tag.h +++ b/include/tag.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,10 +28,11 @@ class GitTag : public ObjectWrap { GitTag(git_tag *raw); ~GitTag(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); + - static NAN_METHOD(Oid); - static NAN_METHOD(GetTarget); + static Handle Oid(const Arguments& args); + static Handle GetTarget(const Arguments& args); static void GetTargetWork(uv_work_t* req); static void GetTargetAfterWork(uv_work_t* req); @@ -46,12 +45,12 @@ class GitTag : public ObjectWrap { const git_tag * tag; Persistent callback; }; - static NAN_METHOD(TargetId); - static NAN_METHOD(TargetType); - static NAN_METHOD(Name); - static NAN_METHOD(Tagger); - static NAN_METHOD(Message); - static NAN_METHOD(Peel); + 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); git_tag *raw; }; diff --git a/include/threads.h b/include/threads.h index 4145ef0f7..7a67b0295 100755 --- a/include/threads.h +++ b/include/threads.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,15 +17,17 @@ 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 NAN_METHOD(Init); - static NAN_METHOD(Shutdown); + static Handle New(const Arguments& args); + + + static Handle Init(const Arguments& args); + static Handle Shutdown(const Arguments& args); }; #endif diff --git a/include/time.h b/include/time.h index 9d0dce8fd..b742a88b0 100644 --- a/include/time.h +++ b/include/time.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,15 +28,10 @@ class GitTime : public ObjectWrap { GitTime(git_time *raw); ~GitTime(); - static NAN_METHOD(New); - - static NAN_METHOD(Time); - static NAN_METHOD(Offset); - - // static Handle New(const Arguments& args); + 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 b77169fa5..5462a82b1 100755 --- a/include/tree.h +++ b/include/tree.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,15 +28,15 @@ class GitTree : public ObjectWrap { GitTree(git_tree *raw); ~GitTree(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - 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); @@ -53,8 +51,8 @@ class GitTree : public ObjectWrap { const char * path; Persistent callback; }; - static NAN_METHOD(Builder); - static NAN_METHOD(DiffTree); + static Handle Builder(const Arguments& args); + static Handle DiffTree(const Arguments& args); static void DiffTreeWork(uv_work_t* req); static void DiffTreeAfterWork(uv_work_t* req); @@ -73,7 +71,7 @@ class GitTree : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static NAN_METHOD(DiffIndex); + static Handle DiffIndex(const Arguments& args); static void DiffIndexWork(uv_work_t* req); static void DiffIndexAfterWork(uv_work_t* req); @@ -92,7 +90,7 @@ class GitTree : public ObjectWrap { const git_diff_options * opts; Persistent callback; }; - static NAN_METHOD(DiffWorkDir); + static Handle DiffWorkDir(const Arguments& args); 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 f840deeee..93d08a69f 100644 --- a/include/tree_builder.h +++ b/include/tree_builder.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,15 +28,16 @@ class GitTreeBuilder : public ObjectWrap { GitTreeBuilder(git_treebuilder *raw); ~GitTreeBuilder(); - static NAN_METHOD(New); + static Handle New(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 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 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 0db8e56bc..7c78ec1e9 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -9,8 +9,6 @@ #include #include -#include "nan.h" - #include "git2.h" using namespace node; @@ -19,7 +17,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(); @@ -30,14 +28,14 @@ class GitTreeEntry : public ObjectWrap { GitTreeEntry(git_tree_entry *raw); ~GitTreeEntry(); - static NAN_METHOD(New); + static Handle New(const Arguments& args); - 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/index.js b/index.js index 0f47b4177..53a54654a 100755 --- a/index.js +++ b/index.js @@ -16,9 +16,9 @@ try { } catch (e) { rawApi = require('./build/Debug/nodegit'); } -for (var key in rawApi) { - exports[key] = rawApi[key]; -} + +// Set the exports prototype to the raw API. +exports.__proto__ = rawApi; // Import extensions require('./lib/commit.js'); diff --git a/install.js b/install.js index 5434079fb..5c987f5fb 100644 --- a/install.js +++ b/install.js @@ -1,132 +1,193 @@ -var async = require('async'), - child_process = require('child_process'), - spawn = child_process.spawn, - path = require('path'), - request = require('request'), - zlib = require('zlib'), - fs = require('fs-extra'), - tar = require('tar'), - exec = require('child_process').exec; - -function passthru() { - var args = Array.prototype.slice.call(arguments); - var cb = args.splice(-1)[0]; - var cmd = args.splice(0, 1)[0]; - var opts = {}; - if(typeof(args.slice(-1)[0]) === 'object') { - opts = args.splice(-1)[0]; +// Core Node.js modules. +var os = require('os'); +var fs = require('fs'); +var path = require('path'); +var zlib = require('zlib'); +var exec = require('child_process').exec; + +// Third-party modules. +var Q = require('q'); +var request = require('request'); +var tar = require('tar'); +var which = require('which'); +var rimraf = require('rimraf'); + +// This will take in an object and find any matching keys in the environment +// to use as overrides. +// +// ENV variables: +// +// PKG: Location of `package.json` sans `.json`. +// LIBGIT2: Location of libgit2 source. +// BUILD: Location of nodegit build directory. +function envOverride(obj) { + // Look through all keys. + return Object.keys(obj).reduce(function(obj, key) { + var normalize = key.toUpperCase(); + + // Check for process environment existence. + if (normalize in process.env) { + obj[key] = process.env[normalize]; } - var child = spawn(cmd, args, opts); - child.stdout.pipe(process.stdout); - child.stderr.pipe(process.stderr); - child.on('exit', cb); + return obj; + }, obj); } -function shpassthru() { - var cmd = - passthru.apply(null, ['/bin/sh', '-c'].concat(Array.prototype.slice.call(arguments))); +// Convert to the correct system path. +function systemPath(parts) { + return parts.join(path.sep); } -function envpassthru() { - passthru.apply(null, ['/usr/bin/env'].concat(Array.prototype.slice.call(arguments))); -} +// Will be used near the end to configure `node-gyp`. +var python, cmake; + +// Common reusable paths that can be overwritten by environment variables. +var paths = envOverride({ + pkg: __dirname + '/package', + libgit2: __dirname + '/vendor/libgit2/', + build: __dirname + '/vendor/libgit2/build/', +}); + +// Load the package.json. +var pkg = require(paths.pkg); + +// Ensure all dependencies are available. +var dependencies = Q.allSettled([ + // This will prioritize `python2` over `python`, because we always want to + // work with Python 2.* if it's available. + Q.nfcall(which, 'python2'), + Q.nfcall(which, 'python'), + + // Check for any version of CMake. + Q.nfcall(which, 'cmake'), +]) + +// Determine if all the dependency requirements are met. +.then(function(results) { + console.info('[nodegit] Determining dependencies.'); -var updateSubmodules = function(mainCallback) { - console.log('[nodegit] Downloading libgit2 dependency.'); - async.series([ - function(callback) { - envpassthru('git', 'submodule', 'init', callback); - }, function(callback) { - envpassthru('git', 'submodule', 'update', callback); - } - ], function(error) { - if (error) process.exit(error); - mainCallback(); - }); -}; - -var checkoutDependencies = function(mainCallback) { - console.log('[nodegit] Downloading libgit2 dependency.'); - var commit = 'e953c1606d0d7aea680c9b19db0b955b34ae63c2'; - - var url = 'https://github.com/libgit2/libgit2/tarball/'+ commit; - var path = __dirname + '/vendor/libgit2/'; - request({ - url: url - }).pipe(zlib.createUnzip()).pipe(tar.Extract({ - path: path, - strip: true - })).on('end', function() { - mainCallback(); - }); -}; - -var libgit2BuildDirectory = path.join(__dirname, 'vendor/libgit2/build'); - -// The python executable to use when building libgit2 -var pythonExecutable = 'python'; - -async.series([ - function checkPython2Exists(callback) { - exec('which python2', - function (error) { - if (!error) { - pythonExecutable = 'python2'; - callback(); - return; - } - // python2 is not available, check for python - exec('which python', function(error) { - if (error) { - throw new Error('Python is required to build libgit2'); - } - callback(); - }); - }); - - }, - function prepareLibgit2Repository(callback) { - // Check for presence of .git folder - fs.exists(__dirname + '/.git', function(exists) { - if (exists) { - updateSubmodules(callback); - } else { - checkoutDependencies(callback); - } - }); - }, - function deleteExistingLibgit2BuildFolder(callback) { - // fs.exists(libgit2BuildDirectory, function(exists) { - // if (exists) { - // fs.remove(libgit2BuildDirectory, callback); - // } else { - callback(); - // } - // }); - }, - function createLibgit2BuildDirectory(callback) { - console.log('[nodegit] Building libgit2 dependency.'); - fs.mkdirs(libgit2BuildDirectory, callback); - }, - function configureLibgit2(callback) { - envpassthru('cmake', '-DTHREADSAFE=1', '-DBUILD_CLAR=0', '..', { - cwd: libgit2BuildDirectory - }, callback); - }, - function buildLibgit2(callback) { - envpassthru('cmake', '--build', '.', { - cwd: libgit2BuildDirectory - }, callback); - }, - function configureNodegit(callback) { - console.log('[nodegit] Building native module.'); - // shpassthru('node-gyp configure --python python2 --debug', callback); - shpassthru('node-gyp configure --python ' + pythonExecutable, callback); - }, - function buildNodegit(callback) { - shpassthru('node-gyp build', callback); + // Assign to reusable variables. + python = results[0].value || results[1].value; + cmake = results[2].value; + + // Missing Python. + if (!python) { + throw new Error('Python is required to build libgit2.'); + } + + // Missing CMake. + if (!cmake) { + throw new Error('CMake is required to build libgit2.'); + } + + // Now lets check the Python version to ensure it's < 3. + return Q.nfcall(exec, python + ' --version').then(function(version) { + if (version[1].indexOf('Python 3') === 0) { + throw new Error('Incorrect version of Python, gyp requires < 3.'); } -], function handleError(error) { - if(error) process.exit(error); + }); +}) + +// Successfully found all dependencies. First step is to clean the vendor +// directory. +.then(function() { + console.info('[nodegit] Removing vendor/libgit2.'); + + return Q.ninvoke(rimraf, null, paths.libgit2); +}) + +// Now fetch the libgit2 source from GitHub. +.then(function() { + console.info('[nodegit] Fetching vendor/libgit2.'); + + var url = 'https://github.com/libgit2/libgit2/tarball/' + pkg.libgit2; + + var extract = tar.Extract({ + path: paths.libgit2, + strip: true + }); + + // First extract from Zlib and then extract from Tar. + var expand = request.get(url).pipe(zlib.createUnzip()).pipe(extract); + + return Q.ninvoke(expand, 'on', 'end'); +}) + +// Fetch completed successfully. +.then(function() { + console.info('[nodegit] Creating vendor/libgit2/build.'); + + return Q.ninvoke(fs, 'mkdir', paths.build); +}) + +// Configure libgit2 using cmake. +.then(function() { + console.info('[nodegit] Configuring libgit2.'); + + // Minimum flags necessary to configure in sane environments. + var flags = ['-DTHREADSAFE=ON', '-DBUILD_CLAR=OFF']; + + // Windows flags. + if (process.platform.indexOf('win') > -1) { + flags.push.apply(flags, [ + '-DSTDCALL=OFF', + '-DBUILD_SHARED_LIBS=OFF', + '-DCMAKE_C_FLAGS=-fPIC', + '-DCMAKE_BUILD_TYPE=RelWithDebInfo' + ]); + + // If the architecture is 64bit, have to change the generator. + if (os.arch() === 'x64') { + flags.push('-G "Visual Studio 12 Win64"'); + } + } + + return Q.nfcall(exec, 'cmake .. ' + flags.join(' '), { + cwd: paths.build + }); +}) + +// Build libgit2 using cmake. +.then(function() { + console.info('[nodegit] Building libgit2.'); + + return Q.nfcall(exec, 'cmake --build .', { + cwd: paths.build + }); +}) + +// Configure the native module using node-gyp. +.then(function() { + console.info('[nodegit] Configuring native node module.'); + + return Q.nfcall(exec, systemPath([ + '.', 'node_modules', '.bin', 'node-gyp configure --python ' + python + ]), { + cwd: '.' + }); +}) + +// Build the native module using node-gyp. +.then(function() { + console.info('[nodegit] Building native node module.'); + + return Q.nfcall(exec, systemPath([ + '.', 'node_modules', '.bin', 'node-gyp build' + ]), { + cwd: '.', + maxBuffer: Number.MAX_VALUE + }); +}) + +// Display a success message. +.then(function() { + console.info('[nodegit] Completed installation successfully.'); +}) + +// Display a warning message about failing to build native node module. +.fail(function(message) { + console.info('[nodegit] Failed to build nodegit.'); + console.info(message.message); + console.info(message.stack); }); diff --git a/package.json b/package.json index cb043e981..94687fa4e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.1.1", + "version": "0.1.2", + "libgit2": "e953c1606d0d7aea680c9b19db0b955b34ae63c2", "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2", @@ -30,22 +31,25 @@ "node": ">= 0.8" }, "dependencies": { - "async": ">= 0.1.21", - "request": "2.9.x", - "node-gyp": "~0.8.2", - "tar": "0.1.17", + "request": "~2.25.0", + "node-gyp": "~0.13.0", + "tar": "~0.1.18", + "which": "~1.0.5", + "q": "~0.9.6", "fs-extra": "0.6.0", - "nan": "0.8.0" + "nan": "0.8.0", + "rimraf": "~2.2.6" }, "devDependencies": { - "nodeunit": "", - "rimraf": "1.0.x", - "ejs": "0.8.x", - "ncp": "~0.4.2" + "jshint": "~2.4.4", + "nodeunit": "~0.8.6", + "ejs": "~1.0.0", + "async": "~0.2.10" }, "scripts": { + "lint": "jshint src", "install": "node install.js", "test": "cd test && nodeunit nodegit.js", - "gen": "node gen.js" + "codegen": "node build/codegen/generate.js" } } diff --git a/src/blob.cc b/src/blob.cc index 25f82bafd..bc6068608 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -27,42 +27,40 @@ GitBlob::~GitBlob() { } void GitBlob::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Blob")); + tpl->SetClassName(String::NewSymbol("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); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Blob"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Blob"), constructor_template); } -NAN_METHOD(GitBlob::New) { - NanScope(); +Handle GitBlob::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_blob is required.")); + return ThrowException(Exception::Error(String::New("git_blob is required."))); } - GitBlob* object = new GitBlob((git_blob *) External::Cast(*args[0])->Value()); + GitBlob* object = new GitBlob((git_blob *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitBlob::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitBlob::constructor_template->NewInstance(1, argv)); } git_blob *GitBlob::GetValue() { @@ -73,8 +71,9 @@ git_blob *GitBlob::GetValue() { /** * @return {Oid} result */ -NAN_METHOD(GitBlob::Oid) { - NanScope(); +Handle GitBlob::Oid(const Arguments& args) { + HandleScope scope; + const git_oid * result = git_blob_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -89,14 +88,15 @@ NAN_METHOD(GitBlob::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Wrapper} result */ -NAN_METHOD(GitBlob::Content) { - NanScope(); +Handle GitBlob::Content(const Arguments& args) { + HandleScope scope; + const void * result = git_blob_rawcontent( ObjectWrap::Unwrap(args.This())->GetValue() @@ -108,14 +108,15 @@ NAN_METHOD(GitBlob::Content) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitBlob::Size) { - NanScope(); +Handle GitBlob::Size(const Arguments& args) { + HandleScope scope; + git_off_t result = git_blob_rawsize( ObjectWrap::Unwrap(args.This())->GetValue() @@ -123,14 +124,15 @@ NAN_METHOD(GitBlob::Size) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Boolean} result */ -NAN_METHOD(GitBlob::IsBinary) { - NanScope(); +Handle GitBlob::IsBinary(const Arguments& args) { + HandleScope scope; + int result = git_blob_is_binary( ObjectWrap::Unwrap(args.This())->GetValue() @@ -138,7 +140,7 @@ NAN_METHOD(GitBlob::IsBinary) { Handle to; to = Boolean::New(result); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitBlob::constructor_template; +Persistent GitBlob::constructor_template; diff --git a/src/branch.cc b/src/branch.cc index 13f8e0fb8..043afe60a 100644 --- a/src/branch.cc +++ b/src/branch.cc @@ -23,12 +23,12 @@ Branch::~Branch() { } void Branch::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Branch")); + tpl->SetClassName(String::NewSymbol("Branch")); NODE_SET_METHOD(tpl, "create", Create); NODE_SET_METHOD(tpl, "delete", Delete); @@ -42,8 +42,9 @@ void Branch::Initialize(Handle target) { NODE_SET_METHOD(tpl, "isHead", IsHead); NODE_SET_METHOD(tpl, "remoteName", RemoteName); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Branch"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Branch"), constructor_template); } Handle Branch::New(const Arguments& args) { @@ -101,7 +102,7 @@ Handle Branch::Create(const Arguments& args) { const git_commit * from_target; from_target = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); int from_force; - from_force = (int) args[3]->ToInt32()->Value(); + from_force = (int) args[3]->ToInt32()->Value(); int result = git_branch_create( &out @@ -178,7 +179,7 @@ Handle Branch::Foreach(const Arguments& args) { git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); unsigned int from_list_flags; - from_list_flags = (unsigned int) args[1]->ToUint32()->Value(); + from_list_flags = (unsigned int) args[1]->ToUint32()->Value(); git_branch_foreach_cb from_branch_cb; from_branch_cb = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); void * from_payload; @@ -226,7 +227,7 @@ Handle Branch::Move(const Arguments& args) { String::Utf8Value new_branch_name(args[1]->ToString()); from_new_branch_name = strdup(*new_branch_name); int from_force; - from_force = (int) args[2]->ToInt32()->Value(); + from_force = (int) args[2]->ToInt32()->Value(); int result = git_branch_move( &out @@ -429,7 +430,7 @@ Handle Branch::UpstreamName(const Arguments& args) { String::Utf8Value tracking_branch_name_out(args[0]->ToString()); from_tracking_branch_name_out = strdup(*tracking_branch_name_out); size_t from_buffer_size; - from_buffer_size = (size_t) args[1]->ToUint32()->Value(); + from_buffer_size = (size_t) args[1]->ToUint32()->Value(); git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); const char * from_canonical_branch_name; @@ -506,7 +507,7 @@ Handle Branch::RemoteName(const Arguments& args) { String::Utf8Value remote_name_out(args[0]->ToString()); from_remote_name_out = strdup(*remote_name_out); size_t from_buffer_size; - from_buffer_size = (size_t) args[1]->ToUint32()->Value(); + from_buffer_size = (size_t) args[1]->ToUint32()->Value(); git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); const char * from_canonical_branch_name; diff --git a/src/clone_options.cc b/src/clone_options.cc index b01c980a4..3f4b058c5 100644 --- a/src/clone_options.cc +++ b/src/clone_options.cc @@ -23,38 +23,36 @@ GitCloneOptions::~GitCloneOptions() { } void GitCloneOptions::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("CloneOptions")); + tpl->SetClassName(String::NewSymbol("CloneOptions")); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("CloneOptions"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("CloneOptions"), constructor_template); } -NAN_METHOD(GitCloneOptions::New) { - NanScope(); +Handle GitCloneOptions::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_clone_options is required.")); + return ThrowException(Exception::Error(String::New("git_clone_options is required."))); } - GitCloneOptions* object = new GitCloneOptions((git_clone_options *) External::Cast(*args[0])->Value()); + GitCloneOptions* object = new GitCloneOptions((git_clone_options *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitCloneOptions::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitCloneOptions::constructor_template->NewInstance(1, argv)); } git_clone_options *GitCloneOptions::GetValue() { @@ -62,4 +60,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 4f66a43fa..29a1a7877 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -27,12 +27,12 @@ GitCommit::~GitCommit() { } void GitCommit::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Commit")); + tpl->SetClassName(String::NewSymbol("Commit")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "messageEncoding", MessageEncoding); @@ -46,30 +46,28 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "parentId", ParentId); NODE_SET_PROTOTYPE_METHOD(tpl, "nthGenAncestor", NthGenAncestor); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Commit"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Commit"), constructor_template); } -NAN_METHOD(GitCommit::New) { - NanScope(); +Handle GitCommit::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_commit is required.")); + return ThrowException(Exception::Error(String::New("git_commit is required."))); } - GitCommit* object = new GitCommit((git_commit *) External::Cast(*args[0])->Value()); + GitCommit* object = new GitCommit((git_commit *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitCommit::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitCommit::constructor_template->NewInstance(1, argv)); } git_commit *GitCommit::GetValue() { @@ -80,8 +78,8 @@ git_commit *GitCommit::GetValue() { /** * @return {Oid} result */ -NAN_METHOD(GitCommit::Oid) { - NanScope(); +Handle GitCommit::Oid(const Arguments& args) { + HandleScope scope; const git_oid * result = git_commit_id( @@ -97,14 +95,14 @@ NAN_METHOD(GitCommit::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitCommit::MessageEncoding) { - NanScope(); +Handle GitCommit::MessageEncoding(const Arguments& args) { + HandleScope scope; const char * result = git_commit_message_encoding( @@ -113,14 +111,14 @@ NAN_METHOD(GitCommit::MessageEncoding) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitCommit::Message) { - NanScope(); +Handle GitCommit::Message(const Arguments& args) { + HandleScope scope; const char * result = git_commit_message( @@ -129,14 +127,14 @@ NAN_METHOD(GitCommit::Message) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitCommit::Time) { - NanScope(); +Handle GitCommit::Time(const Arguments& args) { + HandleScope scope; git_time_t result = git_commit_time( @@ -145,14 +143,15 @@ NAN_METHOD(GitCommit::Time) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitCommit::Offset) { - NanScope(); +Handle GitCommit::Offset(const Arguments& args) { + HandleScope scope; + int result = git_commit_time_offset( ObjectWrap::Unwrap(args.This())->GetValue() @@ -160,14 +159,14 @@ NAN_METHOD(GitCommit::Offset) { Handle to; to = Integer::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Signature} result */ -NAN_METHOD(GitCommit::Committer) { - NanScope(); +Handle GitCommit::Committer(const Arguments& args) { + HandleScope scope; const git_signature * result = git_commit_committer( @@ -183,14 +182,14 @@ NAN_METHOD(GitCommit::Committer) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Signature} result */ -NAN_METHOD(GitCommit::Author) { - NanScope(); +Handle GitCommit::Author(const Arguments& args) { + HandleScope scope; const git_signature * result = git_commit_author( @@ -206,14 +205,14 @@ NAN_METHOD(GitCommit::Author) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Oid} result */ -NAN_METHOD(GitCommit::TreeId) { - NanScope(); +Handle GitCommit::TreeId(const Arguments& args) { + HandleScope scope; const git_oid * result = git_commit_tree_id( @@ -229,14 +228,14 @@ NAN_METHOD(GitCommit::TreeId) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitCommit::ParentCount) { - NanScope(); +Handle GitCommit::ParentCount(const Arguments& args) { + HandleScope scope; unsigned int result = git_commit_parentcount( @@ -245,21 +244,21 @@ NAN_METHOD(GitCommit::ParentCount) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {Number} n * @return {Oid} result */ -NAN_METHOD(GitCommit::ParentId) { - NanScope(); +Handle GitCommit::ParentId(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number n is required.")); + return ThrowException(Exception::Error(String::New("Number n is required."))); } unsigned int from_n; - from_n = (unsigned int) args[0]->ToUint32()->Value(); + from_n = (unsigned int) args[0]->ToUint32()->Value(); const git_oid * result = git_commit_parent_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -275,22 +274,22 @@ NAN_METHOD(GitCommit::ParentId) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {Number} n * @return {Commit} ancestor */ -NAN_METHOD(GitCommit::NthGenAncestor) { - NanScope(); +Handle GitCommit::NthGenAncestor(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number n is required.")); + return ThrowException(Exception::Error(String::New("Number n is required."))); } git_commit * ancestor = 0; unsigned int from_n; - from_n = (unsigned int) args[0]->ToUint32()->Value(); + from_n = (unsigned int) args[0]->ToUint32()->Value(); int result = git_commit_nth_gen_ancestor( &ancestor @@ -299,19 +298,19 @@ NAN_METHOD(GitCommit::NthGenAncestor) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } Handle to; if (ancestor != NULL) { - to = GitCommit::New(ancestor); + to = GitCommit::New((void *)ancestor); } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitCommit::constructor_template; +Persistent GitCommit::constructor_template; diff --git a/src/delta.cc b/src/delta.cc index 1cb4e9d68..7b45d35f9 100644 --- a/src/delta.cc +++ b/src/delta.cc @@ -24,12 +24,13 @@ GitDelta::~GitDelta() { } void GitDelta::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Delta")); + tpl->SetClassName(String::NewSymbol("Delta")); + NODE_SET_PROTOTYPE_METHOD(tpl, "oldFile", OldFile); NODE_SET_PROTOTYPE_METHOD(tpl, "newFile", NewFile); @@ -37,38 +38,36 @@ void GitDelta::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "similarity", Similarity); NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Delta"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Delta"), constructor_template); } -NAN_METHOD(GitDelta::New) { - NanScope(); +Handle GitDelta::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_delta is required.")); + return ThrowException(Exception::Error(String::New("git_diff_delta is required."))); } - GitDelta* object = new GitDelta((git_diff_delta *) External::Cast(*args[0])->Value()); + GitDelta* object = new GitDelta((git_diff_delta *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitDelta::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDelta::constructor_template->NewInstance(1, argv)); } git_diff_delta *GitDelta::GetValue() { return this->raw; } -NAN_METHOD(GitDelta::OldFile) { - NanScope(); + +Handle GitDelta::OldFile(const Arguments& args) { + HandleScope scope; Handle to; git_diff_file *old_file = @@ -82,11 +81,11 @@ NAN_METHOD(GitDelta::OldFile) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDelta::NewFile) { - NanScope(); +Handle GitDelta::NewFile(const Arguments& args) { + HandleScope scope; Handle to; git_diff_file *new_file = @@ -100,40 +99,40 @@ NAN_METHOD(GitDelta::NewFile) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDelta::Status) { - NanScope(); +Handle GitDelta::Status(const Arguments& args) { + HandleScope scope; Handle to; git_delta_t status = ObjectWrap::Unwrap(args.This())->GetValue()->status; to = Integer::New(status); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDelta::Similarity) { - NanScope(); +Handle GitDelta::Similarity(const Arguments& args) { + HandleScope scope; Handle to; uint32_t similarity = ObjectWrap::Unwrap(args.This())->GetValue()->similarity; to = Integer::New(similarity); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDelta::Flags) { - NanScope(); +Handle GitDelta::Flags(const Arguments& args) { + HandleScope scope; Handle to; uint32_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitDelta::constructor_template; +Persistent GitDelta::constructor_template; diff --git a/src/diff_file.cc b/src/diff_file.cc index 6877b632d..c96d4c8be 100644 --- a/src/diff_file.cc +++ b/src/diff_file.cc @@ -24,12 +24,13 @@ GitDiffFile::~GitDiffFile() { } void GitDiffFile::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("DiffFile")); + tpl->SetClassName(String::NewSymbol("DiffFile")); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path); @@ -37,38 +38,36 @@ void GitDiffFile::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags); NODE_SET_PROTOTYPE_METHOD(tpl, "mode", Mode); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("DiffFile"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("DiffFile"), constructor_template); } -NAN_METHOD(GitDiffFile::New) { - NanScope(); +Handle GitDiffFile::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_file is required.")); + return ThrowException(Exception::Error(String::New("git_diff_file is required."))); } - GitDiffFile* object = new GitDiffFile((git_diff_file *) External::Cast(*args[0])->Value()); + GitDiffFile* object = new GitDiffFile((git_diff_file *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitDiffFile::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDiffFile::constructor_template->NewInstance(1, argv)); } git_diff_file *GitDiffFile::GetValue() { return this->raw; } -NAN_METHOD(GitDiffFile::Oid) { - NanScope(); + +Handle GitDiffFile::Oid(const Arguments& args) { + HandleScope scope; Handle to; git_oid *oid = @@ -82,51 +81,51 @@ NAN_METHOD(GitDiffFile::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffFile::Path) { - NanScope(); +Handle GitDiffFile::Path(const Arguments& args) { + HandleScope scope; Handle to; const char * path = ObjectWrap::Unwrap(args.This())->GetValue()->path; to = String::New(path); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffFile::Size) { - NanScope(); +Handle GitDiffFile::Size(const Arguments& args) { + HandleScope scope; Handle to; git_off_t size = ObjectWrap::Unwrap(args.This())->GetValue()->size; to = Integer::New(size); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffFile::Flags) { - NanScope(); +Handle GitDiffFile::Flags(const Arguments& args) { + HandleScope scope; Handle to; uint32_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffFile::Mode) { - NanScope(); +Handle GitDiffFile::Mode(const Arguments& args) { + HandleScope scope; Handle to; uint16_t mode = ObjectWrap::Unwrap(args.This())->GetValue()->mode; to = Integer::New(mode); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitDiffFile::constructor_template; +Persistent GitDiffFile::constructor_template; diff --git a/src/diff_find_options.cc b/src/diff_find_options.cc index c08151a6e..f6fd85756 100644 --- a/src/diff_find_options.cc +++ b/src/diff_find_options.cc @@ -23,39 +23,36 @@ GitDiffFindOptions::~GitDiffFindOptions() { } void GitDiffFindOptions::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("DiffFindOptions")); + tpl->SetClassName(String::NewSymbol("DiffFindOptions")); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("DiffFindOptions"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("DiffFindOptions"), constructor_template); } -NAN_METHOD(GitDiffFindOptions::New) { - NanScope(); +Handle GitDiffFindOptions::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_find_options is required.")); + return ThrowException(Exception::Error(String::New("git_diff_find_options is required."))); } - GitDiffFindOptions* object = new GitDiffFindOptions((git_diff_find_options *) External::Cast(*args[0])->Value()); + GitDiffFindOptions* object = new GitDiffFindOptions((git_diff_find_options *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } - Handle GitDiffFindOptions::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDiffFindOptions::constructor_template->NewInstance(1, argv)); } git_diff_find_options *GitDiffFindOptions::GetValue() { @@ -63,4 +60,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 d6239d813..fbd7e1398 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -30,12 +30,12 @@ GitDiffList::~GitDiffList() { } void GitDiffList::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("DiffList")); + tpl->SetClassName(String::NewSymbol("DiffList")); NODE_SET_PROTOTYPE_METHOD(tpl, "merge", Merge); NODE_SET_PROTOTYPE_METHOD(tpl, "findSimilar", FindSimilar); @@ -44,30 +44,27 @@ void GitDiffList::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "patch", Patch); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("DiffList"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("DiffList"), constructor_template); } -NAN_METHOD(GitDiffList::New) { - NanScope(); +Handle GitDiffList::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_list is required.")); + return ThrowException(Exception::Error(String::New("git_diff_list is required."))); } - GitDiffList* object = new GitDiffList((git_diff_list *) External::Cast(*args[0])->Value()); + GitDiffList* object = new GitDiffList((git_diff_list *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitDiffList::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDiffList::constructor_template->NewInstance(1, argv)); } git_diff_list *GitDiffList::GetValue() { @@ -78,10 +75,10 @@ git_diff_list *GitDiffList::GetValue() { /** * @param {DiffList} from */ -NAN_METHOD(GitDiffList::Merge) { - NanScope(); +Handle GitDiffList::Merge(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("DiffList from is required.")); + return ThrowException(Exception::Error(String::New("DiffList from is required."))); } const git_diff_list * from_from; @@ -93,22 +90,22 @@ NAN_METHOD(GitDiffList::Merge) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {DiffFindOptions} options */ -NAN_METHOD(GitDiffList::FindSimilar) { - NanScope(); +Handle GitDiffList::FindSimilar(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("DiffFindOptions options is required.")); + return ThrowException(Exception::Error(String::New("DiffFindOptions options is required."))); } git_diff_find_options * from_options; @@ -120,20 +117,20 @@ NAN_METHOD(GitDiffList::FindSimilar) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @return {Number} result */ -NAN_METHOD(GitDiffList::Size) { - NanScope(); +Handle GitDiffList::Size(const Arguments& args) { + HandleScope scope; size_t result = git_diff_num_deltas( @@ -142,7 +139,7 @@ NAN_METHOD(GitDiffList::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** @@ -150,19 +147,19 @@ NAN_METHOD(GitDiffList::Size) { * @param {Number} type * @return {Number} result */ -NAN_METHOD(GitDiffList::NumDeltasOfType) { - NanScope(); +Handle GitDiffList::NumDeltasOfType(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("DiffList diff is required.")); + return ThrowException(Exception::Error(String::New("DiffList diff is required."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); + return ThrowException(Exception::Error(String::New("Number type is required."))); } git_diff_list * from_diff; from_diff = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); git_delta_t from_type; - from_type = (git_delta_t) args[1]->ToInt32()->Value(); + from_type = (git_delta_t) args[1]->ToInt32()->Value(); size_t result = git_diff_num_deltas_of_type( from_diff @@ -171,7 +168,7 @@ NAN_METHOD(GitDiffList::NumDeltasOfType) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** @@ -179,16 +176,16 @@ NAN_METHOD(GitDiffList::NumDeltasOfType) { * @return {Patch} patch_out * @return {Delta} delta_out */ -NAN_METHOD(GitDiffList::Patch) { - NanScope(); +Handle GitDiffList::Patch(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number idx is required.")); + return ThrowException(Exception::Error(String::New("Number idx is required."))); } 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(); + from_idx = (size_t) args[0]->ToUint32()->Value(); int result = git_diff_get_patch( &patch_out @@ -198,9 +195,9 @@ NAN_METHOD(GitDiffList::Patch) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -223,7 +220,7 @@ NAN_METHOD(GitDiffList::Patch) { } toReturn->Set(String::NewSymbol("delta"), to); - NanReturnValue(toReturn); + return scope.Close(toReturn); } -Persistent GitDiffList::constructor_template; +Persistent GitDiffList::constructor_template; diff --git a/src/diff_options.cc b/src/diff_options.cc index 24407f98f..dad3fd108 100644 --- a/src/diff_options.cc +++ b/src/diff_options.cc @@ -23,38 +23,36 @@ GitDiffOptions::~GitDiffOptions() { } void GitDiffOptions::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("DiffOptions")); + tpl->SetClassName(String::NewSymbol("DiffOptions")); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("DiffOptions"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("DiffOptions"), constructor_template); } -NAN_METHOD(GitDiffOptions::New) { - NanScope(); +Handle GitDiffOptions::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_options is required.")); + return ThrowException(Exception::Error(String::New("git_diff_options is required."))); } - GitDiffOptions* object = new GitDiffOptions((git_diff_options *) External::Cast(*args[0])->Value()); + GitDiffOptions* object = new GitDiffOptions((git_diff_options *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitDiffOptions::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDiffOptions::constructor_template->NewInstance(1, argv)); } git_diff_options *GitDiffOptions::GetValue() { @@ -62,4 +60,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 e91cefef1..cacbd49b5 100644 --- a/src/diff_range.cc +++ b/src/diff_range.cc @@ -23,90 +23,89 @@ GitDiffRange::~GitDiffRange() { } void GitDiffRange::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("DiffRange")); + tpl->SetClassName(String::NewSymbol("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); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("DiffRange"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("DiffRange"), constructor_template); } -NAN_METHOD(GitDiffRange::New) { - NanScope(); +Handle GitDiffRange::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_range is required.")); + return ThrowException(Exception::Error(String::New("git_diff_range is required."))); } - GitDiffRange* object = new GitDiffRange((git_diff_range *) External::Cast(*args[0])->Value()); + GitDiffRange* object = new GitDiffRange((git_diff_range *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitDiffRange::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitDiffRange::constructor_template->NewInstance(1, argv)); } git_diff_range *GitDiffRange::GetValue() { return this->raw; } -NAN_METHOD(GitDiffRange::OldStart) { - NanScope(); + +Handle GitDiffRange::OldStart(const Arguments& args) { + HandleScope scope; Handle to; int old_start = ObjectWrap::Unwrap(args.This())->GetValue()->old_start; to = Integer::New(old_start); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffRange::OldLines) { - NanScope(); +Handle GitDiffRange::OldLines(const Arguments& args) { + HandleScope scope; Handle to; int old_lines = ObjectWrap::Unwrap(args.This())->GetValue()->old_lines; to = Integer::New(old_lines); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffRange::NewStart) { - NanScope(); +Handle GitDiffRange::NewStart(const Arguments& args) { + HandleScope scope; Handle to; int new_start = ObjectWrap::Unwrap(args.This())->GetValue()->new_start; to = Integer::New(new_start); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitDiffRange::NewLines) { - NanScope(); +Handle GitDiffRange::NewLines(const Arguments& args) { + HandleScope scope; Handle to; int new_lines = ObjectWrap::Unwrap(args.This())->GetValue()->new_lines; to = Integer::New(new_lines); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitDiffRange::constructor_template; +Persistent GitDiffRange::constructor_template; diff --git a/src/index.cc b/src/index.cc index 205afbc82..adeaf91be 100644 --- a/src/index.cc +++ b/src/index.cc @@ -29,12 +29,12 @@ GitIndex::~GitIndex() { } void GitIndex::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Index")); + tpl->SetClassName(String::NewSymbol("Index")); NODE_SET_METHOD(tpl, "open", Open); NODE_SET_PROTOTYPE_METHOD(tpl, "read", Read); @@ -54,30 +54,28 @@ void GitIndex::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "hasConflicts", HasConflicts); NODE_SET_METHOD(tpl, "indexToWorkdir", IndexToWorkdir); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Index"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Index"), constructor_template); } -NAN_METHOD(GitIndex::New) { - NanScope(); +Handle GitIndex::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_index is required.")); + return ThrowException(Exception::Error(String::New("git_index is required."))); } - GitIndex* object = new GitIndex((git_index *) External::Cast(*args[0])->Value()); + GitIndex* object = new GitIndex((git_index *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitIndex::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitIndex::constructor_template->NewInstance(1, argv)); } git_index *GitIndex::GetValue() { @@ -91,30 +89,30 @@ git_index *GitIndex::GetValue() { * @param {String} index_path * @param {Index} callback */ -NAN_METHOD(GitIndex::Open) { - NanScope(); +Handle GitIndex::Open(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String index_path is required.")); + return ThrowException(Exception::Error(String::New("String index_path is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::OpenWork(uv_work_t *req) { @@ -130,7 +128,7 @@ void GitIndex::OpenWork(uv_work_t *req) { } void GitIndex::OpenAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -143,21 +141,21 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -174,24 +172,24 @@ void GitIndex::OpenAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitIndex::Read) { - NanScope(); +Handle GitIndex::Read(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->indexReference, args.This()); + baton->indexReference = Persistent::New(args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReadWork, (uv_after_work_cb)ReadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::ReadWork(uv_work_t *req) { @@ -206,28 +204,28 @@ void GitIndex::ReadWork(uv_work_t *req) { } void GitIndex::ReadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ReadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -243,24 +241,24 @@ void GitIndex::ReadAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitIndex::Write) { - NanScope(); +Handle GitIndex::Write(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->indexReference, args.This()); + baton->indexReference = Persistent::New(args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::WriteWork(uv_work_t *req) { @@ -275,28 +273,28 @@ void GitIndex::WriteWork(uv_work_t *req) { } void GitIndex::WriteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; WriteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -313,31 +311,31 @@ void GitIndex::WriteAfterWork(uv_work_t *req) { /** * @param {Tree} tree */ -NAN_METHOD(GitIndex::ReadTree) { - NanScope(); +Handle GitIndex::ReadTree(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Tree tree is required.")); + return ThrowException(Exception::Error(String::New("Tree tree is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->indexReference, args.This()); + baton->indexReference = Persistent::New(args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, ReadTreeWork, (uv_after_work_cb)ReadTreeAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::ReadTreeWork(uv_work_t *req) { @@ -353,30 +351,30 @@ void GitIndex::ReadTreeWork(uv_work_t *req) { } void GitIndex::ReadTreeAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ReadTreeBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -392,11 +390,11 @@ void GitIndex::ReadTreeAfterWork(uv_work_t *req) { /** * @param {Oid} callback */ -NAN_METHOD(GitIndex::WriteTree) { - NanScope(); +Handle GitIndex::WriteTree(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } WriteTreeBaton* baton = new WriteTreeBaton; @@ -404,13 +402,13 @@ NAN_METHOD(GitIndex::WriteTree) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->indexReference, args.This()); + baton->indexReference = Persistent::New(args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, WriteTreeWork, (uv_after_work_cb)WriteTreeAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::WriteTreeWork(uv_work_t *req) { @@ -426,7 +424,7 @@ void GitIndex::WriteTreeWork(uv_work_t *req) { } void GitIndex::WriteTreeAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; WriteTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -439,24 +437,24 @@ void GitIndex::WriteTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - free(baton->out); - } + free(baton->out); + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -469,8 +467,8 @@ void GitIndex::WriteTreeAfterWork(uv_work_t *req) { /** * @return {Number} result */ -NAN_METHOD(GitIndex::Size) { - NanScope(); +Handle GitIndex::Size(const Arguments& args) { + HandleScope scope; size_t result = git_index_entrycount( @@ -479,34 +477,34 @@ NAN_METHOD(GitIndex::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** */ -NAN_METHOD(GitIndex::Clear) { - NanScope(); +Handle GitIndex::Clear(const Arguments& args) { + HandleScope scope; git_index_clear( ObjectWrap::Unwrap(args.This())->GetValue() ); - NanReturnUndefined(); + return Undefined(); } /** * @param {Number} n * @return {IndexEntry} result */ -NAN_METHOD(GitIndex::Entry) { - NanScope(); +Handle GitIndex::Entry(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number n is required.")); + return ThrowException(Exception::Error(String::New("Number n is required."))); } size_t from_n; - from_n = (size_t) args[0]->ToUint32()->Value(); + from_n = (size_t) args[0]->ToUint32()->Value(); const git_index_entry * result = git_index_get_byindex( ObjectWrap::Unwrap(args.This())->GetValue() @@ -522,27 +520,27 @@ NAN_METHOD(GitIndex::Entry) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} path * @param {Number} stage */ -NAN_METHOD(GitIndex::Remove) { - NanScope(); +Handle GitIndex::Remove(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number stage is required.")); + return ThrowException(Exception::Error(String::New("Number stage is required."))); } const char * from_path; String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); int from_stage; - from_stage = (int) args[1]->ToInt32()->Value(); + from_stage = (int) args[1]->ToInt32()->Value(); int result = git_index_remove( ObjectWrap::Unwrap(args.This())->GetValue() @@ -552,33 +550,33 @@ NAN_METHOD(GitIndex::Remove) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {String} dir * @param {Number} stage */ -NAN_METHOD(GitIndex::RemoveDirectory) { - NanScope(); +Handle GitIndex::RemoveDirectory(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String dir is required.")); + return ThrowException(Exception::Error(String::New("String dir is required."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number stage is required.")); + return ThrowException(Exception::Error(String::New("Number stage is required."))); } const char * from_dir; String::Utf8Value dir(args[0]->ToString()); from_dir = strdup(*dir); int from_stage; - from_stage = (int) args[1]->ToInt32()->Value(); + from_stage = (int) args[1]->ToInt32()->Value(); int result = git_index_remove_directory( ObjectWrap::Unwrap(args.This())->GetValue() @@ -588,13 +586,13 @@ NAN_METHOD(GitIndex::RemoveDirectory) { free((void *)from_dir); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -602,32 +600,32 @@ NAN_METHOD(GitIndex::RemoveDirectory) { /** * @param {String} path */ -NAN_METHOD(GitIndex::AddBypath) { - NanScope(); +Handle GitIndex::AddBypath(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->indexReference, args.This()); + baton->indexReference = Persistent::New(args.This()); baton->index = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, AddBypathWork, (uv_after_work_cb)AddBypathAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::AddBypathWork(uv_work_t *req) { @@ -643,28 +641,28 @@ void GitIndex::AddBypathWork(uv_work_t *req) { } void GitIndex::AddBypathAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; AddBypathBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -681,10 +679,10 @@ void GitIndex::AddBypathAfterWork(uv_work_t *req) { /** * @param {String} path */ -NAN_METHOD(GitIndex::RemoveBypath) { - NanScope(); +Handle GitIndex::RemoveBypath(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } const char * from_path; @@ -698,23 +696,23 @@ NAN_METHOD(GitIndex::RemoveBypath) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {String} path * @return {Number} at_pos */ -NAN_METHOD(GitIndex::Find) { - NanScope(); +Handle GitIndex::Find(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } size_t at_pos = 0; @@ -731,16 +729,16 @@ NAN_METHOD(GitIndex::Find) { Handle to; to = Uint32::New(at_pos); - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} path */ -NAN_METHOD(GitIndex::ConflictRemove) { - NanScope(); +Handle GitIndex::ConflictRemove(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } const char * from_path; @@ -754,33 +752,33 @@ NAN_METHOD(GitIndex::ConflictRemove) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitIndex::ConflictCleanup) { - NanScope(); +Handle GitIndex::ConflictCleanup(const Arguments& args) { + HandleScope scope; git_index_conflict_cleanup( ObjectWrap::Unwrap(args.This())->GetValue() ); - NanReturnUndefined(); + return Undefined(); } /** * @return {Number} result */ -NAN_METHOD(GitIndex::HasConflicts) { - NanScope(); +Handle GitIndex::HasConflicts(const Arguments& args) { + HandleScope scope; int result = git_index_has_conflicts( @@ -789,7 +787,7 @@ NAN_METHOD(GitIndex::HasConflicts) { Handle to; to = Int32::New(result); - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -800,45 +798,45 @@ NAN_METHOD(GitIndex::HasConflicts) { * @param {DiffOptions} opts * @param {DiffList} callback */ -NAN_METHOD(GitIndex::IndexToWorkdir) { - NanScope(); +Handle GitIndex::IndexToWorkdir(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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])); + baton->repoReference = Persistent::New(args[0]); + git_repository * from_repo; + from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->repo = from_repo; + baton->indexReference = Persistent::New(args[1]); + git_index * from_index; + if (args[1]->IsObject()) { + from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_index = 0; + } + baton->index = from_index; + baton->optsReference = Persistent::New(args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, IndexToWorkdirWork, (uv_after_work_cb)IndexToWorkdirAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitIndex::IndexToWorkdirWork(uv_work_t *req) { @@ -856,7 +854,7 @@ void GitIndex::IndexToWorkdirWork(uv_work_t *req) { } void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; IndexToWorkdirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -869,21 +867,21 @@ void GitIndex::IndexToWorkdirAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -897,4 +895,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 7ce9f583b..933ffafda 100644 --- a/src/index_entry.cc +++ b/src/index_entry.cc @@ -25,12 +25,13 @@ GitIndexEntry::~GitIndexEntry() { } void GitIndexEntry::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("IndexEntry")); + tpl->SetClassName(String::NewSymbol("IndexEntry")); + NODE_SET_PROTOTYPE_METHOD(tpl, "ctime", Ctime); NODE_SET_PROTOTYPE_METHOD(tpl, "mtime", Mtime); @@ -45,38 +46,36 @@ void GitIndexEntry::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "flags_extended", FlagsExtended); NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("IndexEntry"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("IndexEntry"), constructor_template); } -NAN_METHOD(GitIndexEntry::New) { - NanScope(); +Handle GitIndexEntry::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_index_entry is required.")); + return ThrowException(Exception::Error(String::New("git_index_entry is required."))); } - GitIndexEntry* object = new GitIndexEntry((git_index_entry *) External::Cast(*args[0])->Value()); + GitIndexEntry* object = new GitIndexEntry((git_index_entry *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitIndexEntry::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitIndexEntry::constructor_template->NewInstance(1, argv)); } git_index_entry *GitIndexEntry::GetValue() { return this->raw; } -NAN_METHOD(GitIndexEntry::Ctime) { - NanScope(); + +Handle GitIndexEntry::Ctime(const Arguments& args) { + HandleScope scope; Handle to; git_index_time *ctime = @@ -90,11 +89,11 @@ NAN_METHOD(GitIndexEntry::Ctime) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Mtime) { - NanScope(); +Handle GitIndexEntry::Mtime(const Arguments& args) { + HandleScope scope; Handle to; git_index_time *mtime = @@ -108,77 +107,77 @@ NAN_METHOD(GitIndexEntry::Mtime) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Dev) { - NanScope(); +Handle GitIndexEntry::Dev(const Arguments& args) { + HandleScope scope; Handle to; unsigned int dev = ObjectWrap::Unwrap(args.This())->GetValue()->dev; to = Uint32::New(dev); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Ino) { - NanScope(); +Handle GitIndexEntry::Ino(const Arguments& args) { + HandleScope scope; Handle to; unsigned int ino = ObjectWrap::Unwrap(args.This())->GetValue()->ino; to = Uint32::New(ino); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Mode) { - NanScope(); +Handle GitIndexEntry::Mode(const Arguments& args) { + HandleScope scope; Handle to; uint16_t mode = ObjectWrap::Unwrap(args.This())->GetValue()->mode; to = Integer::New(mode); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Uid) { - NanScope(); +Handle GitIndexEntry::Uid(const Arguments& args) { + HandleScope scope; Handle to; unsigned int uid = ObjectWrap::Unwrap(args.This())->GetValue()->uid; to = Uint32::New(uid); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::gid) { - NanScope(); +Handle GitIndexEntry::gid(const Arguments& args) { + HandleScope scope; Handle to; unsigned int gid = ObjectWrap::Unwrap(args.This())->GetValue()->gid; to = Uint32::New(gid); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::FileSize) { - NanScope(); +Handle GitIndexEntry::FileSize(const Arguments& args) { + HandleScope scope; Handle to; unsigned int file_size = ObjectWrap::Unwrap(args.This())->GetValue()->file_size; to = Uint32::New(file_size); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Oid) { - NanScope(); +Handle GitIndexEntry::Oid(const Arguments& args) { + HandleScope scope; Handle to; git_oid *oid = @@ -192,40 +191,40 @@ NAN_METHOD(GitIndexEntry::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Flags) { - NanScope(); +Handle GitIndexEntry::Flags(const Arguments& args) { + HandleScope scope; Handle to; uint16_t flags = ObjectWrap::Unwrap(args.This())->GetValue()->flags; to = Integer::New(flags); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::FlagsExtended) { - NanScope(); +Handle GitIndexEntry::FlagsExtended(const Arguments& args) { + HandleScope scope; Handle to; uint16_t flags_extended = ObjectWrap::Unwrap(args.This())->GetValue()->flags_extended; to = Integer::New(flags_extended); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexEntry::Path) { - NanScope(); +Handle GitIndexEntry::Path(const Arguments& args) { + HandleScope scope; Handle to; char * path = ObjectWrap::Unwrap(args.This())->GetValue()->path; to = String::New(path); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitIndexEntry::constructor_template; +Persistent GitIndexEntry::constructor_template; diff --git a/src/index_time.cc b/src/index_time.cc index d44ac3ede..5501bd61a 100644 --- a/src/index_time.cc +++ b/src/index_time.cc @@ -23,66 +23,65 @@ GitIndexTime::~GitIndexTime() { } void GitIndexTime::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("IndexTime")); + tpl->SetClassName(String::NewSymbol("IndexTime")); + NODE_SET_PROTOTYPE_METHOD(tpl, "seconds", Seconds); NODE_SET_PROTOTYPE_METHOD(tpl, "nanoseconds", Nanoseconds); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("IndexTime"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("IndexTime"), constructor_template); } -NAN_METHOD(GitIndexTime::New) { - NanScope(); +Handle GitIndexTime::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_index_time is required.")); + return ThrowException(Exception::Error(String::New("git_index_time is required."))); } - GitIndexTime* object = new GitIndexTime((git_index_time *) External::Cast(*args[0])->Value()); + GitIndexTime* object = new GitIndexTime((git_index_time *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitIndexTime::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitIndexTime::constructor_template->NewInstance(1, argv)); } git_index_time *GitIndexTime::GetValue() { return this->raw; } -NAN_METHOD(GitIndexTime::Seconds) { - NanScope(); + +Handle GitIndexTime::Seconds(const Arguments& args) { + HandleScope scope; Handle to; git_time_t seconds = ObjectWrap::Unwrap(args.This())->GetValue()->seconds; to = Uint32::New(seconds); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitIndexTime::Nanoseconds) { - NanScope(); +Handle GitIndexTime::Nanoseconds(const Arguments& args) { + HandleScope scope; Handle to; unsigned int nanoseconds = ObjectWrap::Unwrap(args.This())->GetValue()->nanoseconds; to = Uint32::New(nanoseconds); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitIndexTime::constructor_template; +Persistent GitIndexTime::constructor_template; diff --git a/src/object.cc b/src/object.cc index d9991c310..be1895226 100644 --- a/src/object.cc +++ b/src/object.cc @@ -25,41 +25,39 @@ GitObject::~GitObject() { } void GitObject::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Object")); + tpl->SetClassName(String::NewSymbol("Object")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Object"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Object"), constructor_template); } -NAN_METHOD(GitObject::New) { - NanScope(); +Handle GitObject::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_object is required.")); + return ThrowException(Exception::Error(String::New("git_object is required."))); } - GitObject* object = new GitObject((git_object *) External::Cast(*args[0])->Value()); + GitObject* object = new GitObject((git_object *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitObject::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitObject::constructor_template->NewInstance(1, argv)); } git_object *GitObject::GetValue() { @@ -70,8 +68,8 @@ git_object *GitObject::GetValue() { /** * @return {Oid} result */ -NAN_METHOD(GitObject::Oid) { - NanScope(); +Handle GitObject::Oid(const Arguments& args) { + HandleScope scope; const git_oid * result = git_object_id( @@ -87,14 +85,14 @@ NAN_METHOD(GitObject::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitObject::Type) { - NanScope(); +Handle GitObject::Type(const Arguments& args) { + HandleScope scope; git_otype result = git_object_type( @@ -103,7 +101,7 @@ NAN_METHOD(GitObject::Type) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -112,31 +110,31 @@ NAN_METHOD(GitObject::Type) { * @param {Number} target_type * @param {Object} callback */ -NAN_METHOD(GitObject::Peel) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number target_type is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->objectReference, args.This()); + baton->objectReference = Persistent::New(args.This()); baton->object = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, PeelWork, (uv_after_work_cb)PeelAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitObject::PeelWork(uv_work_t *req) { @@ -153,7 +151,7 @@ void GitObject::PeelWork(uv_work_t *req) { } void GitObject::PeelAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; PeelBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -166,23 +164,23 @@ void GitObject::PeelAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal< Value >(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -193,4 +191,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 d820b6d27..0ed9b605f 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -26,12 +26,12 @@ GitOdb::~GitOdb() { } void GitOdb::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Odb")); + tpl->SetClassName(String::NewSymbol("Odb")); NODE_SET_METHOD(tpl, "create()", Create); NODE_SET_METHOD(tpl, "open", Open); @@ -45,30 +45,28 @@ void GitOdb::Initialize(Handle target) { NODE_SET_METHOD(tpl, "hash", Hash); NODE_SET_METHOD(tpl, "hashfile", Hashfile); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Odb"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Odb"), constructor_template); } -NAN_METHOD(GitOdb::New) { - NanScope(); +Handle GitOdb::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_odb is required.")); + return ThrowException(Exception::Error(String::New("git_odb is required."))); } - GitOdb* object = new GitOdb((git_odb *) External::Cast(*args[0])->Value()); + GitOdb* object = new GitOdb((git_odb *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitOdb::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitOdb::constructor_template->NewInstance(1, argv)); } git_odb *GitOdb::GetValue() { @@ -79,8 +77,8 @@ git_odb *GitOdb::GetValue() { /** * @return {Odb} out */ -NAN_METHOD(GitOdb::Create) { - NanScope(); +Handle GitOdb::Create(const Arguments& args) { + HandleScope scope; git_odb * out = 0; @@ -89,9 +87,9 @@ NAN_METHOD(GitOdb::Create) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -101,17 +99,17 @@ NAN_METHOD(GitOdb::Create) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} objects_dir * @return {Odb} out */ -NAN_METHOD(GitOdb::Open) { - NanScope(); +Handle GitOdb::Open(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String objects_dir is required.")); + return ThrowException(Exception::Error(String::New("String objects_dir is required."))); } git_odb * out = 0; @@ -126,9 +124,9 @@ NAN_METHOD(GitOdb::Open) { free((void *)from_objects_dir); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -138,16 +136,16 @@ NAN_METHOD(GitOdb::Open) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} path */ -NAN_METHOD(GitOdb::AddDiskAlternate) { - NanScope(); +Handle GitOdb::AddDiskAlternate(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } const char * from_path; @@ -161,13 +159,13 @@ NAN_METHOD(GitOdb::AddDiskAlternate) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -176,31 +174,31 @@ NAN_METHOD(GitOdb::AddDiskAlternate) { * @param {Oid} id * @param {OdbObject} callback */ -NAN_METHOD(GitOdb::Read) { - NanScope(); +Handle GitOdb::Read(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->dbReference, args.This()); + baton->dbReference = Persistent::New(args.This()); baton->db = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, ReadWork, (uv_after_work_cb)ReadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitOdb::ReadWork(uv_work_t *req) { @@ -217,7 +215,7 @@ void GitOdb::ReadWork(uv_work_t *req) { } void GitOdb::ReadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ReadBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -230,21 +228,21 @@ void GitOdb::ReadAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -263,16 +261,16 @@ void GitOdb::ReadAfterWork(uv_work_t *req) { * @param {Number} len * @return {OdbObject} out */ -NAN_METHOD(GitOdb::ReadPrefix) { - NanScope(); +Handle GitOdb::ReadPrefix(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Odb db is required.")); + return ThrowException(Exception::Error(String::New("Odb db is required."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Oid short_id is required.")); + return ThrowException(Exception::Error(String::New("Oid short_id is required."))); } if (args.Length() == 2 || !args[2]->IsUint32()) { - return NanThrowError(String::New("Number len is required.")); + return ThrowException(Exception::Error(String::New("Number len is required."))); } git_odb_object * out = 0; @@ -281,7 +279,7 @@ NAN_METHOD(GitOdb::ReadPrefix) { const git_oid * from_short_id; from_short_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); size_t from_len; - from_len = (size_t) args[2]->ToUint32()->Value(); + from_len = (size_t) args[2]->ToUint32()->Value(); int result = git_odb_read_prefix( &out @@ -291,9 +289,9 @@ NAN_METHOD(GitOdb::ReadPrefix) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -303,7 +301,7 @@ NAN_METHOD(GitOdb::ReadPrefix) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -312,13 +310,13 @@ NAN_METHOD(GitOdb::ReadPrefix) { * @return {Number} len_out * @return {Number} type_out */ -NAN_METHOD(GitOdb::ReadHeader) { - NanScope(); +Handle GitOdb::ReadHeader(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Odb db is required.")); + return ThrowException(Exception::Error(String::New("Odb db is required."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } size_t len_out = 0; @@ -336,9 +334,9 @@ NAN_METHOD(GitOdb::ReadHeader) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -350,16 +348,16 @@ NAN_METHOD(GitOdb::ReadHeader) { to = Int32::New(type_out); toReturn->Set(String::NewSymbol("type_out"), to); - NanReturnValue(toReturn); + return scope.Close(toReturn); } /** * @param {Oid} id */ -NAN_METHOD(GitOdb::Exists) { - NanScope(); +Handle GitOdb::Exists(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } const git_oid * from_id; @@ -371,19 +369,19 @@ NAN_METHOD(GitOdb::Exists) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitOdb::Refresh) { - NanScope(); +Handle GitOdb::Refresh(const Arguments& args) { + HandleScope scope; int result = git_odb_refresh( @@ -391,13 +389,13 @@ NAN_METHOD(GitOdb::Refresh) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -408,20 +406,20 @@ NAN_METHOD(GitOdb::Refresh) { * @param {Number} type * @param {Oid} callback */ -NAN_METHOD(GitOdb::Write) { - NanScope(); +Handle GitOdb::Write(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String data is required.")); + return ThrowException(Exception::Error(String::New("String data is required."))); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return NanThrowError(String::New("Number len is required.")); + return ThrowException(Exception::Error(String::New("Number len is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); + return ThrowException(Exception::Error(String::New("Number type is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } WriteBaton* baton = new WriteBaton; @@ -429,26 +427,26 @@ NAN_METHOD(GitOdb::Write) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->odbReference, args.This()); + baton->odbReference = Persistent::New(args.This()); baton->odb = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitOdb::WriteWork(uv_work_t *req) { @@ -467,7 +465,7 @@ void GitOdb::WriteWork(uv_work_t *req) { } void GitOdb::WriteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -480,21 +478,21 @@ void GitOdb::WriteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -517,25 +515,25 @@ void GitOdb::WriteAfterWork(uv_work_t *req) { * @param {Number} type * @return {Oid} out */ -NAN_METHOD(GitOdb::Hash) { - NanScope(); +Handle GitOdb::Hash(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Buffer data is required.")); + return ThrowException(Exception::Error(String::New("Buffer data is required."))); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return NanThrowError(String::New("Number len is required.")); + return ThrowException(Exception::Error(String::New("Number len is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); + return ThrowException(Exception::Error(String::New("Number type is required."))); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const void * from_data; from_data = Buffer::Data(args[0]->ToObject()); size_t from_len; - from_len = (size_t) args[1]->ToUint32()->Value(); + from_len = (size_t) args[1]->ToUint32()->Value(); git_otype from_type; - from_type = (git_otype) args[2]->ToInt32()->Value(); + from_type = (git_otype) args[2]->ToInt32()->Value(); int result = git_odb_hash( out @@ -546,9 +544,9 @@ NAN_METHOD(GitOdb::Hash) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -558,7 +556,7 @@ NAN_METHOD(GitOdb::Hash) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -566,13 +564,13 @@ NAN_METHOD(GitOdb::Hash) { * @param {Number} type * @return {Oid} out */ -NAN_METHOD(GitOdb::Hashfile) { - NanScope(); +Handle GitOdb::Hashfile(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); + return ThrowException(Exception::Error(String::New("Number type is required."))); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); @@ -580,7 +578,7 @@ NAN_METHOD(GitOdb::Hashfile) { String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); git_otype from_type; - from_type = (git_otype) args[1]->ToInt32()->Value(); + from_type = (git_otype) args[1]->ToInt32()->Value(); int result = git_odb_hashfile( out @@ -591,9 +589,9 @@ NAN_METHOD(GitOdb::Hashfile) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -603,7 +601,7 @@ NAN_METHOD(GitOdb::Hashfile) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitOdb::constructor_template; +Persistent GitOdb::constructor_template; diff --git a/src/odb_object.cc b/src/odb_object.cc index 7c8db710e..507d63736 100644 --- a/src/odb_object.cc +++ b/src/odb_object.cc @@ -25,42 +25,40 @@ GitOdbObject::~GitOdbObject() { } void GitOdbObject::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("OdbObject")); + tpl->SetClassName(String::NewSymbol("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); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("OdbObject"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("OdbObject"), constructor_template); } -NAN_METHOD(GitOdbObject::New) { - NanScope(); +Handle GitOdbObject::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_odb_object is required.")); + return ThrowException(Exception::Error(String::New("git_odb_object is required."))); } - GitOdbObject* object = new GitOdbObject((git_odb_object *) External::Cast(*args[0])->Value()); + GitOdbObject* object = new GitOdbObject((git_odb_object *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitOdbObject::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitOdbObject::constructor_template->NewInstance(1, argv)); } git_odb_object *GitOdbObject::GetValue() { @@ -71,8 +69,8 @@ git_odb_object *GitOdbObject::GetValue() { /** * @return {Wrapper} result */ -NAN_METHOD(GitOdbObject::Data) { - NanScope(); +Handle GitOdbObject::Data(const Arguments& args) { + HandleScope scope; const void * result = git_odb_object_data( @@ -85,14 +83,14 @@ NAN_METHOD(GitOdbObject::Data) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitOdbObject::Size) { - NanScope(); +Handle GitOdbObject::Size(const Arguments& args) { + HandleScope scope; size_t result = git_odb_object_size( @@ -101,14 +99,14 @@ NAN_METHOD(GitOdbObject::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitOdbObject::Type) { - NanScope(); +Handle GitOdbObject::Type(const Arguments& args) { + HandleScope scope; git_otype result = git_odb_object_type( @@ -117,14 +115,14 @@ NAN_METHOD(GitOdbObject::Type) { Handle to; to = Int32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Oid} result */ -NAN_METHOD(GitOdbObject::Oid) { - NanScope(); +Handle GitOdbObject::Oid(const Arguments& args) { + HandleScope scope; const git_oid * result = git_odb_object_id( @@ -140,7 +138,7 @@ NAN_METHOD(GitOdbObject::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitOdbObject::constructor_template; +Persistent GitOdbObject::constructor_template; diff --git a/src/oid.cc b/src/oid.cc index b00c1feb8..0f354998f 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -23,40 +23,38 @@ GitOid::~GitOid() { } void GitOid::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Oid")); + tpl->SetClassName(String::NewSymbol("Oid")); NODE_SET_METHOD(tpl, "fromString", FromString); NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Oid"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Oid"), constructor_template); } -NAN_METHOD(GitOid::New) { - NanScope(); +Handle GitOid::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_oid is required.")); + return ThrowException(Exception::Error(String::New("git_oid is required."))); } - GitOid* object = new GitOid((git_oid *) External::Cast(*args[0])->Value()); + GitOid* object = new GitOid((git_oid *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitOid::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitOid::constructor_template->NewInstance(1, argv)); } git_oid *GitOid::GetValue() { @@ -68,10 +66,10 @@ git_oid *GitOid::GetValue() { * @param {String} str * @return {Oid} out */ -NAN_METHOD(GitOid::FromString) { - NanScope(); +Handle GitOid::FromString(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String str is required.")); + return ThrowException(Exception::Error(String::New("String str is required."))); } git_oid *out = (git_oid *)malloc(sizeof(git_oid)); @@ -87,9 +85,9 @@ NAN_METHOD(GitOid::FromString) { if (result != GIT_OK) { free(out); if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -99,14 +97,14 @@ NAN_METHOD(GitOid::FromString) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitOid::Sha) { - NanScope(); +Handle GitOid::Sha(const Arguments& args) { + HandleScope scope; char * result = git_oid_allocfmt( @@ -116,7 +114,7 @@ NAN_METHOD(GitOid::Sha) { Handle to; to = String::New(result); free(result); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitOid::constructor_template; +Persistent GitOid::constructor_template; diff --git a/src/patch.cc b/src/patch.cc index 36ba451de..ce5e9d90f 100644 --- a/src/patch.cc +++ b/src/patch.cc @@ -25,12 +25,12 @@ GitPatch::~GitPatch() { } void GitPatch::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Patch")); + tpl->SetClassName(String::NewSymbol("Patch")); NODE_SET_PROTOTYPE_METHOD(tpl, "delta", Delta); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); @@ -40,30 +40,28 @@ void GitPatch::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "line", Line); NODE_SET_METHOD(tpl, "toString", ToString); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Patch"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Patch"), constructor_template); } -NAN_METHOD(GitPatch::New) { - NanScope(); +Handle GitPatch::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_diff_patch is required.")); + return ThrowException(Exception::Error(String::New("git_diff_patch is required."))); } - GitPatch* object = new GitPatch((git_diff_patch *) External::Cast(*args[0])->Value()); + GitPatch* object = new GitPatch((git_diff_patch *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitPatch::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitPatch::constructor_template->NewInstance(1, argv)); } git_diff_patch *GitPatch::GetValue() { @@ -74,8 +72,8 @@ git_diff_patch *GitPatch::GetValue() { /** * @return {Delta} result */ -NAN_METHOD(GitPatch::Delta) { - NanScope(); +Handle GitPatch::Delta(const Arguments& args) { + HandleScope scope; const git_diff_delta * result = git_diff_patch_delta( @@ -91,14 +89,14 @@ NAN_METHOD(GitPatch::Delta) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitPatch::Size) { - NanScope(); +Handle GitPatch::Size(const Arguments& args) { + HandleScope scope; size_t result = git_diff_patch_num_hunks( @@ -107,7 +105,7 @@ NAN_METHOD(GitPatch::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** @@ -115,8 +113,8 @@ NAN_METHOD(GitPatch::Size) { * @return {Number} total_additions * @return {Number} total_deletions */ -NAN_METHOD(GitPatch::Stats) { - NanScope(); +Handle GitPatch::Stats(const Arguments& args) { + HandleScope scope; size_t total_context = 0; size_t total_additions = 0; @@ -130,9 +128,9 @@ NAN_METHOD(GitPatch::Stats) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -147,7 +145,7 @@ NAN_METHOD(GitPatch::Stats) { to = Integer::New(total_deletions); toReturn->Set(String::NewSymbol("total_deletions"), to); - NanReturnValue(toReturn); + return scope.Close(toReturn); } /** @@ -157,10 +155,10 @@ NAN_METHOD(GitPatch::Stats) { * @return {Number} header_len * @return {Number} lines_in_hunk */ -NAN_METHOD(GitPatch::Hunk) { - NanScope(); +Handle GitPatch::Hunk(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number hunk_idx is required.")); + return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } const git_diff_range * range = 0; @@ -168,7 +166,7 @@ NAN_METHOD(GitPatch::Hunk) { 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(); + from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); int result = git_diff_patch_get_hunk( &range @@ -180,9 +178,9 @@ NAN_METHOD(GitPatch::Hunk) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -207,21 +205,21 @@ NAN_METHOD(GitPatch::Hunk) { to = Uint32::New(lines_in_hunk); toReturn->Set(String::NewSymbol("lines"), to); - NanReturnValue(toReturn); + return scope.Close(toReturn); } /** * @param {Number} hunk_idx * @return {Number} result */ -NAN_METHOD(GitPatch::Lines) { - NanScope(); +Handle GitPatch::Lines(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number hunk_idx is required.")); + return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } size_t from_hunk_idx; - from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); + from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); int result = git_diff_patch_num_lines_in_hunk( ObjectWrap::Unwrap(args.This())->GetValue() @@ -230,7 +228,7 @@ NAN_METHOD(GitPatch::Lines) { Handle to; to = Int32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** @@ -242,13 +240,13 @@ NAN_METHOD(GitPatch::Lines) { * @return {Number} old_lineno * @return {Number} new_lineno */ -NAN_METHOD(GitPatch::Line) { - NanScope(); +Handle GitPatch::Line(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number hunk_idx is required.")); + return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } if (args.Length() == 1 || !args[1]->IsUint32()) { - return NanThrowError(String::New("Number line_of_hunk is required.")); + return ThrowException(Exception::Error(String::New("Number line_of_hunk is required."))); } char line_origin = 0; @@ -257,9 +255,9 @@ NAN_METHOD(GitPatch::Line) { int old_lineno = 0; int new_lineno = 0; size_t from_hunk_idx; - from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); + from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); size_t from_line_of_hunk; - from_line_of_hunk = (size_t) args[1]->ToUint32()->Value(); + from_line_of_hunk = (size_t) args[1]->ToUint32()->Value(); int result = git_diff_patch_get_line_in_hunk( &line_origin @@ -273,9 +271,9 @@ NAN_METHOD(GitPatch::Line) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -296,14 +294,14 @@ NAN_METHOD(GitPatch::Line) { to = Int32::New(new_lineno); toReturn->Set(String::NewSymbol("newLineNumber"), to); - NanReturnValue(toReturn); + return scope.Close(toReturn); } /** * @return {String} string */ -NAN_METHOD(GitPatch::ToString) { - NanScope(); +Handle GitPatch::ToString(const Arguments& args) { + HandleScope scope; char * string = 0; @@ -313,16 +311,16 @@ NAN_METHOD(GitPatch::ToString) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } Handle to; to = String::New(string); free(string); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitPatch::constructor_template; +Persistent GitPatch::constructor_template; diff --git a/src/refdb.cc b/src/refdb.cc index 5f5074420..d1b344d76 100644 --- a/src/refdb.cc +++ b/src/refdb.cc @@ -23,38 +23,36 @@ GitRefDb::~GitRefDb() { } void GitRefDb::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("RefDb")); + tpl->SetClassName(String::NewSymbol("RefDb")); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("RefDb"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("RefDb"), constructor_template); } -NAN_METHOD(GitRefDb::New) { - NanScope(); +Handle GitRefDb::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_refdb is required.")); + return ThrowException(Exception::Error(String::New("git_refdb is required."))); } - GitRefDb* object = new GitRefDb((git_refdb *) External::Cast(*args[0])->Value()); + GitRefDb* object = new GitRefDb((git_refdb *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitRefDb::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitRefDb::constructor_template->NewInstance(1, argv)); } git_refdb *GitRefDb::GetValue() { @@ -62,4 +60,4 @@ git_refdb *GitRefDb::GetValue() { } -Persistent GitRefDb::constructor_template; +Persistent GitRefDb::constructor_template; diff --git a/src/reference.cc b/src/reference.cc index 4f1957410..53a666230 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -26,12 +26,12 @@ GitReference::~GitReference() { } void GitReference::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Reference")); + tpl->SetClassName(String::NewSymbol("Reference")); NODE_SET_METHOD(tpl, "oidForName", OidForName); NODE_SET_PROTOTYPE_METHOD(tpl, "target", Target); @@ -48,30 +48,28 @@ void GitReference::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); NODE_SET_METHOD(tpl, "isValidName", IsValidName); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Reference"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Reference"), constructor_template); } -NAN_METHOD(GitReference::New) { - NanScope(); +Handle GitReference::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_reference is required.")); + return ThrowException(Exception::Error(String::New("git_reference is required."))); } - GitReference* object = new GitReference((git_reference *) External::Cast(*args[0])->Value()); + GitReference* object = new GitReference((git_reference *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitReference::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitReference::constructor_template->NewInstance(1, argv)); } git_reference *GitReference::GetValue() { @@ -86,18 +84,17 @@ git_reference *GitReference::GetValue() { * @param {String} name * @param {Oid} callback */ -NAN_METHOD(GitReference::OidForName) { - NanScope(); - - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String name is required.")); + return ThrowException(Exception::Error(String::New("String name is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } OidForNameBaton* baton = new OidForNameBaton; @@ -105,21 +102,20 @@ NAN_METHOD(GitReference::OidForName) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, OidForNameWork, (uv_after_work_cb)OidForNameAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitReference::OidForNameWork(uv_work_t *req) { @@ -136,7 +132,7 @@ void GitReference::OidForNameWork(uv_work_t *req) { } void GitReference::OidForNameAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; OidForNameBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -149,25 +145,24 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -182,9 +177,9 @@ void GitReference::OidForNameAfterWork(uv_work_t *req) { /** * @return {Oid} result */ -NAN_METHOD(GitReference::Target) { - NanScope(); - +Handle GitReference::Target(const Arguments& args) { + HandleScope scope; + const git_oid * result = git_reference_target( ObjectWrap::Unwrap(args.This())->GetValue() @@ -199,14 +194,14 @@ NAN_METHOD(GitReference::Target) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitReference::SymbolicTarget) { - NanScope(); +Handle GitReference::SymbolicTarget(const Arguments& args) { + HandleScope scope; const char * result = git_reference_symbolic_target( @@ -215,15 +210,15 @@ NAN_METHOD(GitReference::SymbolicTarget) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitReference::Type) { - NanScope(); - +Handle GitReference::Type(const Arguments& args) { + HandleScope scope; + git_ref_t result = git_reference_type( ObjectWrap::Unwrap(args.This())->GetValue() @@ -231,15 +226,15 @@ NAN_METHOD(GitReference::Type) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitReference::Name) { - NanScope(); - +Handle GitReference::Name(const Arguments& args) { + HandleScope scope; + const char * result = git_reference_name( ObjectWrap::Unwrap(args.This())->GetValue() @@ -247,7 +242,7 @@ NAN_METHOD(GitReference::Name) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -255,25 +250,24 @@ NAN_METHOD(GitReference::Name) { /** * @param {Reference} callback */ -NAN_METHOD(GitReference::Resolve) { - NanScope(); - +Handle GitReference::Resolve(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->refReference, args.This()); + baton->refReference = Persistent::New(args.This()); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ResolveWork, (uv_after_work_cb)ResolveAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitReference::ResolveWork(uv_work_t *req) { @@ -289,7 +283,7 @@ void GitReference::ResolveWork(uv_work_t *req) { } void GitReference::ResolveAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ResolveBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -302,23 +296,23 @@ void GitReference::ResolveAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -332,10 +326,10 @@ void GitReference::ResolveAfterWork(uv_work_t *req) { * @param {String} target * @return {Reference} out */ -NAN_METHOD(GitReference::SetSymbolicTarget) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String target is required.")); +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."))); } git_reference * out = 0; @@ -351,9 +345,9 @@ NAN_METHOD(GitReference::SetSymbolicTarget) { free((void *)from_target); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -363,17 +357,17 @@ NAN_METHOD(GitReference::SetSymbolicTarget) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {Oid} id * @return {Reference} out */ -NAN_METHOD(GitReference::setTarget) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } git_reference * out = 0; @@ -387,9 +381,9 @@ NAN_METHOD(GitReference::setTarget) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -399,7 +393,7 @@ NAN_METHOD(GitReference::setTarget) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -409,39 +403,39 @@ NAN_METHOD(GitReference::setTarget) { * @param {Number} force * @param {Reference} callback */ -NAN_METHOD(GitReference::Rename) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String new_name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number force is required.")); + return ThrowException(Exception::Error(String::New("Number force is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->refReference, args.This()); + baton->refReference = Persistent::New(args.This()); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, RenameWork, (uv_after_work_cb)RenameAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitReference::RenameWork(uv_work_t *req) { @@ -459,36 +453,36 @@ void GitReference::RenameWork(uv_work_t *req) { } void GitReference::RenameAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; 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] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -505,24 +499,24 @@ void GitReference::RenameAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitReference::Delete) { - NanScope(); +Handle GitReference::Delete(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->refReference, Local::Cast(args.This())); + baton->refReference = Persistent::New(args.This()); baton->ref = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, DeleteWork, (uv_after_work_cb)DeleteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitReference::DeleteWork(uv_work_t *req) { @@ -537,30 +531,30 @@ void GitReference::DeleteWork(uv_work_t *req) { } void GitReference::DeleteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DeleteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -572,27 +566,28 @@ void GitReference::DeleteAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitReference::IsBranch) { - NanScope(); +Handle GitReference::IsBranch(const Arguments& args) { + HandleScope scope; + int result = git_reference_is_branch( ObjectWrap::Unwrap(args.This())->GetValue() ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitReference::IsRemote) { - NanScope(); +Handle GitReference::IsRemote(const Arguments& args) { + HandleScope scope; int result = git_reference_is_remote( @@ -600,28 +595,28 @@ NAN_METHOD(GitReference::IsRemote) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {Number} type * @return {Object} out */ -NAN_METHOD(GitReference::Peel) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); +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."))); } git_object * out = 0; git_otype from_type; - from_type = (git_otype) args[0]->ToInt32()->Value(); + from_type = (git_otype) args[0]->ToInt32()->Value(); int result = git_reference_peel( &out @@ -630,9 +625,9 @@ NAN_METHOD(GitReference::Peel) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -642,16 +637,16 @@ NAN_METHOD(GitReference::Peel) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} refname */ -NAN_METHOD(GitReference::IsValidName) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String refname is required.")); +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."))); } const char * from_refname; @@ -664,13 +659,13 @@ NAN_METHOD(GitReference::IsValidName) { free((void *)from_refname); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } -Persistent GitReference::constructor_template; +Persistent GitReference::constructor_template; diff --git a/src/remote.cc b/src/remote.cc index 7945b9ee5..c0fd95a6b 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -24,12 +24,12 @@ GitRemote::~GitRemote() { } void GitRemote::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Remote")); + tpl->SetClassName(String::NewSymbol("Remote")); NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); NODE_SET_PROTOTYPE_METHOD(tpl, "url", Url); @@ -50,30 +50,27 @@ void GitRemote::Initialize(Handle target) { NODE_SET_METHOD(tpl, "isValidName", IsValidName); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Remote"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Remote"), constructor_template); } -NAN_METHOD(GitRemote::New) { - NanScope(); +Handle GitRemote::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_remote is required.")); + return ThrowException(Exception::Error(String::New("git_remote is required."))); } - GitRemote* object = new GitRemote((git_remote *) External::Cast(*args[0])->Value()); + GitRemote* object = new GitRemote((git_remote *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitRemote::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitRemote::constructor_template->NewInstance(1, argv)); } git_remote *GitRemote::GetValue() { @@ -84,8 +81,8 @@ git_remote *GitRemote::GetValue() { /** * @return {String} result */ -NAN_METHOD(GitRemote::Name) { - NanScope(); +Handle GitRemote::Name(const Arguments& args) { + HandleScope scope; const char * result = git_remote_name( @@ -94,14 +91,14 @@ NAN_METHOD(GitRemote::Name) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitRemote::Url) { - NanScope(); +Handle GitRemote::Url(const Arguments& args) { + HandleScope scope; const char * result = git_remote_url( @@ -110,14 +107,14 @@ NAN_METHOD(GitRemote::Url) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitRemote::PushUrl) { - NanScope(); +Handle GitRemote::PushUrl(const Arguments& args) { + HandleScope scope; const char * result = git_remote_pushurl( @@ -126,16 +123,16 @@ NAN_METHOD(GitRemote::PushUrl) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} url */ -NAN_METHOD(GitRemote::SetUrl) { - NanScope(); +Handle GitRemote::SetUrl(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } const char* from_url; @@ -149,22 +146,22 @@ NAN_METHOD(GitRemote::SetUrl) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {String} url */ -NAN_METHOD(GitRemote::SetPushUrl) { - NanScope(); +Handle GitRemote::SetPushUrl(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } const char* from_url; @@ -178,13 +175,13 @@ NAN_METHOD(GitRemote::SetPushUrl) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -192,31 +189,31 @@ NAN_METHOD(GitRemote::SetPushUrl) { /** * @param {Number} direction */ -NAN_METHOD(GitRemote::Connect) { - NanScope(); +Handle GitRemote::Connect(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsNumber()) { - return NanThrowError(String::New("Number direction is required.")); + return ThrowException(Exception::Error(String::New("Number direction is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->remoteReference, args.This()); + baton->remoteReference = Persistent::New(args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->directionReference = Persistent::New(args[0]); + git_direction from_direction; + from_direction = (git_direction) (int) args[0]->ToNumber()->Value(); + baton->direction = from_direction; + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, ConnectWork, (uv_after_work_cb)ConnectAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRemote::ConnectWork(uv_work_t *req) { @@ -232,28 +229,28 @@ void GitRemote::ConnectWork(uv_work_t *req) { } void GitRemote::ConnectAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ConnectBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -272,34 +269,33 @@ void GitRemote::ConnectAfterWork(uv_work_t *req) { * @param {Function} progress_cb * @param {void} payload */ -NAN_METHOD(GitRemote::Download) { - NanScope(); +Handle GitRemote::Download(const Arguments& args) { + HandleScope scope; if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->remoteReference, args.This()); + baton->remoteReference = Persistent::New(args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->progress_cbReference = Persistent::New(args[0]); + git_transfer_progress_callback from_progress_cb; + if (args[0]->IsFunction()) { + Persistent::New(Local::Cast(args[0])); + } else { + from_progress_cb = 0; + } + baton->progress_cb = from_progress_cb; + baton->payloadReference = Persistent::New(args[1]); + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, DownloadWork, (uv_after_work_cb)DownloadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRemote::DownloadWork(uv_work_t *req) { @@ -316,28 +312,28 @@ void GitRemote::DownloadWork(uv_work_t *req) { } void GitRemote::DownloadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DownloadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -353,8 +349,8 @@ void GitRemote::DownloadAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitRemote::Connected) { - NanScope(); +Handle GitRemote::Connected(const Arguments& args) { + HandleScope scope; int result = git_remote_connected( @@ -362,50 +358,50 @@ NAN_METHOD(GitRemote::Connected) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitRemote::Stop) { - NanScope(); +Handle GitRemote::Stop(const Arguments& args) { + HandleScope scope; git_remote_stop( ObjectWrap::Unwrap(args.This())->GetValue() ); - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" /** */ -NAN_METHOD(GitRemote::Disconnect) { - NanScope(); +Handle GitRemote::Disconnect(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->remoteReference, args.This()); + baton->remoteReference = Persistent::New(args.This()); baton->remote = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, DisconnectWork, (uv_after_work_cb)DisconnectAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRemote::DisconnectWork(uv_work_t *req) { @@ -416,28 +412,28 @@ void GitRemote::DisconnectWork(uv_work_t *req) { } void GitRemote::DisconnectAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DisconnectBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -451,8 +447,8 @@ void GitRemote::DisconnectAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitRemote::UpdateTips) { - NanScope(); +Handle GitRemote::UpdateTips(const Arguments& args) { + HandleScope scope; int result = git_remote_update_tips( @@ -460,22 +456,22 @@ NAN_METHOD(GitRemote::UpdateTips) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {String} url */ -NAN_METHOD(GitRemote::ValidUrl) { - NanScope(); +Handle GitRemote::ValidUrl(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } const char * from_url; @@ -488,22 +484,22 @@ NAN_METHOD(GitRemote::ValidUrl) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {String} url */ -NAN_METHOD(GitRemote::SupportedUrl) { - NanScope(); +Handle GitRemote::SupportedUrl(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } const char* from_url; @@ -516,39 +512,39 @@ NAN_METHOD(GitRemote::SupportedUrl) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {Number} check */ -NAN_METHOD(GitRemote::CheckCert) { - NanScope(); +Handle GitRemote::CheckCert(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number check is required.")); + return ThrowException(Exception::Error(String::New("Number check is required."))); } int from_check; - from_check = (int) args[0]->ToInt32()->Value(); + from_check = (int) args[0]->ToInt32()->Value(); git_remote_check_cert( ObjectWrap::Unwrap(args.This())->GetValue() , from_check ); - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitRemote::UpdateFetchhead) { - NanScope(); +Handle GitRemote::UpdateFetchhead(const Arguments& args) { + HandleScope scope; int result = git_remote_update_fetchhead( @@ -556,42 +552,42 @@ NAN_METHOD(GitRemote::UpdateFetchhead) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @param {Number} value */ -NAN_METHOD(GitRemote::SetUpdateFetchhead) { - NanScope(); +Handle GitRemote::SetUpdateFetchhead(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number value is required.")); + return ThrowException(Exception::Error(String::New("Number value is required."))); } int from_value; - from_value = (int) args[0]->ToInt32()->Value(); + from_value = (int) args[0]->ToInt32()->Value(); git_remote_set_update_fetchhead( ObjectWrap::Unwrap(args.This())->GetValue() , from_value ); - NanReturnUndefined(); + return Undefined(); } /** * @param {String} remote_name */ -NAN_METHOD(GitRemote::IsValidName) { - NanScope(); +Handle GitRemote::IsValidName(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String remote_name is required.")); + return ThrowException(Exception::Error(String::New("String remote_name is required."))); } const char * from_remote_name; @@ -604,13 +600,13 @@ NAN_METHOD(GitRemote::IsValidName) { free((void *)from_remote_name); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } -Persistent GitRemote::constructor_template; +Persistent GitRemote::constructor_template; diff --git a/src/repo.cc b/src/repo.cc index 279252df2..637479573 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -39,7 +39,7 @@ GitRepo::~GitRepo() { } void GitRepo::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); @@ -76,32 +76,28 @@ void GitRepo::Initialize(Handle target) { NODE_SET_METHOD(tpl, "clone", Clone); NODE_SET_PROTOTYPE_METHOD(tpl, "getRemote", GetRemote); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Repo"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Repo"), constructor_template); } -NAN_METHOD(GitRepo::New) { - NanScope(); +Handle GitRepo::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_repository is required.")); + return ThrowException(Exception::Error(String::New("git_repository is required."))); } - GitRepo* object = new GitRepo((git_repository *) External::Cast(*args[0])->Value()); + GitRepo* object = new GitRepo((git_repository *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitRepo::New(void *raw) { - NanScope(); - + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - - return scope.Close(instance); + return scope.Close(GitRepo::constructor_template->NewInstance(1, argv)); } git_repository *GitRepo::GetValue() { @@ -115,30 +111,30 @@ git_repository *GitRepo::GetValue() { * @param {String} path * @param {Repository} callback */ -NAN_METHOD(GitRepo::Open) { - NanScope(); +Handle GitRepo::Open(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::OpenWork(uv_work_t *req) { @@ -154,7 +150,7 @@ void GitRepo::OpenWork(uv_work_t *req) { } void GitRepo::OpenAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -167,23 +163,23 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -201,37 +197,37 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { * @param {Boolean} is_bare * @param {Repository} callback */ -NAN_METHOD(GitRepo::Init) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsBoolean()) { - return NanThrowError(String::New("Boolean is_bare is required.")); + return ThrowException(Exception::Error(String::New("Boolean is_bare is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, InitWork, (uv_after_work_cb)InitAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::InitWork(uv_work_t *req) { @@ -248,7 +244,7 @@ void GitRepo::InitWork(uv_work_t *req) { } void GitRepo::InitAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; InitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -261,23 +257,23 @@ void GitRepo::InitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -292,8 +288,8 @@ void GitRepo::InitAfterWork(uv_work_t *req) { /** * @return {String} result */ -NAN_METHOD(GitRepo::Path) { - NanScope(); +Handle GitRepo::Path(const Arguments& args) { + HandleScope scope; const char * result = git_repository_path( @@ -302,14 +298,14 @@ NAN_METHOD(GitRepo::Path) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitRepo::Workdir) { - NanScope(); +Handle GitRepo::Workdir(const Arguments& args) { + HandleScope scope; const char * result = git_repository_workdir( @@ -318,14 +314,14 @@ NAN_METHOD(GitRepo::Workdir) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Odb} out */ -NAN_METHOD(GitRepo::Odb) { - NanScope(); +Handle GitRepo::Odb(const Arguments& args) { + HandleScope scope; git_odb * out = 0; @@ -335,9 +331,9 @@ NAN_METHOD(GitRepo::Odb) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -347,7 +343,7 @@ NAN_METHOD(GitRepo::Odb) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -355,24 +351,24 @@ NAN_METHOD(GitRepo::Odb) { /** * @param {Index} callback */ -NAN_METHOD(GitRepo::openIndex) { - NanScope(); +Handle GitRepo::openIndex(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, openIndexWork, (uv_after_work_cb)openIndexAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::openIndexWork(uv_work_t *req) { @@ -388,7 +384,7 @@ void GitRepo::openIndexWork(uv_work_t *req) { } void GitRepo::openIndexAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; openIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -401,23 +397,23 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -433,31 +429,31 @@ void GitRepo::openIndexAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Blob} callback */ -NAN_METHOD(GitRepo::GetBlob) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetBlobWork, (uv_after_work_cb)GetBlobAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetBlobWork(uv_work_t *req) { @@ -474,7 +470,7 @@ void GitRepo::GetBlobWork(uv_work_t *req) { } void GitRepo::GetBlobAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetBlobBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -487,21 +483,21 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -520,31 +516,31 @@ void GitRepo::GetBlobAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Commit} callback */ -NAN_METHOD(GitRepo::GetCommit) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetCommitWork, (uv_after_work_cb)GetCommitAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetCommitWork(uv_work_t *req) { @@ -561,7 +557,7 @@ void GitRepo::GetCommitWork(uv_work_t *req) { } void GitRepo::GetCommitAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -574,23 +570,23 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -614,29 +610,29 @@ void GitRepo::GetCommitAfterWork(uv_work_t *req) { * @param {Array} parents * @param {Oid} callback */ -NAN_METHOD(GitRepo::CreateCommit) { - NanScope(); - if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Signature author is required.")); +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."))); } if (args.Length() == 2 || !args[2]->IsObject()) { - return NanThrowError(String::New("Signature committer is required.")); + return ThrowException(Exception::Error(String::New("Signature committer is required."))); } if (args.Length() == 4 || !args[4]->IsString()) { - return NanThrowError(String::New("String message is required.")); + return ThrowException(Exception::Error(String::New("String message is required."))); } if (args.Length() == 5 || !args[5]->IsObject()) { - return NanThrowError(String::New("Tree tree is required.")); + return ThrowException(Exception::Error(String::New("Tree tree is required."))); } if (args.Length() == 6 || !args[6]->IsInt32()) { - return NanThrowError(String::New("Number parent_count is required.")); + return ThrowException(Exception::Error(String::New("Number parent_count is required."))); } if (args.Length() == 7 || !args[7]->IsObject()) { - return NanThrowError(String::New("Array parents is required.")); + return ThrowException(Exception::Error(String::New("Array parents is required."))); } if (args.Length() == 8 || !args[8]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } CreateCommitBaton* baton = new CreateCommitBaton; @@ -644,60 +640,61 @@ NAN_METHOD(GitRepo::CreateCommit) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->update_refReference = Persistent::New(args[0]); + const char * from_update_ref; + if (args[0]->IsString()) { + String::Utf8Value update_ref(args[0]->ToString()); + from_update_ref = strdup(*update_ref); + } else { + from_update_ref = 0; + } + baton->update_ref = from_update_ref; + baton->authorReference = Persistent::New(args[1]); + const git_signature * from_author; + from_author = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->author = from_author; + baton->committerReference = Persistent::New(args[2]); + const git_signature * from_committer; + from_committer = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + baton->committer = from_committer; + baton->message_encodingReference = Persistent::New(args[3]); + const char * from_message_encoding; + if (args[3]->IsString()) { + String::Utf8Value message_encoding(args[3]->ToString()); + from_message_encoding = strdup(*message_encoding); + } else { + from_message_encoding = 0; + } + baton->message_encoding = from_message_encoding; + baton->messageReference = Persistent::New(args[4]); + const char * from_message; + String::Utf8Value message(args[4]->ToString()); + from_message = strdup(*message); + baton->message = from_message; + baton->treeReference = Persistent::New(args[5]); + const git_tree * from_tree; + from_tree = ObjectWrap::Unwrap(args[5]->ToObject())->GetValue(); + baton->tree = from_tree; + baton->parent_countReference = Persistent::New(args[6]); + int from_parent_count; + from_parent_count = (int) args[6]->ToInt32()->Value(); + baton->parent_count = from_parent_count; + baton->parentsReference = Persistent::New(args[7]); + const git_commit ** from_parents; + Array *tmp_parents = Array::Cast(*args[7]); + from_parents = (const git_commit **)malloc(tmp_parents->Length() * sizeof(const git_commit *)); + for (unsigned int i = 0; i < tmp_parents->Length(); i++) { + + from_parents[i] = ObjectWrap::Unwrap(tmp_parents->Get(Number::New(static_cast(i)))->ToObject())->GetValue(); + } + baton->parents = from_parents; + baton->callback = Persistent::New(Local::Cast(args[8])); uv_queue_work(uv_default_loop(), &baton->request, CreateCommitWork, (uv_after_work_cb)CreateCommitAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CreateCommitWork(uv_work_t *req) { @@ -721,7 +718,7 @@ void GitRepo::CreateCommitWork(uv_work_t *req) { } void GitRepo::CreateCommitAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CreateCommitBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -734,24 +731,24 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - free(baton->id); - } + free(baton->id); + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -780,39 +777,38 @@ void GitRepo::CreateCommitAfterWork(uv_work_t *req) { * @param {Number} type * @param {Object} callback */ -NAN_METHOD(GitRepo::GetObject) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsInt32()) { - return NanThrowError(String::New("Number type is required.")); + return ThrowException(Exception::Error(String::New("Number type is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetObjectWork, (uv_after_work_cb)GetObjectAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetObjectWork(uv_work_t *req) { @@ -830,7 +826,7 @@ void GitRepo::GetObjectWork(uv_work_t *req) { } void GitRepo::GetObjectAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -843,21 +839,21 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -877,32 +873,32 @@ void GitRepo::GetObjectAfterWork(uv_work_t *req) { * @param {String} name * @param {Reference} callback */ -NAN_METHOD(GitRepo::GetReference) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetReferenceWork, (uv_after_work_cb)GetReferenceAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetReferenceWork(uv_work_t *req) { @@ -919,7 +915,7 @@ void GitRepo::GetReferenceWork(uv_work_t *req) { } void GitRepo::GetReferenceAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetReferenceBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -932,21 +928,21 @@ void GitRepo::GetReferenceAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -966,16 +962,16 @@ void GitRepo::GetReferenceAfterWork(uv_work_t *req) { * @param {Number} force * @return {Reference} out */ -NAN_METHOD(GitRepo::CreateSymbolicReference) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String target is required.")); + return ThrowException(Exception::Error(String::New("String target is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number force is required.")); + return ThrowException(Exception::Error(String::New("Number force is required."))); } git_reference * out = 0; @@ -986,7 +982,7 @@ NAN_METHOD(GitRepo::CreateSymbolicReference) { String::Utf8Value target(args[1]->ToString()); from_target = strdup(*target); int from_force; - from_force = (int) args[2]->ToInt32()->Value(); + from_force = (int) args[2]->ToInt32()->Value(); int result = git_reference_symbolic_create( &out @@ -999,9 +995,9 @@ NAN_METHOD(GitRepo::CreateSymbolicReference) { free((void *)from_target); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -1011,7 +1007,7 @@ NAN_METHOD(GitRepo::CreateSymbolicReference) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -1020,16 +1016,16 @@ NAN_METHOD(GitRepo::CreateSymbolicReference) { * @param {Number} force * @return {Reference} out */ -NAN_METHOD(GitRepo::CreateReference) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number force is required.")); + return ThrowException(Exception::Error(String::New("Number force is required."))); } git_reference * out = 0; @@ -1039,7 +1035,7 @@ NAN_METHOD(GitRepo::CreateReference) { const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); int from_force; - from_force = (int) args[2]->ToInt32()->Value(); + from_force = (int) args[2]->ToInt32()->Value(); int result = git_reference_create( &out @@ -1051,9 +1047,9 @@ NAN_METHOD(GitRepo::CreateReference) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -1063,7 +1059,7 @@ NAN_METHOD(GitRepo::CreateReference) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -1073,40 +1069,40 @@ NAN_METHOD(GitRepo::CreateReference) { * @param {String} url * @param {Remote} callback */ -NAN_METHOD(GitRepo::AddRemote) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, AddRemoteWork, (uv_after_work_cb)AddRemoteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::AddRemoteWork(uv_work_t *req) { @@ -1124,7 +1120,7 @@ void GitRepo::AddRemoteWork(uv_work_t *req) { } void GitRepo::AddRemoteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; AddRemoteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1137,21 +1133,21 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1170,8 +1166,8 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { /** * @return {RevWalk} out */ -NAN_METHOD(GitRepo::CreateRevWalk) { - NanScope(); +Handle GitRepo::CreateRevWalk(const Arguments& args) { + HandleScope scope; git_revwalk * out = 0; @@ -1181,9 +1177,9 @@ NAN_METHOD(GitRepo::CreateRevWalk) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -1193,17 +1189,17 @@ NAN_METHOD(GitRepo::CreateRevWalk) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} name * @return {Submodule} submodule */ -NAN_METHOD(GitRepo::GetSubmodule) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } git_submodule * submodule = 0; @@ -1219,9 +1215,9 @@ NAN_METHOD(GitRepo::GetSubmodule) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -1231,7 +1227,7 @@ NAN_METHOD(GitRepo::GetSubmodule) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -1240,16 +1236,16 @@ NAN_METHOD(GitRepo::GetSubmodule) { * @param {Number} use_gitlink * @return {Submodule} submodule */ -NAN_METHOD(GitRepo::AddSubmodule) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number use_gitlink is required.")); + return ThrowException(Exception::Error(String::New("Number use_gitlink is required."))); } git_submodule * submodule = 0; @@ -1260,7 +1256,7 @@ NAN_METHOD(GitRepo::AddSubmodule) { String::Utf8Value path(args[1]->ToString()); from_path = strdup(*path); int from_use_gitlink; - from_use_gitlink = (int) args[2]->ToInt32()->Value(); + from_use_gitlink = (int) args[2]->ToInt32()->Value(); int result = git_submodule_add_setup( &submodule @@ -1273,9 +1269,9 @@ NAN_METHOD(GitRepo::AddSubmodule) { free((void *)from_path); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -1285,7 +1281,7 @@ NAN_METHOD(GitRepo::AddSubmodule) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -1294,31 +1290,31 @@ NAN_METHOD(GitRepo::AddSubmodule) { * @param {Oid} id * @param {Tag} callback */ -NAN_METHOD(GitRepo::GetTag) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetTagWork, (uv_after_work_cb)GetTagAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetTagWork(uv_work_t *req) { @@ -1335,7 +1331,7 @@ void GitRepo::GetTagWork(uv_work_t *req) { } void GitRepo::GetTagAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1348,21 +1344,21 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1385,26 +1381,26 @@ void GitRepo::GetTagAfterWork(uv_work_t *req) { * @param {Number} force * @param {Oid} callback */ -NAN_METHOD(GitRepo::CreateTag) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String tag_name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Object target is required.")); + return ThrowException(Exception::Error(String::New("Object target is required."))); } if (args.Length() == 2 || !args[2]->IsObject()) { - return NanThrowError(String::New("Signature tagger is required.")); + return ThrowException(Exception::Error(String::New("Signature tagger is required."))); } if (args.Length() == 3 || !args[3]->IsString()) { - return NanThrowError(String::New("String message is required.")); + return ThrowException(Exception::Error(String::New("String message is required."))); } if (args.Length() == 4 || !args[4]->IsInt32()) { - return NanThrowError(String::New("Number force is required.")); + return ThrowException(Exception::Error(String::New("Number force is required."))); } if (args.Length() == 5 || !args[5]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } CreateTagBaton* baton = new CreateTagBaton; @@ -1412,35 +1408,35 @@ NAN_METHOD(GitRepo::CreateTag) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, CreateTagWork, (uv_after_work_cb)CreateTagAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CreateTagWork(uv_work_t *req) { @@ -1461,7 +1457,7 @@ void GitRepo::CreateTagWork(uv_work_t *req) { } void GitRepo::CreateTagAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CreateTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1474,21 +1470,21 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -1516,20 +1512,20 @@ void GitRepo::CreateTagAfterWork(uv_work_t *req) { * @param {Number} force * @param {Oid} callback */ -NAN_METHOD(GitRepo::CreateLightweightTag) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String tag_name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Object target is required.")); + return ThrowException(Exception::Error(String::New("Object target is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number force is required.")); + return ThrowException(Exception::Error(String::New("Number force is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } CreateLightweightTagBaton* baton = new CreateLightweightTagBaton; @@ -1537,26 +1533,26 @@ NAN_METHOD(GitRepo::CreateLightweightTag) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, CreateLightweightTagWork, (uv_after_work_cb)CreateLightweightTagAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CreateLightweightTagWork(uv_work_t *req) { @@ -1575,7 +1571,7 @@ void GitRepo::CreateLightweightTagWork(uv_work_t *req) { } void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CreateLightweightTagBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1588,21 +1584,21 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -1625,31 +1621,31 @@ void GitRepo::CreateLightweightTagAfterWork(uv_work_t *req) { * @param {Oid} id * @param {Tree} callback */ -NAN_METHOD(GitRepo::GetTree) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetTreeWork, (uv_after_work_cb)GetTreeAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetTreeWork(uv_work_t *req) { @@ -1666,7 +1662,7 @@ void GitRepo::GetTreeWork(uv_work_t *req) { } void GitRepo::GetTreeAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1679,21 +1675,21 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1710,24 +1706,24 @@ void GitRepo::GetTreeAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitRepo::ReloadSubmodules) { - NanScope(); +Handle GitRepo::ReloadSubmodules(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReloadSubmodulesWork, (uv_after_work_cb)ReloadSubmodulesAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { @@ -1742,28 +1738,28 @@ void GitRepo::ReloadSubmodulesWork(uv_work_t *req) { } void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ReloadSubmodulesBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1780,32 +1776,32 @@ void GitRepo::ReloadSubmodulesAfterWork(uv_work_t *req) { /** * @param {String} tag_name */ -NAN_METHOD(GitRepo::Delete) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String tag_name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, DeleteWork, (uv_after_work_cb)DeleteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::DeleteWork(uv_work_t *req) { @@ -1821,28 +1817,28 @@ void GitRepo::DeleteWork(uv_work_t *req) { } void GitRepo::DeleteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DeleteBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -1862,11 +1858,11 @@ void GitRepo::DeleteAfterWork(uv_work_t *req) { * @param {Number} list_flags * @param {Array} callback */ -NAN_METHOD(GitRepo::GetReferences) { - NanScope(); +Handle GitRepo::GetReferences(const Arguments& args) { + HandleScope scope; if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } GetReferencesBaton* baton = new GetReferencesBaton; @@ -1874,21 +1870,21 @@ NAN_METHOD(GitRepo::GetReferences) { baton->error = NULL; baton->request.data = baton; baton->array = (git_strarray *)malloc(sizeof(git_strarray )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->list_flagsReference = Persistent::New(args[0]); + unsigned int from_list_flags; + if (args[0]->IsUint32()) { + from_list_flags = (unsigned int) args[0]->ToUint32()->Value(); + } else { + from_list_flags = 0; + } + baton->list_flags = from_list_flags; + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetReferencesWork, (uv_after_work_cb)GetReferencesAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetReferencesWork(uv_work_t *req) { @@ -1905,7 +1901,7 @@ void GitRepo::GetReferencesWork(uv_work_t *req) { } void GitRepo::GetReferencesAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetReferencesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -1919,21 +1915,21 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { to = tmpArray; Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->array); } @@ -1956,17 +1952,17 @@ void GitRepo::GetReferencesAfterWork(uv_work_t *req) { * @param {Number} len * @param {Oid} callback */ -NAN_METHOD(GitRepo::CreateBlobFromBuffer) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Buffer buffer is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsNumber()) { - return NanThrowError(String::New("Number len is required.")); + return ThrowException(Exception::Error(String::New("Number len is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } CreateBlobFromBufferBaton* baton = new CreateBlobFromBufferBaton; @@ -1974,21 +1970,21 @@ NAN_METHOD(GitRepo::CreateBlobFromBuffer) { baton->error = NULL; baton->request.data = baton; baton->oid = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, CreateBlobFromBufferWork, (uv_after_work_cb)CreateBlobFromBufferAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { @@ -2006,7 +2002,7 @@ void GitRepo::CreateBlobFromBufferWork(uv_work_t *req) { } void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CreateBlobFromBufferBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2019,21 +2015,21 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->oid); } @@ -2054,14 +2050,14 @@ void GitRepo::CreateBlobFromBufferAfterWork(uv_work_t *req) { * @param {String} path * @param {Oid} callback */ -NAN_METHOD(GitRepo::CreateBlobFromFile) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } CreateBlobFromFileBaton* baton = new CreateBlobFromFileBaton; @@ -2069,18 +2065,18 @@ NAN_METHOD(GitRepo::CreateBlobFromFile) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, CreateBlobFromFileWork, (uv_after_work_cb)CreateBlobFromFileAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { @@ -2097,7 +2093,7 @@ void GitRepo::CreateBlobFromFileWork(uv_work_t *req) { } void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CreateBlobFromFileBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2110,21 +2106,21 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->id); } @@ -2144,11 +2140,11 @@ void GitRepo::CreateBlobFromFileAfterWork(uv_work_t *req) { /** * @param {Array} callback */ -NAN_METHOD(GitRepo::GetRemotes) { - NanScope(); +Handle GitRepo::GetRemotes(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } GetRemotesBaton* baton = new GetRemotesBaton; @@ -2156,13 +2152,13 @@ NAN_METHOD(GitRepo::GetRemotes) { baton->error = NULL; baton->request.data = baton; baton->out = (git_strarray *)malloc(sizeof(git_strarray )); - NanAssignPersistent(Value, baton->repoReference, args.This()); + baton->repoReference = Persistent::New(args.This()); baton->repo = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, GetRemotesWork, (uv_after_work_cb)GetRemotesAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::GetRemotesWork(uv_work_t *req) { @@ -2178,7 +2174,7 @@ void GitRepo::GetRemotesWork(uv_work_t *req) { } void GitRepo::GetRemotesAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetRemotesBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2192,21 +2188,21 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { to = tmpArray; Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -2229,46 +2225,46 @@ void GitRepo::GetRemotesAfterWork(uv_work_t *req) { * @param {CloneOptions} options * @param {Repository} callback */ -NAN_METHOD(GitRepo::Clone) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String local_path is required.")); + return ThrowException(Exception::Error(String::New("String local_path is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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])); + baton->urlReference = Persistent::New(args[0]); + const char * from_url; + String::Utf8Value url(args[0]->ToString()); + from_url = strdup(*url); + baton->url = from_url; + baton->local_pathReference = Persistent::New(args[1]); + const char * from_local_path; + String::Utf8Value local_path(args[1]->ToString()); + from_local_path = strdup(*local_path); + baton->local_path = from_local_path; + baton->optionsReference = Persistent::New(args[2]); + const git_clone_options * from_options; + if (args[2]->IsObject()) { + from_options = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_options = 0; + } + baton->options = from_options; + baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, CloneWork, (uv_after_work_cb)CloneAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRepo::CloneWork(uv_work_t *req) { @@ -2286,7 +2282,7 @@ void GitRepo::CloneWork(uv_work_t *req) { } void GitRepo::CloneAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; CloneBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -2299,23 +2295,23 @@ void GitRepo::CloneAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -2333,16 +2329,16 @@ void GitRepo::CloneAfterWork(uv_work_t *req) { * @param {String} name * @return {Remote} out */ -NAN_METHOD(GitRepo::GetRemote) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } 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 @@ -2352,9 +2348,9 @@ NAN_METHOD(GitRepo::GetRemote) { free((void *)from_name); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -2364,7 +2360,7 @@ NAN_METHOD(GitRepo::GetRemote) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitRepo::constructor_template; +Persistent GitRepo::constructor_template; diff --git a/src/revwalk.cc b/src/revwalk.cc index 63751cf04..20d7a940b 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -25,12 +25,12 @@ GitRevWalk::~GitRevWalk() { } void GitRevWalk::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("RevWalk")); + tpl->SetClassName(String::NewSymbol("RevWalk")); NODE_SET_PROTOTYPE_METHOD(tpl, "reset", Reset); NODE_SET_PROTOTYPE_METHOD(tpl, "push", Push); @@ -45,29 +45,27 @@ void GitRevWalk::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "sorting", Sorting); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("RevWalk"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("RevWalk"), constructor_template); } -NAN_METHOD(GitRevWalk::New) { - NanScope(); + +Handle GitRevWalk::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_revwalk is required.")); + return ThrowException(Exception::Error(String::New("git_revwalk is required."))); } - GitRevWalk* object = new GitRevWalk((git_revwalk *) External::Cast(*args[0])->Value()); + GitRevWalk* object = new GitRevWalk((git_revwalk *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitRevWalk::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitRevWalk::constructor_template->NewInstance(1, argv)); } git_revwalk *GitRevWalk::GetValue() { @@ -77,15 +75,15 @@ git_revwalk *GitRevWalk::GetValue() { /** */ -NAN_METHOD(GitRevWalk::Reset) { - NanScope(); +Handle GitRevWalk::Reset(const Arguments& args) { + HandleScope scope; git_revwalk_reset( ObjectWrap::Unwrap(args.This())->GetValue() ); - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -93,31 +91,31 @@ NAN_METHOD(GitRevWalk::Reset) { /** * @param {Oid} id */ -NAN_METHOD(GitRevWalk::Push) { - NanScope(); +Handle GitRevWalk::Push(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, PushWork, (uv_after_work_cb)PushAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::PushWork(uv_work_t *req) { @@ -133,28 +131,28 @@ void GitRevWalk::PushWork(uv_work_t *req) { } void GitRevWalk::PushAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; PushBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -172,32 +170,32 @@ void GitRevWalk::PushAfterWork(uv_work_t *req) { /** * @param {String} glob */ -NAN_METHOD(GitRevWalk::PushGlob) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String glob is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, PushGlobWork, (uv_after_work_cb)PushGlobAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::PushGlobWork(uv_work_t *req) { @@ -213,28 +211,28 @@ void GitRevWalk::PushGlobWork(uv_work_t *req) { } void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; PushGlobBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -252,24 +250,24 @@ void GitRevWalk::PushGlobAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitRevWalk::PushHead) { - NanScope(); +Handle GitRevWalk::PushHead(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, PushHeadWork, (uv_after_work_cb)PushHeadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::PushHeadWork(uv_work_t *req) { @@ -284,28 +282,28 @@ void GitRevWalk::PushHeadWork(uv_work_t *req) { } void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; PushHeadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -322,31 +320,31 @@ void GitRevWalk::PushHeadAfterWork(uv_work_t *req) { /** * @param {Oid} commit_id */ -NAN_METHOD(GitRevWalk::Hide) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid commit_id is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, HideWork, (uv_after_work_cb)HideAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::HideWork(uv_work_t *req) { @@ -362,28 +360,28 @@ void GitRevWalk::HideWork(uv_work_t *req) { } void GitRevWalk::HideAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; HideBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -401,32 +399,32 @@ void GitRevWalk::HideAfterWork(uv_work_t *req) { /** * @param {String} glob */ -NAN_METHOD(GitRevWalk::HideGlob) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String glob is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, HideGlobWork, (uv_after_work_cb)HideGlobAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::HideGlobWork(uv_work_t *req) { @@ -442,28 +440,28 @@ void GitRevWalk::HideGlobWork(uv_work_t *req) { } void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; HideGlobBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -481,24 +479,24 @@ void GitRevWalk::HideGlobAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitRevWalk::HideHead) { - NanScope(); +Handle GitRevWalk::HideHead(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, HideHeadWork, (uv_after_work_cb)HideHeadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::HideHeadWork(uv_work_t *req) { @@ -513,30 +511,30 @@ void GitRevWalk::HideHeadWork(uv_work_t *req) { } void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; HideHeadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -551,32 +549,32 @@ void GitRevWalk::HideHeadAfterWork(uv_work_t *req) { /** * @param {String} refname */ -NAN_METHOD(GitRevWalk::PushRef) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String refname is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, PushRefWork, (uv_after_work_cb)PushRefAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::PushRefWork(uv_work_t *req) { @@ -592,30 +590,30 @@ void GitRevWalk::PushRefWork(uv_work_t *req) { } void GitRevWalk::PushRefAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; PushRefBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -632,32 +630,32 @@ void GitRevWalk::PushRefAfterWork(uv_work_t *req) { /** * @param {String} refname */ -NAN_METHOD(GitRevWalk::HideRef) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String refname is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, HideRefWork, (uv_after_work_cb)HideRefAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::HideRefWork(uv_work_t *req) { @@ -673,30 +671,30 @@ void GitRevWalk::HideRefWork(uv_work_t *req) { } void GitRevWalk::HideRefAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; HideRefBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } - } + } if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -713,11 +711,11 @@ void GitRevWalk::HideRefAfterWork(uv_work_t *req) { /** * @param {Oid} callback */ -NAN_METHOD(GitRevWalk::Next) { - NanScope(); +Handle GitRevWalk::Next(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } NextBaton* baton = new NextBaton; @@ -725,13 +723,13 @@ NAN_METHOD(GitRevWalk::Next) { baton->error = NULL; baton->request.data = baton; baton->out = (git_oid *)malloc(sizeof(git_oid )); - NanAssignPersistent(Value, baton->walkReference, args.This()); + baton->walkReference = Persistent::New(args.This()); baton->walk = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, NextWork, (uv_after_work_cb)NextAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitRevWalk::NextWork(uv_work_t *req) { @@ -747,7 +745,7 @@ void GitRevWalk::NextWork(uv_work_t *req) { } void GitRevWalk::NextAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; NextBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -760,21 +758,21 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->out); } @@ -790,21 +788,21 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { /** * @param {Number} sort_mode */ -NAN_METHOD(GitRevWalk::Sorting) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number sort_mode is required.")); +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."))); } unsigned int from_sort_mode; - from_sort_mode = (unsigned int) args[0]->ToUint32()->Value(); + from_sort_mode = (unsigned int) args[0]->ToUint32()->Value(); git_revwalk_sorting( ObjectWrap::Unwrap(args.This())->GetValue() , from_sort_mode ); - NanReturnUndefined(); + return Undefined(); } -Persistent GitRevWalk::constructor_template; +Persistent GitRevWalk::constructor_template; diff --git a/src/signature.cc b/src/signature.cc index aec9b1f3a..d355896eb 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -24,12 +24,12 @@ GitSignature::~GitSignature() { } void GitSignature::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Signature")); + tpl->SetClassName(String::NewSymbol("Signature")); NODE_SET_METHOD(tpl, "create", Create); NODE_SET_METHOD(tpl, "now", Now); @@ -38,30 +38,27 @@ void GitSignature::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "email", Email); NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Signature"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Signature"), constructor_template); } -NAN_METHOD(GitSignature::New) { - NanScope(); +Handle GitSignature::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_signature is required.")); + return ThrowException(Exception::Error(String::New("git_signature is required."))); } - GitSignature* object = new GitSignature((git_signature *) External::Cast(*args[0])->Value()); + GitSignature* object = new GitSignature((git_signature *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitSignature::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitSignature::constructor_template->NewInstance(1, argv)); } git_signature *GitSignature::GetValue() { @@ -76,19 +73,19 @@ git_signature *GitSignature::GetValue() { * @param {Number} offset * @return {Signature} out */ -NAN_METHOD(GitSignature::Create) { - NanScope(); - if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); +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."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String email is required.")); + return ThrowException(Exception::Error(String::New("String email is required."))); } if (args.Length() == 2 || !args[2]->IsInt32()) { - return NanThrowError(String::New("Number time is required.")); + return ThrowException(Exception::Error(String::New("Number time is required."))); } if (args.Length() == 3 || !args[3]->IsInt32()) { - return NanThrowError(String::New("Number offset is required.")); + return ThrowException(Exception::Error(String::New("Number offset is required."))); } git_signature * out = 0; @@ -99,9 +96,9 @@ NAN_METHOD(GitSignature::Create) { String::Utf8Value email(args[1]->ToString()); from_email = strdup(*email); git_time_t from_time; - from_time = (git_time_t) args[2]->ToInt32()->Value(); + from_time = (git_time_t) args[2]->ToInt32()->Value(); int from_offset; - from_offset = (int) args[3]->ToInt32()->Value(); + from_offset = (int) args[3]->ToInt32()->Value(); int result = git_signature_new( &out @@ -114,9 +111,9 @@ NAN_METHOD(GitSignature::Create) { free((void *)from_email); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -126,7 +123,7 @@ NAN_METHOD(GitSignature::Create) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -134,13 +131,13 @@ NAN_METHOD(GitSignature::Create) { * @param {String} email * @return {Signature} out */ -NAN_METHOD(GitSignature::Now) { - NanScope(); +Handle GitSignature::Now(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String name is required.")); + return ThrowException(Exception::Error(String::New("String name is required."))); } if (args.Length() == 1 || !args[1]->IsString()) { - return NanThrowError(String::New("String email is required.")); + return ThrowException(Exception::Error(String::New("String email is required."))); } git_signature * out = 0; @@ -160,9 +157,9 @@ NAN_METHOD(GitSignature::Now) { free((void *)from_email); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -172,32 +169,33 @@ NAN_METHOD(GitSignature::Now) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitSignature::Name) { - NanScope(); + +Handle GitSignature::Name(const Arguments& args) { + HandleScope scope; Handle to; const char * name = ObjectWrap::Unwrap(args.This())->GetValue()->name; to = String::New(name); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitSignature::Email) { - NanScope(); +Handle GitSignature::Email(const Arguments& args) { + HandleScope scope; Handle to; const char * email = ObjectWrap::Unwrap(args.This())->GetValue()->email; to = String::New(email); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitSignature::Time) { - NanScope(); +Handle GitSignature::Time(const Arguments& args) { + HandleScope scope; Handle to; git_time *when = @@ -211,7 +209,7 @@ NAN_METHOD(GitSignature::Time) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitSignature::constructor_template; +Persistent GitSignature::constructor_template; diff --git a/src/submodule.cc b/src/submodule.cc index 367426317..2b355fc9c 100644 --- a/src/submodule.cc +++ b/src/submodule.cc @@ -25,12 +25,12 @@ GitSubmodule::~GitSubmodule() { } void GitSubmodule::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Submodule")); + tpl->SetClassName(String::NewSymbol("Submodule")); NODE_SET_PROTOTYPE_METHOD(tpl, "addFinalize", AddFinalize); NODE_SET_PROTOTYPE_METHOD(tpl, "addToIndex", AddToIndex); @@ -48,30 +48,27 @@ void GitSubmodule::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "status", Status); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Submodule"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Submodule"), constructor_template); } -NAN_METHOD(GitSubmodule::New) { - NanScope(); +Handle GitSubmodule::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_submodule is required.")); + return ThrowException(Exception::Error(String::New("git_submodule is required."))); } - GitSubmodule* object = new GitSubmodule((git_submodule *) External::Cast(*args[0])->Value()); + GitSubmodule* object = new GitSubmodule((git_submodule *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitSubmodule::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitSubmodule::constructor_template->NewInstance(1, argv)); } git_submodule *GitSubmodule::GetValue() { @@ -83,24 +80,24 @@ git_submodule *GitSubmodule::GetValue() { /** */ -NAN_METHOD(GitSubmodule::AddFinalize) { - NanScope(); +Handle GitSubmodule::AddFinalize(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, AddFinalizeWork, (uv_after_work_cb)AddFinalizeAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::AddFinalizeWork(uv_work_t *req) { @@ -115,28 +112,28 @@ void GitSubmodule::AddFinalizeWork(uv_work_t *req) { } void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; AddFinalizeBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -153,31 +150,31 @@ void GitSubmodule::AddFinalizeAfterWork(uv_work_t *req) { /** * @param {Number} write_index */ -NAN_METHOD(GitSubmodule::AddToIndex) { - NanScope(); +Handle GitSubmodule::AddToIndex(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number write_index is required.")); + return ThrowException(Exception::Error(String::New("Number write_index is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, AddToIndexWork, (uv_after_work_cb)AddToIndexAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::AddToIndexWork(uv_work_t *req) { @@ -193,28 +190,28 @@ void GitSubmodule::AddToIndexWork(uv_work_t *req) { } void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; AddToIndexBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -231,24 +228,24 @@ void GitSubmodule::AddToIndexAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitSubmodule::Save) { - NanScope(); +Handle GitSubmodule::Save(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, SaveWork, (uv_after_work_cb)SaveAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::SaveWork(uv_work_t *req) { @@ -263,28 +260,28 @@ void GitSubmodule::SaveWork(uv_work_t *req) { } void GitSubmodule::SaveAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; SaveBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -299,8 +296,8 @@ void GitSubmodule::SaveAfterWork(uv_work_t *req) { /** * @return {String} result */ -NAN_METHOD(GitSubmodule::Name) { - NanScope(); +Handle GitSubmodule::Name(const Arguments& args) { + HandleScope scope; const char * result = git_submodule_name( @@ -309,14 +306,14 @@ NAN_METHOD(GitSubmodule::Name) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitSubmodule::Path) { - NanScope(); +Handle GitSubmodule::Path(const Arguments& args) { + HandleScope scope; const char * result = git_submodule_path( @@ -325,14 +322,14 @@ NAN_METHOD(GitSubmodule::Path) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitSubmodule::Url) { - NanScope(); +Handle GitSubmodule::Url(const Arguments& args) { + HandleScope scope; const char * result = git_submodule_url( @@ -341,16 +338,16 @@ NAN_METHOD(GitSubmodule::Url) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} url */ -NAN_METHOD(GitSubmodule::SetUrl) { - NanScope(); +Handle GitSubmodule::SetUrl(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String url is required.")); + return ThrowException(Exception::Error(String::New("String url is required."))); } const char * from_url; @@ -364,20 +361,20 @@ NAN_METHOD(GitSubmodule::SetUrl) { free((void *)from_url); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** * @return {Oid} result */ -NAN_METHOD(GitSubmodule::IndexId) { - NanScope(); +Handle GitSubmodule::IndexId(const Arguments& args) { + HandleScope scope; const git_oid * result = git_submodule_index_id( @@ -393,14 +390,14 @@ NAN_METHOD(GitSubmodule::IndexId) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Oid} result */ -NAN_METHOD(GitSubmodule::HeadId) { - NanScope(); +Handle GitSubmodule::HeadId(const Arguments& args) { + HandleScope scope; const git_oid * result = git_submodule_head_id( @@ -416,7 +413,7 @@ NAN_METHOD(GitSubmodule::HeadId) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -424,31 +421,31 @@ NAN_METHOD(GitSubmodule::HeadId) { /** * @param {Number} overwrite */ -NAN_METHOD(GitSubmodule::Init) { - NanScope(); +Handle GitSubmodule::Init(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number overwrite is required.")); + return ThrowException(Exception::Error(String::New("Number overwrite is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, InitWork, (uv_after_work_cb)InitAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::InitWork(uv_work_t *req) { @@ -464,28 +461,28 @@ void GitSubmodule::InitWork(uv_work_t *req) { } void GitSubmodule::InitAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; InitBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -502,24 +499,24 @@ void GitSubmodule::InitAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitSubmodule::Sync) { - NanScope(); +Handle GitSubmodule::Sync(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, SyncWork, (uv_after_work_cb)SyncAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::SyncWork(uv_work_t *req) { @@ -534,28 +531,28 @@ void GitSubmodule::SyncWork(uv_work_t *req) { } void GitSubmodule::SyncAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; SyncBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -572,24 +569,24 @@ void GitSubmodule::SyncAfterWork(uv_work_t *req) { /** * @param {Repository} callback */ -NAN_METHOD(GitSubmodule::Open) { - NanScope(); +Handle GitSubmodule::Open(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, OpenWork, (uv_after_work_cb)OpenAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::OpenWork(uv_work_t *req) { @@ -605,7 +602,7 @@ void GitSubmodule::OpenWork(uv_work_t *req) { } void GitSubmodule::OpenAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; OpenBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -618,21 +615,21 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -648,24 +645,24 @@ void GitSubmodule::OpenAfterWork(uv_work_t *req) { /** */ -NAN_METHOD(GitSubmodule::Reload) { - NanScope(); +Handle GitSubmodule::Reload(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->submoduleReference, args.This()); + baton->submoduleReference = Persistent::New(args.This()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, ReloadWork, (uv_after_work_cb)ReloadAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::ReloadWork(uv_work_t *req) { @@ -680,28 +677,28 @@ void GitSubmodule::ReloadWork(uv_work_t *req) { } void GitSubmodule::ReloadAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; ReloadBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -718,31 +715,31 @@ void GitSubmodule::ReloadAfterWork(uv_work_t *req) { /** * @param {Number} status */ -NAN_METHOD(GitSubmodule::Status) { - NanScope(); +Handle GitSubmodule::Status(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsInt32()) { - return NanThrowError(String::New("Number status is required.")); + return ThrowException(Exception::Error(String::New("Number status is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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->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()); baton->submodule = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, StatusWork, (uv_after_work_cb)StatusAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitSubmodule::StatusWork(uv_work_t *req) { @@ -758,28 +755,28 @@ void GitSubmodule::StatusWork(uv_work_t *req) { } void GitSubmodule::StatusAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; StatusBaton *baton = static_cast(req->data); TryCatch try_catch; if (baton->error_code == GIT_OK) { - Handle result = NanNewLocal(Undefined()); + Handle result = Local::New(Undefined()); Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -792,4 +789,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 4423559e6..08b099d41 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -27,12 +27,12 @@ GitTag::~GitTag() { } void GitTag::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Tag")); + tpl->SetClassName(String::NewSymbol("Tag")); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "getTarget", GetTarget); @@ -44,30 +44,27 @@ void GitTag::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Tag"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Tag"), constructor_template); } -NAN_METHOD(GitTag::New) { - NanScope(); +Handle GitTag::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_tag is required.")); + return ThrowException(Exception::Error(String::New("git_tag is required."))); } - GitTag* object = new GitTag((git_tag *) External::Cast(*args[0])->Value()); + GitTag* object = new GitTag((git_tag *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitTag::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitTag::constructor_template->NewInstance(1, argv)); } git_tag *GitTag::GetValue() { @@ -78,8 +75,8 @@ git_tag *GitTag::GetValue() { /** * @return {Oid} result */ -NAN_METHOD(GitTag::Oid) { - NanScope(); +Handle GitTag::Oid(const Arguments& args) { + HandleScope scope; const git_oid * result = git_tag_id( @@ -95,7 +92,7 @@ NAN_METHOD(GitTag::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -103,24 +100,24 @@ NAN_METHOD(GitTag::Oid) { /** * @param {Object} callback */ -NAN_METHOD(GitTag::GetTarget) { - NanScope(); +Handle GitTag::GetTarget(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->tagReference, args.This()); + baton->tagReference = Persistent::New(args.This()); baton->tag = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[0])); + baton->callback = Persistent::New(Local::Cast(args[0])); uv_queue_work(uv_default_loop(), &baton->request, GetTargetWork, (uv_after_work_cb)GetTargetAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTag::GetTargetWork(uv_work_t *req) { @@ -136,7 +133,7 @@ void GitTag::GetTargetWork(uv_work_t *req) { } void GitTag::GetTargetAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetTargetBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -149,21 +146,21 @@ void GitTag::GetTargetAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -178,8 +175,9 @@ void GitTag::GetTargetAfterWork(uv_work_t *req) { /** * @return {Oid} result */ -NAN_METHOD(GitTag::TargetId) { - NanScope(); +Handle GitTag::TargetId(const Arguments& args) { + HandleScope scope; + const git_oid * result = git_tag_target_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -194,14 +192,14 @@ NAN_METHOD(GitTag::TargetId) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitTag::TargetType) { - NanScope(); +Handle GitTag::TargetType(const Arguments& args) { + HandleScope scope; git_otype result = git_tag_target_type( @@ -210,14 +208,14 @@ NAN_METHOD(GitTag::TargetType) { Handle to; to = Int32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitTag::Name) { - NanScope(); +Handle GitTag::Name(const Arguments& args) { + HandleScope scope; const char * result = git_tag_name( @@ -226,14 +224,14 @@ NAN_METHOD(GitTag::Name) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Signature} result */ -NAN_METHOD(GitTag::Tagger) { - NanScope(); +Handle GitTag::Tagger(const Arguments& args) { + HandleScope scope; const git_signature * result = git_tag_tagger( @@ -249,14 +247,14 @@ NAN_METHOD(GitTag::Tagger) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {String} result */ -NAN_METHOD(GitTag::Message) { - NanScope(); +Handle GitTag::Message(const Arguments& args) { + HandleScope scope; const char * result = git_tag_message( @@ -265,17 +263,17 @@ NAN_METHOD(GitTag::Message) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {Tag} tag * @return {Object} tag_target_out */ -NAN_METHOD(GitTag::Peel) { - NanScope(); +Handle GitTag::Peel(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Tag tag is required.")); + return ThrowException(Exception::Error(String::New("Tag tag is required."))); } git_object * tag_target_out = 0; @@ -288,9 +286,9 @@ NAN_METHOD(GitTag::Peel) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -300,7 +298,7 @@ NAN_METHOD(GitTag::Peel) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } -Persistent GitTag::constructor_template; +Persistent GitTag::constructor_template; diff --git a/src/threads.cc b/src/threads.cc index 3aa2edaff..020600206 100755 --- a/src/threads.cc +++ b/src/threads.cc @@ -15,47 +15,45 @@ using namespace v8; using namespace node; void GitThreads::Initialize(Handle target) { - NanScope(); + HandleScope scope; - Persistent object; + Persistent object = Persistent::New(Object::New()); - NanAssignPersistent(Object, object, Object::New()); + object->Set(String::NewSymbol("init"), FunctionTemplate::New(Init)->GetFunction()); + object->Set(String::NewSymbol("shutdown"), FunctionTemplate::New(Shutdown)->GetFunction()); - 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)); + target->Set(String::NewSymbol("Threads"), object); } /** */ -NAN_METHOD(GitThreads::Init) { - NanScope(); +Handle GitThreads::Init(const Arguments& args) { + HandleScope scope; int result = git_threads_init( ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } /** */ -NAN_METHOD(GitThreads::Shutdown) { - NanScope(); +Handle GitThreads::Shutdown(const Arguments& args) { + HandleScope scope; git_threads_shutdown( ); - NanReturnUndefined(); + return Undefined(); } diff --git a/src/time.cc b/src/time.cc index 4196ec83e..b03a49c84 100644 --- a/src/time.cc +++ b/src/time.cc @@ -23,66 +23,65 @@ GitTime::~GitTime() { } void GitTime::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Time")); - + tpl->SetClassName(String::NewSymbol("Time")); + + NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); NODE_SET_PROTOTYPE_METHOD(tpl, "offset", Offset); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Time"), tpl->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Time"), constructor_template); } -NAN_METHOD(GitTime::New) { - NanScope(); +Handle GitTime::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_time is required.")); + return ThrowException(Exception::Error(String::New("git_time is required."))); } - GitTime* object = new GitTime((git_time *) External::Cast(*args[0])->Value()); + GitTime* object = new GitTime((git_time *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitTime::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitTime::constructor_template->NewInstance(1, argv)); } git_time *GitTime::GetValue() { return this->raw; } -NAN_METHOD(GitTime::Time) { - NanScope(); + +Handle GitTime::Time(const Arguments& args) { + HandleScope scope; Handle to; git_time_t time = ObjectWrap::Unwrap(args.This())->GetValue()->time; to = Integer::New(time); - NanReturnValue(to); + return scope.Close(to); } -NAN_METHOD(GitTime::Offset) { - NanScope(); +Handle GitTime::Offset(const Arguments& args) { + HandleScope scope; Handle to; int offset = ObjectWrap::Unwrap(args.This())->GetValue()->offset; to = Int32::New(offset); - NanReturnValue(to); + return scope.Close(to); } -Persistent GitTime::constructor_template; +Persistent GitTime::constructor_template; diff --git a/src/tree.cc b/src/tree.cc index 6798183ae..8a2661ce1 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -30,13 +30,13 @@ GitTree::~GitTree() { } void GitTree::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("Tree")); - + tpl->SetClassName(String::NewSymbol("Tree")); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); NODE_SET_PROTOTYPE_METHOD(tpl, "entryByName", EntryByName); @@ -48,30 +48,28 @@ void GitTree::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "diffIndex", DiffIndex); NODE_SET_PROTOTYPE_METHOD(tpl, "diffWorkDir", DiffWorkDir); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("Tree"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Tree"), constructor_template); } -NAN_METHOD(GitTree::New) { - NanScope(); +Handle GitTree::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_tree is required.")); + return ThrowException(Exception::Error(String::New("git_tree is required."))); } - GitTree* object = new GitTree((git_tree *) External::Cast(*args[0])->Value()); + GitTree* object = new GitTree((git_tree *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitTree::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitTree::constructor_template->NewInstance(1, argv)); } git_tree *GitTree::GetValue() { @@ -82,9 +80,9 @@ git_tree *GitTree::GetValue() { /** * @return {Oid} result */ -NAN_METHOD(GitTree::Oid) { - NanScope(); - +Handle GitTree::Oid(const Arguments& args) { + HandleScope scope; + const git_oid * result = git_tree_id( ObjectWrap::Unwrap(args.This())->GetValue() @@ -99,14 +97,14 @@ NAN_METHOD(GitTree::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitTree::Size) { - NanScope(); +Handle GitTree::Size(const Arguments& args) { + HandleScope scope; size_t result = git_tree_entrycount( @@ -115,17 +113,17 @@ NAN_METHOD(GitTree::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} filename * @return {TreeEntry} result */ -NAN_METHOD(GitTree::EntryByName) { - NanScope(); +Handle GitTree::EntryByName(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String filename is required.")); + return ThrowException(Exception::Error(String::New("String filename is required."))); } const char * from_filename; @@ -147,21 +145,21 @@ NAN_METHOD(GitTree::EntryByName) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {Number} idx * @return {TreeEntry} result */ -NAN_METHOD(GitTree::EntryByIndex) { - NanScope(); +Handle GitTree::EntryByIndex(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsUint32()) { - return NanThrowError(String::New("Number idx is required.")); + return ThrowException(Exception::Error(String::New("Number idx is required."))); } size_t from_idx; - from_idx = (size_t) args[0]->ToUint32()->Value(); + from_idx = (size_t) args[0]->ToUint32()->Value(); const git_tree_entry * result = git_tree_entry_byindex( ObjectWrap::Unwrap(args.This())->GetValue() @@ -177,17 +175,17 @@ NAN_METHOD(GitTree::EntryByIndex) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {Oid} oid * @return {TreeEntry} result */ -NAN_METHOD(GitTree::EntryByOid) { - NanScope(); +Handle GitTree::EntryByOid(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Oid oid is required.")); + return ThrowException(Exception::Error(String::New("Oid oid is required."))); } const git_oid * from_oid; @@ -207,7 +205,7 @@ NAN_METHOD(GitTree::EntryByOid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -216,32 +214,32 @@ NAN_METHOD(GitTree::EntryByOid) { * @param {String} path * @param {TreeEntry} callback */ -NAN_METHOD(GitTree::GetEntry) { - NanScope(); +Handle GitTree::GetEntry(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String path is required.")); + return ThrowException(Exception::Error(String::New("String path is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - NanAssignPersistent(Value, baton->rootReference, args.This()); + baton->rootReference = Persistent::New(args.This()); baton->root = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + 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])); uv_queue_work(uv_default_loop(), &baton->request, GetEntryWork, (uv_after_work_cb)GetEntryAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTree::GetEntryWork(uv_work_t *req) { @@ -258,7 +256,7 @@ void GitTree::GetEntryWork(uv_work_t *req) { } void GitTree::GetEntryAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetEntryBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -271,21 +269,21 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -302,8 +300,8 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { /** * @return {TreeBuilder} out */ -NAN_METHOD(GitTree::Builder) { - NanScope(); +Handle GitTree::Builder(const Arguments& args) { + HandleScope scope; git_treebuilder * out = 0; @@ -313,9 +311,9 @@ NAN_METHOD(GitTree::Builder) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -325,7 +323,7 @@ NAN_METHOD(GitTree::Builder) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -336,46 +334,46 @@ NAN_METHOD(GitTree::Builder) { * @param {DiffOptions} opts * @param {DiffList} callback */ -NAN_METHOD(GitTree::DiffTree) { - NanScope(); +Handle GitTree::DiffTree(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Tree new_tree is required.")); + return ThrowException(Exception::Error(String::New("Tree new_tree is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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->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()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->new_treeReference = Persistent::New(args[1]); + git_tree * from_new_tree; + from_new_tree = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->new_tree = from_new_tree; + baton->optsReference = Persistent::New(args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, DiffTreeWork, (uv_after_work_cb)DiffTreeAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTree::DiffTreeWork(uv_work_t *req) { @@ -394,7 +392,7 @@ void GitTree::DiffTreeWork(uv_work_t *req) { } void GitTree::DiffTreeAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DiffTreeBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -407,21 +405,21 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -444,47 +442,47 @@ void GitTree::DiffTreeAfterWork(uv_work_t *req) { * @param {DiffOptions} opts * @param {DiffList} callback */ -NAN_METHOD(GitTree::DiffIndex) { - NanScope(); +Handle GitTree::DiffIndex(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 3 || !args[3]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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->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()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->indexReference = Persistent::New(args[1]); + git_index * from_index; + if (args[1]->IsObject()) { + from_index = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_index = 0; + } + baton->index = from_index; + baton->optsReference = Persistent::New(args[2]); + const git_diff_options * from_opts; + if (args[2]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + baton->callback = Persistent::New(Local::Cast(args[3])); uv_queue_work(uv_default_loop(), &baton->request, DiffIndexWork, (uv_after_work_cb)DiffIndexAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTree::DiffIndexWork(uv_work_t *req) { @@ -503,7 +501,7 @@ void GitTree::DiffIndexWork(uv_work_t *req) { } void GitTree::DiffIndexAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DiffIndexBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -516,21 +514,21 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -552,39 +550,39 @@ void GitTree::DiffIndexAfterWork(uv_work_t *req) { * @param {DiffOptions} opts * @param {DiffList} callback */ -NAN_METHOD(GitTree::DiffWorkDir) { - NanScope(); +Handle GitTree::DiffWorkDir(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 2 || !args[2]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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->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()); baton->old_tree = ObjectWrap::Unwrap(args.This())->GetValue(); - 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])); + baton->optsReference = Persistent::New(args[1]); + const git_diff_options * from_opts; + if (args[1]->IsObject()) { + from_opts = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + } else { + from_opts = 0; + } + baton->opts = from_opts; + baton->callback = Persistent::New(Local::Cast(args[2])); uv_queue_work(uv_default_loop(), &baton->request, DiffWorkDirWork, (uv_after_work_cb)DiffWorkDirAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTree::DiffWorkDirWork(uv_work_t *req) { @@ -602,7 +600,7 @@ void GitTree::DiffWorkDirWork(uv_work_t *req) { } void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; DiffWorkDirBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -615,21 +613,21 @@ void GitTree::DiffWorkDirAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -643,4 +641,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 59ccd63ba..3a6b6585f 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -30,13 +30,13 @@ GitTreeBuilder::~GitTreeBuilder() { } void GitTreeBuilder::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("TreeBuilder")); - + tpl->SetClassName(String::NewSymbol("TreeBuilder")); + NODE_SET_METHOD(tpl, "create", Create); NODE_SET_PROTOTYPE_METHOD(tpl, "clear", Clear); NODE_SET_METHOD(tpl, "size", Size); @@ -45,30 +45,28 @@ void GitTreeBuilder::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "gitTreebuilderRemove", GitTreebuilderRemove); NODE_SET_PROTOTYPE_METHOD(tpl, "write", Write); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("TreeBuilder"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("TreeBuilder"), constructor_template); } -NAN_METHOD(GitTreeBuilder::New) { - NanScope(); +Handle GitTreeBuilder::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_treebuilder is required.")); + return ThrowException(Exception::Error(String::New("git_treebuilder is required."))); } - GitTreeBuilder* object = new GitTreeBuilder((git_treebuilder *) External::Cast(*args[0])->Value()); + GitTreeBuilder* object = new GitTreeBuilder((git_treebuilder *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitTreeBuilder::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitTreeBuilder::constructor_template->NewInstance(1, argv)); } git_treebuilder *GitTreeBuilder::GetValue() { @@ -80,8 +78,8 @@ git_treebuilder *GitTreeBuilder::GetValue() { * @param {Tree} source * @return {TreeBuilder} out */ -NAN_METHOD(GitTreeBuilder::Create) { - NanScope(); +Handle GitTreeBuilder::Create(const Arguments& args) { + HandleScope scope; git_treebuilder * out = 0; const git_tree * from_source; @@ -97,9 +95,9 @@ NAN_METHOD(GitTreeBuilder::Create) { ); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -109,16 +107,16 @@ NAN_METHOD(GitTreeBuilder::Create) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {TreeBuilder} bld */ -NAN_METHOD(GitTreeBuilder::Clear) { - NanScope(); +Handle GitTreeBuilder::Clear(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("TreeBuilder bld is required.")); + return ThrowException(Exception::Error(String::New("TreeBuilder bld is required."))); } git_treebuilder * from_bld; @@ -128,14 +126,14 @@ NAN_METHOD(GitTreeBuilder::Clear) { from_bld ); - NanReturnUndefined(); + return Undefined(); } /** * @return {Number} result */ -NAN_METHOD(GitTreeBuilder::Size) { - NanScope(); +Handle GitTreeBuilder::Size(const Arguments& args) { + HandleScope scope; unsigned int result = git_treebuilder_entrycount( @@ -144,17 +142,17 @@ NAN_METHOD(GitTreeBuilder::Size) { Handle to; to = Uint32::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} filename * @return {TreeEntry} result */ -NAN_METHOD(GitTreeBuilder::Get) { - NanScope(); +Handle GitTreeBuilder::Get(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String filename is required.")); + return ThrowException(Exception::Error(String::New("String filename is required."))); } const char * from_filename; @@ -176,7 +174,7 @@ NAN_METHOD(GitTreeBuilder::Get) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** @@ -185,16 +183,16 @@ NAN_METHOD(GitTreeBuilder::Get) { * @param {Number} filemode * @return {TreeEntry} out */ -NAN_METHOD(GitTreeBuilder::Insert) { - NanScope(); +Handle GitTreeBuilder::Insert(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String filename is required.")); + return ThrowException(Exception::Error(String::New("String filename is required."))); } if (args.Length() == 1 || !args[1]->IsObject()) { - return NanThrowError(String::New("Oid id is required.")); + return ThrowException(Exception::Error(String::New("Oid id is required."))); } if (args.Length() == 2 || !args[2]->IsNumber()) { - return NanThrowError(String::New("Number filemode is required.")); + return ThrowException(Exception::Error(String::New("Number filemode is required."))); } const git_tree_entry * out = 0; @@ -204,7 +202,7 @@ NAN_METHOD(GitTreeBuilder::Insert) { const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); git_filemode_t from_filemode; - from_filemode = (git_filemode_t) args[2]->ToNumber()->Value(); + from_filemode = (git_filemode_t) (int) args[2]->ToNumber()->Value(); int result = git_treebuilder_insert( &out @@ -216,9 +214,9 @@ NAN_METHOD(GitTreeBuilder::Insert) { free((void *)from_filename); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } @@ -231,16 +229,16 @@ NAN_METHOD(GitTreeBuilder::Insert) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @param {String} filename */ -NAN_METHOD(GitTreeBuilder::GitTreebuilderRemove) { - NanScope(); +Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { - return NanThrowError(String::New("String filename is required.")); + return ThrowException(Exception::Error(String::New("String filename is required."))); } const char * from_filename; @@ -254,13 +252,13 @@ NAN_METHOD(GitTreeBuilder::GitTreebuilderRemove) { free((void *)from_filename); if (result != GIT_OK) { if (giterr_last()) { - return NanThrowError(String::New(giterr_last()->message)); + return ThrowException(Exception::Error(String::New(giterr_last()->message))); } else { - return NanThrowError(String::New("Unkown Error")); + return ThrowException(Exception::Error(String::New("Unkown Error"))); } } - NanReturnUndefined(); + return Undefined(); } #include "../include/functions/copy.h" @@ -269,14 +267,14 @@ NAN_METHOD(GitTreeBuilder::GitTreebuilderRemove) { * @param {Repository} repo * @param {Oid} callback */ -NAN_METHOD(GitTreeBuilder::Write) { - NanScope(); +Handle GitTreeBuilder::Write(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } WriteBaton* baton = new WriteBaton; @@ -284,17 +282,17 @@ NAN_METHOD(GitTreeBuilder::Write) { baton->error = NULL; baton->request.data = baton; baton->id = (git_oid *)malloc(sizeof(git_oid )); - 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->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()); baton->bld = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTreeBuilder::WriteWork(uv_work_t *req) { @@ -311,7 +309,7 @@ void GitTreeBuilder::WriteWork(uv_work_t *req) { } void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; WriteBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -324,21 +322,21 @@ void GitTreeBuilder::WriteAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } free(baton->id); } @@ -352,4 +350,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 baa5a1966..2d761e611 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -26,43 +26,41 @@ GitTreeEntry::~GitTreeEntry() { } void GitTreeEntry::Initialize(Handle target) { - NanScope(); + HandleScope scope; Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(NanSymbol("TreeEntry")); - + tpl->SetClassName(String::NewSymbol("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); - NanAssignPersistent(FunctionTemplate, constructor_template, tpl); - target->Set(String::NewSymbol("TreeEntry"), tpl->GetFunction()); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("TreeEntry"), constructor_template); } -NAN_METHOD(GitTreeEntry::New) { - NanScope(); +Handle GitTreeEntry::New(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsExternal()) { - return NanThrowError(String::New("git_tree_entry is required.")); + return ThrowException(Exception::Error(String::New("git_tree_entry is required."))); } - GitTreeEntry* object = new GitTreeEntry((git_tree_entry *) External::Cast(*args[0])->Value()); + GitTreeEntry* object = new GitTreeEntry((git_tree_entry *) External::Unwrap(args[0])); object->Wrap(args.This()); - NanReturnValue(args.This()); + return scope.Close(args.This()); } Handle GitTreeEntry::New(void *raw) { - NanScope(); + HandleScope scope; Handle argv[1] = { External::New((void *)raw) }; - Local instance; - Local constructorHandle = NanPersistentToLocal(constructor_template); - instance = constructorHandle->GetFunction()->NewInstance(1, argv); - return scope.Close(instance); + return scope.Close(GitTreeEntry::constructor_template->NewInstance(1, argv)); } git_tree_entry *GitTreeEntry::GetValue() { @@ -73,8 +71,8 @@ git_tree_entry *GitTreeEntry::GetValue() { /** * @return {String} result */ -NAN_METHOD(GitTreeEntry::Name) { - NanScope(); +Handle GitTreeEntry::Name(const Arguments& args) { + HandleScope scope; const char * result = git_tree_entry_name( @@ -83,14 +81,14 @@ NAN_METHOD(GitTreeEntry::Name) { Handle to; to = String::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Oid} result */ -NAN_METHOD(GitTreeEntry::Oid) { - NanScope(); +Handle GitTreeEntry::Oid(const Arguments& args) { + HandleScope scope; const git_oid * result = git_tree_entry_id( @@ -106,14 +104,14 @@ NAN_METHOD(GitTreeEntry::Oid) { } else { to = Null(); } - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitTreeEntry::Type) { - NanScope(); +Handle GitTreeEntry::Type(const Arguments& args) { + HandleScope scope; git_otype result = git_tree_entry_type( @@ -122,14 +120,14 @@ NAN_METHOD(GitTreeEntry::Type) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } /** * @return {Number} result */ -NAN_METHOD(GitTreeEntry::filemode) { - NanScope(); +Handle GitTreeEntry::filemode(const Arguments& args) { + HandleScope scope; git_filemode_t result = git_tree_entry_filemode( @@ -138,7 +136,7 @@ NAN_METHOD(GitTreeEntry::filemode) { Handle to; to = Number::New(result); - NanReturnValue(to); + return scope.Close(to); } #include "../include/functions/copy.h" @@ -147,31 +145,31 @@ NAN_METHOD(GitTreeEntry::filemode) { * @param {Repository} repo * @param {Object} callback */ -NAN_METHOD(GitTreeEntry::GetObject) { - NanScope(); +Handle GitTreeEntry::GetObject(const Arguments& args) { + HandleScope scope; if (args.Length() == 0 || !args[0]->IsObject()) { - return NanThrowError(String::New("Repository repo is required.")); + return ThrowException(Exception::Error(String::New("Repository repo is required."))); } if (args.Length() == 1 || !args[1]->IsFunction()) { - return NanThrowError(String::New("Callback is required and must be a Function.")); + return ThrowException(Exception::Error(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; - 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->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()); baton->entry = ObjectWrap::Unwrap(args.This())->GetValue(); - NanAssignPersistent(Function, baton->callback, Local::Cast(args[1])); + baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, GetObjectWork, (uv_after_work_cb)GetObjectAfterWork); - NanReturnUndefined(); + return Undefined(); } void GitTreeEntry::GetObjectWork(uv_work_t *req) { @@ -188,7 +186,7 @@ void GitTreeEntry::GetObjectWork(uv_work_t *req) { } void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { - NanScope(); + HandleScope scope; GetObjectBaton *baton = static_cast(req->data); TryCatch try_catch; @@ -201,21 +199,21 @@ void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { } Handle result = to; Handle argv[2] = { - NanNewLocal(Null()), + Local::New(Null()), result }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 2, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); } else { if (baton->error) { Handle argv[1] = { Exception::Error(String::New(baton->error->message)) }; - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 1, argv); + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else { - NanPersistentToLocal(baton->callback)->Call(Context::GetCurrent()->Global(), 0, NULL); + baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL); } } @@ -228,4 +226,4 @@ void GitTreeEntry::GetObjectAfterWork(uv_work_t *req) { delete baton; } -Persistent GitTreeEntry::constructor_template; +Persistent GitTreeEntry::constructor_template; diff --git a/test/nodegit.js b/test/nodegit.js index e8192c6ad..b603e7ae5 100644 --- a/test/nodegit.js +++ b/test/nodegit.js @@ -1,6 +1,5 @@ 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'); @@ -8,38 +7,34 @@ 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); - }); + fs.mkdir('repos',function() { + async.series([ + function empty(cb) { exec('git init repos/empty',function() { cb(); }); }, + function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git repos/workdir',function() { cb(); }); }, + function nonrepo(cb) { + fs.mkdir('repos/nonrepo',function() { + fs.writeFile('repos/nonrepo/file.txt','This is a bogus file',function() { + cb(); + }); + }); + } + ],function() { + 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); - } +exports.setUp = function(cb) { + fs.exists('.reposCache', function(exists) { + if (!exists) { + setupReposCache(function(err) { + cb(); + }); + } + }); }; -for(var i in testFiles) { - var testFile = testFiles[i]; - module.exports[testFile] = require('./'+testFile); -} +Object.keys(testFiles).forEach(function(fileName) { + var testFile = testFiles[fileName] + exports[testFile] = require('./' + testFile); +}); diff --git a/test/tree.js b/test/tree.js index 686dc4c2c..a7c55fef0 100644 --- a/test/tree.js +++ b/test/tree.js @@ -1,6 +1,7 @@ var git = require('../'), rimraf = require('rimraf'), - fs = require('fs'); + fs = require('fs'), + path = require('path'); var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; var fileCount = 512; // Number of blob & blob executabless @@ -36,7 +37,7 @@ exports.insert = function(test) { buffer = new Buffer(text); repo.createBlobFromBuffer(buffer, function(error, blobId) { var builder = tree.builder(); - builder.insert("lib/baz/bar.txt", blobId, git.TreeEntry.FileMode.Blob); + builder.insert(path.join("lib", "baz", "bar.txt"), blobId, git.TreeEntry.FileMode.Blob); builder.write(function(error, treeId) { repo.getTree(treeId, function(error, tree) { var author = git.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60), diff --git a/util/hint-check.js b/util/hint-check.js deleted file mode 100644 index ab71ac549..000000000 --- a/util/hint-check.js +++ /dev/null @@ -1,22 +0,0 @@ -var nodejshint = require('./nodejshint.js').test, - fs = require('fs'), - path = require('path'); - -var files = []; - -['lib', 'test', 'example'].forEach(function(dir) { - console.log(dir); - fs.readdirSync(dir).forEach(function(file) { - if (/\.js$/.test(file)) files.push(path.join(dir, file)); - }); -}); - -nodejshint(files, function(failures) { - console.log(failures, 'failures'); - - if(!files.length) { - process.exit(0); - } else { - process.exit(1); - } -}); diff --git a/util/jshint.js b/util/jshint.js deleted file mode 100755 index f622efd9a..000000000 --- a/util/jshint.js +++ /dev/null @@ -1,3855 +0,0 @@ -/* - * JSHint, by JSHint Community. - * - * Licensed under the same slightly modified MIT license that JSLint is. - * It stops evil-doers everywhere. - * - * JSHint is a derivative work of JSLint: - * - * Copyright (c) 2002 Douglas Crockford (www.JSLint.com) - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * The Software shall be used for Good, not Evil. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * JSHint was forked from 2010-12-16 edition of JSLint. - * - */ - -/* - JSHINT is a global function. It takes two parameters. - - var myResult = JSHINT(source, option); - - The first parameter is either a string or an array of strings. If it is a - string, it will be split on '\n' or '\r'. If it is an array of strings, it - is assumed that each string represents one line. The source can be a - JavaScript text or a JSON text. - - The second parameter is an optional object of options which control the - operation of JSHINT. Most of the options are booleans: They are all - optional and have a default value of false. One of the options, predef, - can be an array of names, which will be used to declare global variables, - or an object whose keys are used as global names, with a boolean value - that determines if they are assignable. - - If it checks out, JSHINT returns true. Otherwise, it returns false. - - If false, you can inspect JSHINT.errors to find out the problems. - JSHINT.errors is an array of objects containing these members: - - { - line : The line (relative to 0) at which the lint was found - character : The character (relative to 0) at which the lint was found - reason : The problem - evidence : The text line in which the problem occurred - raw : The raw message before the details were inserted - a : The first detail - b : The second detail - c : The third detail - d : The fourth detail - } - - If a fatal error was found, a null will be the last element of the - JSHINT.errors array. - - You can request a Function Report, which shows all of the functions - and the parameters and vars that they use. This can be used to find - implied global variables and other problems. The report is in HTML and - can be inserted in an HTML . - - var myReport = JSHINT.report(limited); - - If limited is true, then the report will be limited to only errors. - - You can request a data structure which contains JSHint's results. - - var myData = JSHINT.data(); - - It returns a structure with this form: - - { - errors: [ - { - line: NUMBER, - character: NUMBER, - reason: STRING, - evidence: STRING - } - ], - functions: [ - name: STRING, - line: NUMBER, - last: NUMBER, - param: [ - STRING - ], - closure: [ - STRING - ], - var: [ - STRING - ], - exception: [ - STRING - ], - outer: [ - STRING - ], - unused: [ - STRING - ], - global: [ - STRING - ], - label: [ - STRING - ] - ], - globals: [ - STRING - ], - member: { - STRING: NUMBER - }, - unuseds: [ - { - name: STRING, - line: NUMBER - } - ], - implieds: [ - { - name: STRING, - line: NUMBER - } - ], - urls: [ - STRING - ], - json: BOOLEAN - } - - Empty arrays will not be included. - -*/ - -/*jshint - evil: true, nomen: false, onevar: false, regexp: false, strict: true, boss: true -*/ - -/*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", - "(begin)", "(breakage)", "(context)", "(error)", "(global)", - "(identifier)", "(last)", "(line)", "(loopage)", "(name)", "(onevar)", - "(params)", "(scope)", "(statement)", "(verb)", "*", "+", "++", "-", - "--", "\/", "<", "<=", "==", "===", ">", ">=", $, $$, $A, $F, $H, $R, $break, - $continue, $w, Abstract, Ajax, __filename, __dirname, ActiveXObject, Array, - ArrayBuffer, ArrayBufferView, Autocompleter, Assets, Boolean, Builder, - Buffer, Browser, COM, CScript, Canvas, CustomAnimation, Class, Control, - Chain, Color, Cookie, Core, DataView, Date, Debug, Draggable, Draggables, - Droppables, Document, DomReady, DOMReady, Drag, E, Enumerator, Enumerable, - Element, Elements, Error, Effect, EvalError, Event, Events, FadeAnimation, - Field, Flash, Float32Array, Float64Array, Form, FormField, Frame, Function, - Fx, Group, Hash, HotKey, HTMLElement, HtmlTable, Iframe, IframeShim, Image, - Int16Array, Int32Array, Int8Array, Insertion, InputValidator, JSON, Keyboard, - Locale, LN10, LN2, LOG10E, LOG2E, MAX_VALUE, MIN_VALUE, Mask, Math, MenuItem, - MoveAnimation, MooTools, Native, NEGATIVE_INFINITY, Number, Object, - ObjectRange, Option, Options, OverText, PI, POSITIVE_INFINITY, - PeriodicalExecuter, Point, Position, Prototype, RangeError, Rectangle, - ReferenceError, RegExp, ResizeAnimation, Request, RotateAnimation, SQRT1_2, - SQRT2, ScrollBar, Scriptaculous, Scroller, Slick, Slider, Selector, String, - Style, SyntaxError, Sortable, Sortables, SortableObserver, Sound, Spinner, - System, Swiff, Text, TextArea, Template, Timer, Tips, Type, TypeError, - Toggle, Try, URI, URIError, URL, VBArray, WScript, Web, Window, XMLDOM, - XMLHttpRequest, XPathEvaluator, XPathException, XPathExpression, - XPathNamespace, XPathNSResolver, XPathResult, "\\", a, addEventListener, - address, alert, apply, applicationCache, arguments, arity, asi, b, bitwise, - block, blur, boolOptions, boss, browser, c, call, callee, caller, cases, - charAt, charCodeAt, character, clearInterval, clearTimeout, close, closed, - closure, comment, condition, confirm, console, constructor, content, couch, - create, css, curly, d, data, datalist, dd, debug, decodeURI, - decodeURIComponent, defaultStatus, defineClass, deserialize, devel, - document, edition, else, emit, encodeURI, encodeURIComponent, entityify, - eqeqeq, eqnull, errors, es5, escape, eval, event, evidence, evil, ex, - exception, exec, exps, expr, exports, FileReader, first, floor, focus, - forin, fragment, frames, from, fromCharCode, fud, funct, function, functions, - g, gc, getComputedStyle, getRow, GLOBAL, global, globals, globalstrict, - hasOwnProperty, help, history, i, id, identifier, immed, implieds, - include, indent, indexOf, init, ins, instanceOf, isAlpha, - isApplicationRunning, isArray, isDigit, isFinite, isNaN, join, jshint, - JSHINT, json, jquery, jQuery, keys, label, labelled, last, laxbreak, - latedef, lbp, led, left, length, line, load, loadClass, localStorage, - location, log, loopfunc, m, match, maxerr, maxlen, member,message, meta, - module, moveBy, moveTo, mootools, name, navigator, new, newcap, noarg, - node, noempty, nomen, nonew, nud, onbeforeunload, onblur, onerror, onevar, - onfocus, onload, onresize, onunload, open, openDatabase, openURL, opener, - opera, outer, param, parent, parseFloat, parseInt, passfail, plusplus, - predef, print, process, prompt, prototype, prototypejs, push, quit, range, - raw, reach, reason, regexp, readFile, readUrl, removeEventListener, replace, - report, require, reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, - respond, rhino, right, runCommand, scroll, screen, scrollBy, scrollTo, - scrollbar, search, seal, send, serialize, setInterval, setTimeout, shift, - slice, sort,spawn, split, stack, status, start, strict, sub, substr, supernew, - shadow, supplant, sum, sync, test, toLowerCase, toString, toUpperCase, toint32, - token, top, type, typeOf, Uint16Array, Uint32Array, Uint8Array, undef, - unused, urls, value, valueOf, var, version, WebSocket, white, window, Worker -*/ - -/*global exports: false */ - -// We build the application inside a function so that we produce only a single -// global variable. That function will be invoked immediately, and its return -// value is the JSHINT function itself. - -var JSHINT = (function () { - "use strict"; - - var anonname, // The guessed name for anonymous functions. - -// These are operators that should not be used with the ! operator. - - bang = { - '<' : true, - '<=' : true, - '==' : true, - '===': true, - '!==': true, - '!=' : true, - '>' : true, - '>=' : true, - '+' : true, - '-' : true, - '*' : true, - '/' : true, - '%' : true - }, - -// These are the JSHint boolean options. - - boolOptions = { - asi : true, // if automatic semicolon insertion should be tolerated - bitwise : true, // if bitwise operators should not be allowed - boss : true, // if advanced usage of assignments should be allowed - browser : true, // if the standard browser globals should be predefined - couch : true, // if CouchDB globals should be predefined - curly : true, // if curly braces around blocks should be required (even in if/for/while) - debug : true, // if debugger statements should be allowed - devel : true, // if logging globals should be predefined (console, alert, etc.) - eqeqeq : true, // if === should be required - eqnull : true, // if == null comparisons should be tolerated - es5 : true, // if ES5 syntax should be allowed - evil : true, // if eval should be allowed - expr : true, // if ExpressionStatement should be allowed as Programs - forin : true, // if for in statements must filter - globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict') - immed : true, // if immediate invocations must be wrapped in parens - jquery : true, // if jQuery globals should be predefined - latedef : true, // if the use before definition should not be tolerated - laxbreak : true, // if line breaks should not be checked - loopfunc : true, // if functions should be allowed to be defined within loops - mootools : true, // if MooTools globals should be predefined - newcap : true, // if constructor names must be capitalized - noarg : true, // if arguments.caller and arguments.callee should be disallowed - node : true, // if the Node.js environment globals should be predefined - noempty : true, // if empty blocks should be disallowed - nonew : true, // if using `new` for side-effects should be disallowed - nomen : true, // if names should be checked - onevar : true, // if only one var statement per function should be allowed - passfail : true, // if the scan should stop on first error - plusplus : true, // if increment/decrement should not be allowed - prototypejs : true, // if Prototype and Scriptaculous globals shoudl be predefined - regexp : true, // if the . should not be allowed in regexp literals - rhino : true, // if the Rhino environment globals should be predefined - undef : true, // if variables should be declared before used - shadow : true, // if variable shadowing should be tolerated - strict : true, // require the "use strict"; pragma - sub : true, // if all forms of subscript notation are tolerated - supernew : true, // if `new function () { ... };` and `new Object;` should be tolerated - white : true // if strict whitespace rules apply - }, - -// browser contains a set of global names which are commonly provided by a -// web browser environment. - - browser = { - ArrayBuffer : false, - ArrayBufferView : false, - addEventListener: false, - applicationCache: false, - blur : false, - clearInterval : false, - clearTimeout : false, - close : false, - closed : false, - DataView : false, - defaultStatus : false, - document : false, - event : false, - FileReader : false, - Float32Array : false, - Float64Array : false, - focus : false, - frames : false, - getComputedStyle: false, - HTMLElement : false, - history : false, - Int16Array : false, - Int32Array : false, - Int8Array : false, - Image : false, - length : false, - localStorage : false, - location : false, - moveBy : false, - moveTo : false, - name : false, - navigator : false, - onbeforeunload : true, - onblur : true, - onerror : true, - onfocus : true, - onload : true, - onresize : true, - onunload : true, - open : false, - openDatabase : false, - opener : false, - Option : false, - parent : false, - print : false, - removeEventListener: false, - resizeBy : false, - resizeTo : false, - screen : false, - scroll : false, - scrollBy : false, - scrollTo : false, - setInterval : false, - setTimeout : false, - status : false, - top : false, - Uint16Array : false, - Uint32Array : false, - Uint8Array : false, - WebSocket : false, - window : false, - Worker : false, - XMLHttpRequest : false, - XPathEvaluator : false, - XPathException : false, - XPathExpression : false, - XPathNamespace : false, - XPathNSResolver : false, - XPathResult : false - }, - - couch = { - "require" : false, - respond : false, - getRow : false, - emit : false, - send : false, - start : false, - sum : false, - log : false, - exports : false, - module : false - }, - - devel = { - alert : false, - confirm : false, - console : false, - Debug : false, - opera : false, - prompt : false - }, - - escapes = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '/' : '\\/', - '\\': '\\\\' - }, - - funct, // The current function - - functionicity = [ - 'closure', 'exception', 'global', 'label', - 'outer', 'unused', 'var' - ], - - functions, // All of the functions - - global, // The global scope - implied, // Implied globals - inblock, - indent, - jsonmode, - - jquery = { - '$' : false, - jQuery : false - }, - - lines, - lookahead, - member, - membersOnly, - - mootools = { - '$' : false, - '$$' : false, - Assets : false, - Browser : false, - Chain : false, - Class : false, - Color : false, - Cookie : false, - Core : false, - Document : false, - DomReady : false, - DOMReady : false, - Drag : false, - Element : false, - Elements : false, - Event : false, - Events : false, - Fx : false, - Group : false, - Hash : false, - HtmlTable : false, - Iframe : false, - IframeShim : false, - InputValidator : false, - instanceOf : false, - Keyboard : false, - Locale : false, - Mask : false, - MooTools : false, - Native : false, - Options : false, - OverText : false, - Request : false, - Scroller : false, - Slick : false, - Slider : false, - Sortables : false, - Spinner : false, - Swiff : false, - Tips : false, - Type : false, - typeOf : false, - URI : false, - Window : false - }, - - nexttoken, - - node = { - __filename : false, - __dirname : false, - exports : false, - Buffer : false, - GLOBAL : false, - global : false, - module : false, - process : false, - require : false - }, - - noreach, - option, - predefined, // Global variables defined by option - prereg, - prevtoken, - - prototypejs = { - '$' : false, - '$$' : false, - '$A' : false, - '$F' : false, - '$H' : false, - '$R' : false, - '$break' : false, - '$continue' : false, - '$w' : false, - Abstract : false, - Ajax : false, - Class : false, - Enumerable : false, - Element : false, - Event : false, - Field : false, - Form : false, - Hash : false, - Insertion : false, - ObjectRange : false, - PeriodicalExecuter: false, - Position : false, - Prototype : false, - Selector : false, - Template : false, - Toggle : false, - Try : false, - Autocompleter : false, - Builder : false, - Control : false, - Draggable : false, - Draggables : false, - Droppables : false, - Effect : false, - Sortable : false, - SortableObserver : false, - Sound : false, - Scriptaculous : false - }, - - rhino = { - defineClass : false, - deserialize : false, - gc : false, - help : false, - load : false, - loadClass : false, - print : false, - quit : false, - readFile : false, - readUrl : false, - runCommand : false, - seal : false, - serialize : false, - spawn : false, - sync : false, - toint32 : false, - version : false - }, - - scope, // The current scope - src, - stack, - -// standard contains the global names that are provided by the -// ECMAScript standard. - - standard = { - Array : false, - Boolean : false, - Date : false, - decodeURI : false, - decodeURIComponent : false, - encodeURI : false, - encodeURIComponent : false, - Error : false, - 'eval' : false, - EvalError : false, - Function : false, - hasOwnProperty : false, - isFinite : false, - isNaN : false, - JSON : false, - Math : false, - Number : false, - Object : false, - parseInt : false, - parseFloat : false, - RangeError : false, - ReferenceError : false, - RegExp : false, - String : false, - SyntaxError : false, - TypeError : false, - URIError : false - }, - - standard_member = { - E : true, - LN2 : true, - LN10 : true, - LOG2E : true, - LOG10E : true, - MAX_VALUE : true, - MIN_VALUE : true, - NEGATIVE_INFINITY : true, - PI : true, - POSITIVE_INFINITY : true, - SQRT1_2 : true, - SQRT2 : true - }, - - strict_mode, - syntax = {}, - tab, - token, - urls, - warnings, - -// Regular expressions. Some of these are stupidly long. - -// unsafe comment or string - ax = /@cc|<\/?|script|\]\s*\]|<\s*!|</i, -// unsafe characters that are silently deleted by one or more browsers - cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, -// token - tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jshint|jslint|members?|global)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/, -// characters in strings that need escapement - nx = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, - nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, -// star slash - lx = /\*\/|\/\*/, -// identifier - ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/, -// javascript url - jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i, -// catches /* falls through */ comments - ft = /^\s*\/\*\s*falls\sthrough\s*\*\/\s*$/; - - function F() {} // Used by Object.create - - function is_own(object, name) { - -// The object.hasOwnProperty method fails when the property under consideration -// is named 'hasOwnProperty'. So we have to use this more convoluted form. - - return Object.prototype.hasOwnProperty.call(object, name); - } - -// Provide critical ES5 functions to ES3. - - if (typeof Array.isArray !== 'function') { - Array.isArray = function (o) { - return Object.prototype.toString.apply(o) === '[object Array]'; - }; - } - - if (typeof Object.create !== 'function') { - Object.create = function (o) { - F.prototype = o; - return new F(); - }; - } - - if (typeof Object.keys !== 'function') { - Object.keys = function (o) { - var a = [], k; - for (k in o) { - if (is_own(o, k)) { - a.push(k); - } - } - return a; - }; - } - -// Non standard methods - - if (typeof String.prototype.entityify !== 'function') { - String.prototype.entityify = function () { - return this - .replace(/&/g, '&') - .replace(//g, '>'); - }; - } - - if (typeof String.prototype.isAlpha !== 'function') { - String.prototype.isAlpha = function () { - return (this >= 'a' && this <= 'z\uffff') || - (this >= 'A' && this <= 'Z\uffff'); - }; - } - - if (typeof String.prototype.isDigit !== 'function') { - String.prototype.isDigit = function () { - return (this >= '0' && this <= '9'); - }; - } - - if (typeof String.prototype.supplant !== 'function') { - String.prototype.supplant = function (o) { - return this.replace(/\{([^{}]*)\}/g, function (a, b) { - var r = o[b]; - return typeof r === 'string' || typeof r === 'number' ? r : a; - }); - }; - } - - if (typeof String.prototype.name !== 'function') { - String.prototype.name = function () { - -// If the string looks like an identifier, then we can return it as is. -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can simply slap some quotes around it. -// Otherwise we must also replace the offending characters with safe -// sequences. - - if (ix.test(this)) { - return this; - } - if (nx.test(this)) { - return '"' + this.replace(nxg, function (a) { - var c = escapes[a]; - if (c) { - return c; - } - return '\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4); - }) + '"'; - } - return '"' + this + '"'; - }; - } - - - function combine(t, o) { - var n; - for (n in o) { - if (is_own(o, n)) { - t[n] = o[n]; - } - } - } - - function assume() { - if (option.couch) - combine(predefined, couch); - - if (option.rhino) - combine(predefined, rhino); - - if (option.prototypejs) - combine(predefined, prototypejs); - - if (option.node) - combine(predefined, node); - - if (option.devel) - combine(predefined, devel); - - if (option.browser) - combine(predefined, browser); - - if (option.jquery) - combine(predefined, jquery); - - if (option.mootools) - combine(predefined, mootools); - - if (option.globalstrict) - option.strict = true; - } - - -// Produce an error warning. - - function quit(m, l, ch) { - throw { - name: 'JSHintError', - line: l, - character: ch, - message: m + " (" + Math.floor((l / lines.length) * 100) + - "% scanned)." - }; - } - - function warning(m, t, a, b, c, d) { - var ch, l, w; - t = t || nexttoken; - if (t.id === '(end)') { // `~ - t = token; - } - l = t.line || 0; - ch = t.from || 0; - w = { - id: '(error)', - raw: m, - evidence: lines[l - 1] || '', - line: l, - character: ch, - a: a, - b: b, - c: c, - d: d - }; - w.reason = m.supplant(w); - JSHINT.errors.push(w); - if (option.passfail) { - quit('Stopping. ', l, ch); - } - warnings += 1; - if (warnings >= option.maxerr) { - quit("Too many errors.", l, ch); - } - return w; - } - - function warningAt(m, l, ch, a, b, c, d) { - return warning(m, { - line: l, - from: ch - }, a, b, c, d); - } - - function error(m, t, a, b, c, d) { - var w = warning(m, t, a, b, c, d); - quit("Stopping, unable to continue.", w.line, w.character); - } - - function errorAt(m, l, ch, a, b, c, d) { - return error(m, { - line: l, - from: ch - }, a, b, c, d); - } - - - -// lexical analysis and token construction - - var lex = (function lex() { - var character, from, line, s; - -// Private lex methods - - function nextLine() { - var at, - tw; // trailing whitespace check - - if (line >= lines.length) - return false; - - character = 1; - s = lines[line]; - line += 1; - at = s.search(/ \t/); - - if (at >= 0) - warningAt("Mixed spaces and tabs.", line, at + 1); - - s = s.replace(/\t/g, tab); - at = s.search(cx); - - if (at >= 0) - warningAt("Unsafe character.", line, at); - - if (option.maxlen && option.maxlen < s.length) - warningAt("Line too long.", line, s.length); - - // Check for trailing whitespaces - tw = s.search(/\s+$/); - if (option.white && ~tw) - warningAt("Trailing whitespace.", line, tw); - - return true; - } - -// Produce a token object. The token inherits from a syntax symbol. - - function it(type, value) { - var i, t; - if (type === '(color)' || type === '(range)') { - t = {type: type}; - } else if (type === '(punctuator)' || - (type === '(identifier)' && is_own(syntax, value))) { - t = syntax[value] || syntax['(error)']; - } else { - t = syntax[type]; - } - t = Object.create(t); - if (type === '(string)' || type === '(range)') { - if (jx.test(value)) { - warningAt("Script URL.", line, from); - } - } - if (type === '(identifier)') { - t.identifier = true; - if (value === '__iterator__' || value === '__proto__') { - errorAt("Reserved name '{a}'.", - line, from, value); - } else if (option.nomen && - (value.charAt(0) === '_' || - value.charAt(value.length - 1) === '_')) { - warningAt("Unexpected {a} in '{b}'.", line, from, - "dangling '_'", value); - } - } - t.value = value; - t.line = line; - t.character = character; - t.from = from; - i = t.id; - if (i !== '(endline)') { - prereg = i && - (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) || - i === 'return'); - } - return t; - } - -// Public lex methods - - return { - init: function (source) { - if (typeof source === 'string') { - lines = source - .replace(/\r\n/g, '\n') - .replace(/\r/g, '\n') - .split('\n'); - } else { - lines = source; - } - - // If the first line is a shebang (#!), make it a blank and move on. - // Shebangs are used by Node scripts. - if (lines[0] && lines[0].substr(0, 2) == '#!') - lines[0] = ''; - - line = 0; - nextLine(); - from = 1; - }, - - range: function (begin, end) { - var c, value = ''; - from = character; - if (s.charAt(0) !== begin) { - errorAt("Expected '{a}' and instead saw '{b}'.", - line, character, begin, s.charAt(0)); - } - for (;;) { - s = s.slice(1); - character += 1; - c = s.charAt(0); - switch (c) { - case '': - errorAt("Missing '{a}'.", line, character, c); - break; - case end: - s = s.slice(1); - character += 1; - return it('(range)', value); - case '\\': - warningAt("Unexpected '{a}'.", line, character, c); - } - value += c; - } - - }, - -// token -- this is called by advance to get the next token. - - token: function () { - var b, c, captures, d, depth, high, i, l, low, q, t; - - function match(x) { - var r = x.exec(s), r1; - if (r) { - l = r[0].length; - r1 = r[1]; - c = r1.charAt(0); - s = s.substr(l); - from = character + l - r1.length; - character += l; - return r1; - } - } - - function string(x) { - var c, j, r = ''; - - if (jsonmode && x !== '"') { - warningAt("Strings must use doublequote.", - line, character); - } - - function esc(n) { - var i = parseInt(s.substr(j + 1, n), 16); - j += n; - if (i >= 32 && i <= 126 && - i !== 34 && i !== 92 && i !== 39) { - warningAt("Unnecessary escapement.", line, character); - } - character += n; - c = String.fromCharCode(i); - } - j = 0; - for (;;) { - while (j >= s.length) { - j = 0; - if (!nextLine()) { - errorAt("Unclosed string.", line, from); - } - } - c = s.charAt(j); - if (c === x) { - character += 1; - s = s.substr(j + 1); - return it('(string)', r, x); - } - if (c < ' ') { - if (c === '\n' || c === '\r') { - break; - } - warningAt("Control character in string: {a}.", - line, character + j, s.slice(0, j)); - } else if (c === '\\') { - j += 1; - character += 1; - c = s.charAt(j); - switch (c) { - case '\\': - case '"': - case '/': - break; - case '\'': - if (jsonmode) { - warningAt("Avoid \\'.", line, character); - } - break; - case 'b': - c = '\b'; - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'u': - esc(4); - break; - case 'v': - if (jsonmode) { - warningAt("Avoid \\v.", line, character); - } - c = '\v'; - break; - case 'x': - if (jsonmode) { - warningAt("Avoid \\x-.", line, character); - } - esc(2); - break; - default: - warningAt("Bad escapement.", line, character); - } - } - r += c; - character += 1; - j += 1; - } - } - - for (;;) { - if (!s) { - return it(nextLine() ? '(endline)' : '(end)', ''); - } - t = match(tx); - if (!t) { - t = ''; - c = ''; - while (s && s < '!') { - s = s.substr(1); - } - if (s) { - errorAt("Unexpected '{a}'.", line, character, s.substr(0, 1)); - } - } else { - - // identifier - - if (c.isAlpha() || c === '_' || c === '$') { - return it('(identifier)', t); - } - - // number - - if (c.isDigit()) { - if (!isFinite(Number(t))) { - warningAt("Bad number '{a}'.", - line, character, t); - } - if (s.substr(0, 1).isAlpha()) { - warningAt("Missing space after '{a}'.", - line, character, t); - } - if (c === '0') { - d = t.substr(1, 1); - if (d.isDigit()) { - if (token.id !== '.') { - warningAt("Don't use extra leading zeros '{a}'.", - line, character, t); - } - } else if (jsonmode && (d === 'x' || d === 'X')) { - warningAt("Avoid 0x-. '{a}'.", - line, character, t); - } - } - if (t.substr(t.length - 1) === '.') { - warningAt( -"A trailing decimal point can be confused with a dot '{a}'.", line, character, t); - } - return it('(number)', t); - } - switch (t) { - - // string - - case '"': - case "'": - return string(t); - - // // comment - - case '//': - if (src) { - warningAt("Unexpected comment.", line, character); - } - s = ''; - token.comment = true; - break; - - // /* comment - - case '/*': - if (src) { - warningAt("Unexpected comment.", line, character); - } - for (;;) { - i = s.search(lx); - if (i >= 0) { - break; - } - if (!nextLine()) { - errorAt("Unclosed comment.", line, character); - } - } - character += i + 2; - if (s.substr(i, 1) === '/') { - errorAt("Nested comment.", line, character); - } - s = s.substr(i + 2); - token.comment = true; - break; - - // /*members /*jshint /*global - - case '/*members': - case '/*member': - case '/*jshint': - case '/*jslint': - case '/*global': - case '*/': - return { - value: t, - type: 'special', - line: line, - character: character, - from: from - }; - - case '': - break; - // / - case '/': - if (token.id === '/=') { - errorAt( -"A regular expression literal can be confused with '/='.", line, from); - } - if (prereg) { - depth = 0; - captures = 0; - l = 0; - for (;;) { - b = true; - c = s.charAt(l); - l += 1; - switch (c) { - case '': - errorAt("Unclosed regular expression.", - line, from); - return; - case '/': - if (depth > 0) { - warningAt("Unescaped '{a}'.", - line, from + l, '/'); - } - c = s.substr(0, l - 1); - q = { - g: true, - i: true, - m: true - }; - while (q[s.charAt(l)] === true) { - q[s.charAt(l)] = false; - l += 1; - } - character += l; - s = s.substr(l); - q = s.charAt(0); - if (q === '/' || q === '*') { - errorAt("Confusing regular expression.", - line, from); - } - return it('(regexp)', c); - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt( -"Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt( -"Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - break; - case '(': - depth += 1; - b = false; - if (s.charAt(l) === '?') { - l += 1; - switch (s.charAt(l)) { - case ':': - case '=': - case '!': - l += 1; - break; - default: - warningAt( -"Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l)); - } - } else { - captures += 1; - } - break; - case '|': - b = false; - break; - case ')': - if (depth === 0) { - warningAt("Unescaped '{a}'.", - line, from + l, ')'); - } else { - depth -= 1; - } - break; - case ' ': - q = 1; - while (s.charAt(l) === ' ') { - l += 1; - q += 1; - } - if (q > 1) { - warningAt( -"Spaces are hard to count. Use {{a}}.", line, from + l, q); - } - break; - case '[': - c = s.charAt(l); - if (c === '^') { - l += 1; - if (option.regexp) { - warningAt("Insecure '{a}'.", - line, from + l, c); - } else if (s.charAt(l) === ']') { - errorAt("Unescaped '{a}'.", - line, from + l, '^'); - } - } - q = false; - if (c === ']') { - warningAt("Empty class.", line, - from + l - 1); - q = true; - } -klass: do { - c = s.charAt(l); - l += 1; - switch (c) { - case '[': - case '^': - warningAt("Unescaped '{a}'.", - line, from + l, c); - q = true; - break; - case '-': - if (q) { - q = false; - } else { - warningAt("Unescaped '{a}'.", - line, from + l, '-'); - q = true; - } - break; - case ']': - if (!q) { - warningAt("Unescaped '{a}'.", - line, from + l - 1, '-'); - } - break klass; - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt( -"Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt( -"Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - q = true; - break; - case '/': - warningAt("Unescaped '{a}'.", - line, from + l - 1, '/'); - q = true; - break; - case '<': - q = true; - break; - default: - q = true; - } - } while (c); - break; - case '.': - if (option.regexp) { - warningAt("Insecure '{a}'.", line, - from + l, c); - } - break; - case ']': - case '?': - case '{': - case '}': - case '+': - case '*': - warningAt("Unescaped '{a}'.", line, - from + l, c); - } - if (b) { - switch (s.charAt(l)) { - case '?': - case '+': - case '*': - l += 1; - if (s.charAt(l) === '?') { - l += 1; - } - break; - case '{': - l += 1; - c = s.charAt(l); - if (c < '0' || c > '9') { - warningAt( -"Expected a number and instead saw '{a}'.", line, from + l, c); - } - l += 1; - low = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - low = +c + (low * 10); - } - high = low; - if (c === ',') { - l += 1; - high = Infinity; - c = s.charAt(l); - if (c >= '0' && c <= '9') { - l += 1; - high = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - high = +c + (high * 10); - } - } - } - if (s.charAt(l) !== '}') { - warningAt( -"Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c); - } else { - l += 1; - } - if (s.charAt(l) === '?') { - l += 1; - } - if (low > high) { - warningAt( -"'{a}' should not be greater than '{b}'.", line, from + l, low, high); - } - } - } - } - c = s.substr(0, l - 1); - character += l; - s = s.substr(l); - return it('(regexp)', c); - } - return it('(punctuator)', t); - - // punctuator - - case '#': - return it('(punctuator)', t); - default: - return it('(punctuator)', t); - } - } - } - } - }; - }()); - - - function addlabel(t, type) { - - if (t === 'hasOwnProperty') { - warning("'hasOwnProperty' is a really bad name."); - } - -// Define t in the current function in the current scope. - - if (is_own(funct, t) && !funct['(global)']) { - if (funct[t] === true) { - if (option.latedef) - warning("'{a}' was used before it was defined.", nexttoken, t); - } else { - if (!option.shadow) - warning("'{a}' is already defined.", nexttoken, t); - } - } - - funct[t] = type; - if (funct['(global)']) { - global[t] = funct; - if (is_own(implied, t)) { - if (option.latedef) - warning("'{a}' was used before it was defined.", nexttoken, t); - delete implied[t]; - } - } else { - scope[t] = funct; - } - } - - - function doOption() { - var b, obj, filter, o = nexttoken.value, t, v; - switch (o) { - case '*/': - error("Unbegun comment."); - break; - case '/*members': - case '/*member': - o = '/*members'; - if (!membersOnly) { - membersOnly = {}; - } - obj = membersOnly; - break; - case '/*jshint': - case '/*jslint': - obj = option; - filter = boolOptions; - break; - case '/*global': - obj = predefined; - break; - default: - error("What?"); - } - t = lex.token(); -loop: for (;;) { - for (;;) { - if (t.type === 'special' && t.value === '*/') { - break loop; - } - if (t.id !== '(endline)' && t.id !== ',') { - break; - } - t = lex.token(); - } - if (t.type !== '(string)' && t.type !== '(identifier)' && - o !== '/*members') { - error("Bad option.", t); - } - v = lex.token(); - if (v.id === ':') { - v = lex.token(); - if (obj === membersOnly) { - error("Expected '{a}' and instead saw '{b}'.", - t, '*/', ':'); - } - if (t.value === 'indent' && (o === '/*jshint' || o === '/*jslint')) { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.white = true; - obj.indent = b; - } else if (t.value === 'maxerr' && (o === '/*jshint' || o === '/*jslint')) { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxerr = b; - } else if (t.value === 'maxlen' && (o === '/*jshint' || o === '/*jslint')) { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxlen = b; - } else if (v.value === 'true') { - obj[t.value] = true; - } else if (v.value === 'false') { - obj[t.value] = false; - } else { - error("Bad option value.", v); - } - t = lex.token(); - } else { - if (o === '/*jshint' || o === '/*jslint') { - error("Missing option value.", t); - } - obj[t.value] = false; - t = v; - } - } - if (filter) { - assume(); - } - } - - -// We need a peek function. If it has an argument, it peeks that much farther -// ahead. It is used to distinguish -// for ( var i in ... -// from -// for ( var i = ... - - function peek(p) { - var i = p || 0, j = 0, t; - - while (j <= i) { - t = lookahead[j]; - if (!t) { - t = lookahead[j] = lex.token(); - } - j += 1; - } - return t; - } - - - -// Produce the next token. It looks for programming errors. - - function advance(id, t) { - switch (token.id) { - case '(number)': - if (nexttoken.id === '.') { - warning("A dot following a number can be confused with a decimal point.", token); - } - break; - case '-': - if (nexttoken.id === '-' || nexttoken.id === '--') { - warning("Confusing minusses."); - } - break; - case '+': - if (nexttoken.id === '+' || nexttoken.id === '++') { - warning("Confusing plusses."); - } - break; - } - if (token.type === '(string)' || token.identifier) { - anonname = token.value; - } - - if (id && nexttoken.id !== id) { - if (t) { - if (nexttoken.id === '(end)') { - warning("Unmatched '{a}'.", t, t.id); - } else { - warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", - nexttoken, id, t.id, t.line, nexttoken.value); - } - } else if (nexttoken.type !== '(identifier)' || - nexttoken.value !== id) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, id, nexttoken.value); - } - } - prevtoken = token; - token = nexttoken; - for (;;) { - nexttoken = lookahead.shift() || lex.token(); - if (nexttoken.id === '(end)' || nexttoken.id === '(error)') { - return; - } - if (nexttoken.type === 'special') { - doOption(); - } else { - if (nexttoken.id !== '(endline)') { - break; - } - } - } - } - - -// This is the heart of JSHINT, the Pratt parser. In addition to parsing, it -// is looking for ad hoc lint patterns. We add .fud to Pratt's model, which is -// like .nud except that it is only used on the first token of a statement. -// Having .fud makes it much easier to define statement-oriented languages like -// JavaScript. I retained Pratt's nomenclature. - -// .nud Null denotation -// .fud First null denotation -// .led Left denotation -// lbp Left binding power -// rbp Right binding power - -// They are elements of the parsing method called Top Down Operator Precedence. - - function expression(rbp, initial) { - var left, isArray = false; - - if (nexttoken.id === '(end)') - error("Unexpected early end of program.", token); - - advance(); - if (initial) { - anonname = 'anonymous'; - funct['(verb)'] = token.value; - } - if (initial === true && token.fud) { - left = token.fud(); - } else { - if (token.nud) { - left = token.nud(); - } else { - if (nexttoken.type === '(number)' && token.id === '.') { - warning("A leading decimal point can be confused with a dot: '.{a}'.", - token, nexttoken.value); - advance(); - return token; - } else { - error("Expected an identifier and instead saw '{a}'.", - token, token.id); - } - } - while (rbp < nexttoken.lbp) { - isArray = token.value == 'Array'; - advance(); - if (isArray && token.id == '(' && nexttoken.id == ')') - warning("Use the array literal notation [].", token); - if (token.led) { - left = token.led(left); - } else { - error("Expected an operator and instead saw '{a}'.", - token, token.id); - } - } - } - return left; - } - - -// Functions for conformance of style. - - function adjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white) { - if (left.character !== right.from && left.line === right.line) { - warning("Unexpected space after '{a}'.", right, left.value); - } - } - } - - function nobreak(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white && (left.character !== right.from || left.line !== right.line)) { - warning("Unexpected space before '{a}'.", right, right.value); - } - } - - function nospace(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white && !left.comment) { - if (left.line === right.line) { - adjacent(left, right); - } - } - } - - function nonadjacent(left, right) { - if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.line === right.line && left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function nobreaknonadjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (!option.laxbreak && left.line !== right.line) { - warning("Bad line breaking before '{a}'.", right, right.id); - } else if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function indentation(bias) { - var i; - if (option.white && nexttoken.id !== '(end)') { - i = indent + (bias || 0); - if (nexttoken.from !== i) { - warning( -"Expected '{a}' to have an indentation at {b} instead at {c}.", - nexttoken, nexttoken.value, i, nexttoken.from); - } - } - } - - function nolinebreak(t) { - t = t || token; - if (t.line !== nexttoken.line) { - warning("Line breaking error '{a}'.", t, t.value); - } - } - - - function comma() { - if (token.line !== nexttoken.line) { - if (!option.laxbreak) { - warning("Bad line breaking before '{a}'.", token, nexttoken.id); - } - } else if (token.character !== nexttoken.from && option.white) { - warning("Unexpected space after '{a}'.", nexttoken, token.value); - } - advance(','); - nonadjacent(token, nexttoken); - } - - -// Functional constructors for making the symbols that will be inherited by -// tokens. - - function symbol(s, p) { - var x = syntax[s]; - if (!x || typeof x !== 'object') { - syntax[s] = x = { - id: s, - lbp: p, - value: s - }; - } - return x; - } - - - function delim(s) { - return symbol(s, 0); - } - - - function stmt(s, f) { - var x = delim(s); - x.identifier = x.reserved = true; - x.fud = f; - return x; - } - - - function blockstmt(s, f) { - var x = stmt(s, f); - x.block = true; - return x; - } - - - function reserveName(x) { - var c = x.id.charAt(0); - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - x.identifier = x.reserved = true; - } - return x; - } - - - function prefix(s, f) { - var x = symbol(s, 150); - reserveName(x); - x.nud = (typeof f === 'function') ? f : function () { - this.right = expression(150); - this.arity = 'unary'; - if (this.id === '++' || this.id === '--') { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!this.right.identifier || this.right.reserved) && - this.right.id !== '.' && this.right.id !== '[') { - warning("Bad operand.", this); - } - } - return this; - }; - return x; - } - - - function type(s, f) { - var x = delim(s); - x.type = s; - x.nud = f; - return x; - } - - - function reserve(s, f) { - var x = type(s, f); - x.identifier = x.reserved = true; - return x; - } - - - function reservevar(s, v) { - return reserve(s, function () { - if (typeof v === 'function') { - v(this); - } - return this; - }); - } - - - function infix(s, f, p, w) { - var x = symbol(s, p); - reserveName(x); - x.led = function (left) { - if (!w) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - } - if (typeof f === 'function') { - return f(left, this); - } else { - this.left = left; - this.right = expression(p); - return this; - } - }; - return x; - } - - - function relation(s, f) { - var x = symbol(s, 100); - x.led = function (left) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - var right = expression(100); - if ((left && left.id === 'NaN') || (right && right.id === 'NaN')) { - warning("Use the isNaN function to compare with NaN.", this); - } else if (f) { - f.apply(this, [left, right]); - } - if (left.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - if (right.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - this.left = left; - this.right = right; - return this; - }; - return x; - } - - - function isPoorRelation(node) { - return node && - ((node.type === '(number)' && +node.value === 0) || - (node.type === '(string)' && node.value === '') || - (node.type === 'null' && !option.eqnull) || - node.type === 'true' || - node.type === 'false' || - node.type === 'undefined'); - } - - - function assignop(s, f) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - var l; - that.left = left; - if (predefined[left.value] === false && - scope[left.value]['(global)'] === true) { - warning("Read only.", left); - } else if (left['function']) { - warning("'{a}' is a function.", left, left.value); - } - if (left) { - if (left.id === '.' || left.id === '[') { - if (!left.left || left.left.value === 'arguments') { - warning('Bad assignment.', that); - } - that.right = expression(19); - return that; - } else if (left.identifier && !left.reserved) { - if (funct[left.value] === 'exception') { - warning("Do not assign to the exception parameter.", left); - } - that.right = expression(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment and instead saw a function invocation.", - token); - } - } - error("Bad assignment.", that); - }, 20); - } - - - function bitwise(s, f, p) { - var x = symbol(s, p); - reserveName(x); - x.led = (typeof f === 'function') ? f : function (left) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", this, this.id); - } - this.left = left; - this.right = expression(p); - return this; - }; - return x; - } - - - function bitwiseassignop(s) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", that, that.id); - } - nonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - if (left) { - if (left.id === '.' || left.id === '[' || - (left.identifier && !left.reserved)) { - expression(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment, and instead saw a function invocation.", - token); - } - return that; - } - error("Bad assignment.", that); - }, 20); - } - - - function suffix(s, f) { - var x = symbol(s, 150); - x.led = function (left) { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!left.identifier || left.reserved) && - left.id !== '.' && left.id !== '[') { - warning("Bad operand.", this); - } - this.left = left; - return this; - }; - return x; - } - - - // fnparam means that this identifier is being defined as a function - // argument (see identifier()) - function optionalidentifier(fnparam) { - if (nexttoken.identifier) { - advance(); - if (token.reserved && !option.es5) { - // `undefined` as a function param is a common pattern to protect - // against the case when somebody does `undefined = true` and - // help with minification. More info: https://gist.github.com/315916 - if (!fnparam || token.value != 'undefined') { - warning("Expected an identifier and instead saw '{a}' (a reserved word).", - token, token.id); - } - } - return token.value; - } - } - - // fnparam means that this identifier is being defined as a function - // argument - function identifier(fnparam) { - var i = optionalidentifier(fnparam); - if (i) { - return i; - } - if (token.id === 'function' && nexttoken.id === '(') { - warning("Missing name in function declaration."); - } else { - error("Expected an identifier and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - } - - - function reachable(s) { - var i = 0, t; - if (nexttoken.id !== ';' || noreach) { - return; - } - for (;;) { - t = peek(i); - if (t.reach) { - return; - } - if (t.id !== '(endline)') { - if (t.id === 'function') { - warning( -"Inner functions should be listed at the top of the outer function.", t); - break; - } - warning("Unreachable '{a}' after '{b}'.", t, t.value, s); - break; - } - i += 1; - } - } - - - function statement(noindent) { - var i = indent, r, s = scope, t = nexttoken; - -// We don't like the empty statement. - - if (t.id === ';') { - warning("Unnecessary semicolon.", t); - advance(';'); - return; - } - -// Is this a labelled statement? - - if (t.identifier && !t.reserved && peek().id === ':') { - advance(); - advance(':'); - scope = Object.create(s); - addlabel(t.value, 'label'); - if (!nexttoken.labelled) { - warning("Label '{a}' on {b} statement.", - nexttoken, t.value, nexttoken.value); - } - if (jx.test(t.value + ':')) { - warning("Label '{a}' looks like a javascript url.", - t, t.value); - } - nexttoken.label = t.value; - t = nexttoken; - } - -// Parse the statement. - - if (!noindent) { - indentation(); - } - r = expression(0, true); - -// Look for the final semicolon. - - if (!t.block) { - if (!option.expr && (!r || !r.exps)) { - warning("Expected an assignment or function call and instead saw an expression.", token); - } else if (option.nonew && r.id === '(' && r.left.id === 'new') { - warning("Do not use 'new' for side effects."); - } - if (nexttoken.id !== ';') { - if (!option.asi) { - warningAt("Missing semicolon.", token.line, token.from + token.value.length); - } - } else { - adjacent(token, nexttoken); - advance(';'); - nonadjacent(token, nexttoken); - } - } - -// Restore the indentation. - - indent = i; - scope = s; - return r; - } - - - function use_strict() { - if (nexttoken.value === 'use strict') { - if (strict_mode) { - warning("Unnecessary \"use strict\"."); - } - advance(); - advance(';'); - strict_mode = true; - option.newcap = true; - option.undef = true; - return true; - } else { - return false; - } - } - - - function statements(begin) { - var a = [], f, p; - - while (!nexttoken.reach && nexttoken.id !== '(end)') { - if (nexttoken.id === ';') { - warning("Unnecessary semicolon."); - advance(';'); - } else { - a.push(statement()); - } - } - return a; - } - - - /* - * Parses a single block. A block is a sequence of statements wrapped in - * braces. - * - * ordinary - true for everything but function bodies and try blocks. - * stmt - true if block can be a single statement (e.g. in if/for/while). - */ - function block(ordinary, stmt) { - var a, - b = inblock, - old_indent = indent, - m = strict_mode, - s = scope, - t; - - inblock = ordinary; - scope = Object.create(scope); - nonadjacent(token, nexttoken); - t = nexttoken; - - if (nexttoken.id === '{') { - advance('{'); - if (nexttoken.id !== '}' || token.line !== nexttoken.line) { - indent += option.indent; - while (!ordinary && nexttoken.from > indent) { - indent += option.indent; - } - if (!ordinary && !use_strict() && !m && option.strict && - funct['(context)']['(global)']) { - warning("Missing \"use strict\" statement."); - } - a = statements(); - strict_mode = m; - indent -= option.indent; - indentation(); - } - advance('}', t); - indent = old_indent; - } else if (!ordinary) { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); - } else { - if (!stmt || option.curly) - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); - - noreach = true; - a = [statement()]; - noreach = false; - } - funct['(verb)'] = null; - scope = s; - inblock = b; - if (ordinary && option.noempty && (!a || a.length === 0)) { - warning("Empty block."); - } - return a; - } - - - function countMember(m) { - if (membersOnly && typeof membersOnly[m] !== 'boolean') { - warning("Unexpected /*member '{a}'.", token, m); - } - if (typeof member[m] === 'number') { - member[m] += 1; - } else { - member[m] = 1; - } - } - - - function note_implied(token) { - var name = token.value, line = token.line, a = implied[name]; - if (typeof a === 'function') { - a = false; - } - if (!a) { - a = [line]; - implied[name] = a; - } else if (a[a.length - 1] !== line) { - a.push(line); - } - } - -// Build the syntax table by declaring the syntactic elements of the language. - - type('(number)', function () { - return this; - }); - type('(string)', function () { - return this; - }); - - syntax['(identifier)'] = { - type: '(identifier)', - lbp: 0, - identifier: true, - nud: function () { - var v = this.value, - s = scope[v], - f; - if (typeof s === 'function') { - -// Protection against accidental inheritance. - - s = undefined; - } else if (typeof s === 'boolean') { - f = funct; - funct = functions[0]; - addlabel(v, 'var'); - s = funct; - funct = f; - } - -// The name is in scope and defined in the current function. - - if (funct === s) { - -// Change 'unused' to 'var', and reject labels. - - switch (funct[v]) { - case 'unused': - funct[v] = 'var'; - break; - case 'unction': - funct[v] = 'function'; - this['function'] = true; - break; - case 'function': - this['function'] = true; - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - break; - } - -// The name is not defined in the function. If we are in the global scope, -// then we have an undefined variable. -// -// Operators typeof and delete do not raise runtime errors even if the base -// object of a reference is null so no need to display warning if we're -// inside of typeof or delete. - - } else if (funct['(global)']) { - if (anonname != 'typeof' && anonname != 'delete' && - option.undef && typeof predefined[v] !== 'boolean') { - warning("'{a}' is not defined.", token, v); - } - note_implied(token); - -// If the name is already defined in the current -// function, but not as outer, then there is a scope error. - - } else { - switch (funct[v]) { - case 'closure': - case 'function': - case 'var': - case 'unused': - warning("'{a}' used out of scope.", token, v); - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - break; - case 'outer': - case 'global': - break; - default: - -// If the name is defined in an outer function, make an outer entry, and if -// it was unused, make it var. - - if (s === true) { - funct[v] = true; - } else if (s === null) { - warning("'{a}' is not allowed.", token, v); - note_implied(token); - } else if (typeof s !== 'object') { - -// Operators typeof and delete do not raise runtime errors even if the base object of -// a reference is null so no need to display warning if we're inside of typeof or delete. - - if (anonname != 'typeof' && anonname != 'delete' && option.undef) { - warning("'{a}' is not defined.", token, v); - } else { - funct[v] = true; - } - note_implied(token); - } else { - switch (s[v]) { - case 'function': - case 'unction': - this['function'] = true; - s[v] = 'closure'; - funct[v] = s['(global)'] ? 'global' : 'outer'; - break; - case 'var': - case 'unused': - s[v] = 'closure'; - funct[v] = s['(global)'] ? 'global' : 'outer'; - break; - case 'closure': - case 'parameter': - funct[v] = s['(global)'] ? 'global' : 'outer'; - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - } - } - } - } - return this; - }, - led: function () { - error("Expected an operator and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - }; - - type('(regexp)', function () { - return this; - }); - - -// ECMAScript parser - - delim('(endline)'); - delim('(begin)'); - delim('(end)').reach = true; - delim(''); - delim('(error)').reach = true; - delim('}').reach = true; - delim(')'); - delim(']'); - delim('"').reach = true; - delim("'").reach = true; - delim(';'); - delim(':').reach = true; - delim(','); - delim('#'); - delim('@'); - reserve('else'); - reserve('case').reach = true; - reserve('catch'); - reserve('default').reach = true; - reserve('finally'); - reservevar('arguments', function (x) { - if (strict_mode && funct['(global)']) { - warning("Strict violation.", x); - } - }); - reservevar('eval'); - reservevar('false'); - reservevar('Infinity'); - reservevar('NaN'); - reservevar('null'); - reservevar('this', function (x) { - if (strict_mode && ((funct['(statement)'] && - funct['(name)'].charAt(0) > 'Z') || funct['(global)'])) { - warning("Strict violation.", x); - } - }); - reservevar('true'); - reservevar('undefined'); - assignop('=', 'assign', 20); - assignop('+=', 'assignadd', 20); - assignop('-=', 'assignsub', 20); - assignop('*=', 'assignmult', 20); - assignop('/=', 'assigndiv', 20).nud = function () { - error("A regular expression literal can be confused with '/='."); - }; - assignop('%=', 'assignmod', 20); - bitwiseassignop('&=', 'assignbitand', 20); - bitwiseassignop('|=', 'assignbitor', 20); - bitwiseassignop('^=', 'assignbitxor', 20); - bitwiseassignop('<<=', 'assignshiftleft', 20); - bitwiseassignop('>>=', 'assignshiftright', 20); - bitwiseassignop('>>>=', 'assignshiftrightunsigned', 20); - infix('?', function (left, that) { - that.left = left; - that.right = expression(10); - advance(':'); - that['else'] = expression(10); - return that; - }, 30); - - infix('||', 'or', 40); - infix('&&', 'and', 50); - bitwise('|', 'bitor', 70); - bitwise('^', 'bitxor', 80); - bitwise('&', 'bitand', 90); - relation('==', function (left, right) { - var eqnull = option.eqnull && - (left.value == 'null' || right.value == 'null'); - - if (!eqnull && option.eqeqeq) { - warning("Expected '{a}' and instead saw '{b}'.", - this, '===', '=='); - } else if (isPoorRelation(left)) { - warning("Use '{a}' to compare with '{b}'.", - this, '===', left.value); - } else if (isPoorRelation(right)) { - warning("Use '{a}' to compare with '{b}'.", - this, '===', right.value); - } - return this; - }); - relation('==='); - relation('!=', function (left, right) { - if (option.eqeqeq) { - warning("Expected '{a}' and instead saw '{b}'.", - this, '!==', '!='); - } else if (isPoorRelation(left)) { - warning("Use '{a}' to compare with '{b}'.", - this, '!==', left.value); - } else if (isPoorRelation(right)) { - warning("Use '{a}' to compare with '{b}'.", - this, '!==', right.value); - } - return this; - }); - relation('!=='); - relation('<'); - relation('>'); - relation('<='); - relation('>='); - bitwise('<<', 'shiftleft', 120); - bitwise('>>', 'shiftright', 120); - bitwise('>>>', 'shiftrightunsigned', 120); - infix('in', 'in', 120); - infix('instanceof', 'instanceof', 120); - infix('+', function (left, that) { - var right = expression(130); - if (left && right && left.id === '(string)' && right.id === '(string)') { - left.value += right.value; - left.character = right.character; - if (jx.test(left.value)) { - warning("JavaScript URL.", left); - } - return left; - } - that.left = left; - that.right = right; - return that; - }, 130); - prefix('+', 'num'); - prefix('+++', function () { - warning("Confusing pluses."); - this.right = expression(150); - this.arity = 'unary'; - return this; - }); - infix('+++', function (left) { - warning("Confusing pluses."); - this.left = left; - this.right = expression(130); - return this; - }, 130); - infix('-', 'sub', 130); - prefix('-', 'neg'); - prefix('---', function () { - warning("Confusing minuses."); - this.right = expression(150); - this.arity = 'unary'; - return this; - }); - infix('---', function (left) { - warning("Confusing minuses."); - this.left = left; - this.right = expression(130); - return this; - }, 130); - infix('*', 'mult', 140); - infix('/', 'div', 140); - infix('%', 'mod', 140); - - suffix('++', 'postinc'); - prefix('++', 'preinc'); - syntax['++'].exps = true; - - suffix('--', 'postdec'); - prefix('--', 'predec'); - syntax['--'].exps = true; - prefix('delete', function () { - var p = expression(0); - if (!p || (p.id !== '.' && p.id !== '[')) { - warning("Variables should not be deleted."); - } - this.first = p; - return this; - }).exps = true; - - prefix('~', function () { - if (option.bitwise) { - warning("Unexpected '{a}'.", this, '~'); - } - expression(150); - return this; - }); - - prefix('!', function () { - this.right = expression(150); - this.arity = 'unary'; - if (bang[this.right.id] === true) { - warning("Confusing use of '{a}'.", this, '!'); - } - return this; - }); - prefix('typeof', 'typeof'); - prefix('new', function () { - var c = expression(155), i; - if (c && c.id !== 'function') { - if (c.identifier) { - c['new'] = true; - switch (c.value) { - case 'Object': - warning("Use the object literal notation {}.", token); - break; - case 'Number': - case 'String': - case 'Boolean': - case 'Math': - case 'JSON': - warning("Do not use {a} as a constructor.", token, c.value); - break; - case 'Function': - if (!option.evil) { - warning("The Function constructor is eval."); - } - break; - case 'Date': - case 'RegExp': - break; - default: - if (c.id !== 'function') { - i = c.value.substr(0, 1); - if (option.newcap && (i < 'A' || i > 'Z')) { - warning("A constructor name should start with an uppercase letter.", token); - } - } - } - } else { - if (c.id !== '.' && c.id !== '[' && c.id !== '(') { - warning("Bad constructor.", token); - } - } - } else { - if (!option.supernew) - warning("Weird construction. Delete 'new'.", this); - } - adjacent(token, nexttoken); - if (nexttoken.id !== '(' && !option.supernew) { - warning("Missing '()' invoking a constructor."); - } - this.first = c; - return this; - }); - syntax['new'].exps = true; - - prefix('void').exps = true; - - infix('.', function (left, that) { - adjacent(prevtoken, token); - nobreak(); - var m = identifier(); - if (typeof m === 'string') { - countMember(m); - } - that.left = left; - that.right = m; - if (option.noarg && left && left.value === 'arguments' && - (m === 'callee' || m === 'caller')) { - warning("Avoid arguments.{a}.", left, m); - } else if (!option.evil && left && left.value === 'document' && - (m === 'write' || m === 'writeln')) { - warning("document.write can be a form of eval.", left); - } - if (!option.evil && (m === 'eval' || m === 'execScript')) { - warning('eval is evil.'); - } - return that; - }, 160, true); - - infix('(', function (left, that) { - if (prevtoken.id !== '}' && prevtoken.id !== ')') { - nobreak(prevtoken, token); - } - nospace(); - if (option.immed && !left.immed && left.id === 'function') { - warning("Wrap an immediate function invocation in parentheses " + - "to assist the reader in understanding that the expression " + - "is the result of a function, and not the function itself."); - } - var n = 0, - p = []; - if (left) { - if (left.type === '(identifier)') { - if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) { - if (left.value !== 'Number' && left.value !== 'String' && - left.value !== 'Boolean' && - left.value !== 'Date') { - if (left.value === 'Math') { - warning("Math is not a function.", left); - } else if (option.newcap) { - warning( -"Missing 'new' prefix when invoking a constructor.", left); - } - } - } - } - } - if (nexttoken.id !== ')') { - for (;;) { - p[p.length] = expression(10); - n += 1; - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - advance(')'); - nospace(prevtoken, token); - if (typeof left === 'object') { - if (left.value === 'parseInt' && n === 1) { - warning("Missing radix parameter.", left); - } - if (!option.evil) { - if (left.value === 'eval' || left.value === 'Function' || - left.value === 'execScript') { - warning("eval is evil.", left); - } else if (p[0] && p[0].id === '(string)' && - (left.value === 'setTimeout' || - left.value === 'setInterval')) { - warning( - "Implied eval is evil. Pass a function instead of a string.", left); - } - } - if (!left.identifier && left.id !== '.' && left.id !== '[' && - left.id !== '(' && left.id !== '&&' && left.id !== '||' && - left.id !== '?') { - warning("Bad invocation.", left); - } - } - that.left = left; - return that; - }, 155, true).exps = true; - - prefix('(', function () { - nospace(); - if (nexttoken.id === 'function') { - nexttoken.immed = true; - } - var v = expression(0); - advance(')', this); - nospace(prevtoken, token); - if (option.immed && v.id === 'function') { - if (nexttoken.id === '(') { - warning( -"Move the invocation into the parens that contain the function.", nexttoken); - } else { - warning( -"Do not wrap function literals in parens unless they are to be immediately invoked.", - this); - } - } - return v; - }); - - infix('[', function (left, that) { - nobreak(prevtoken, token); - nospace(); - var e = expression(0), s; - if (e && e.type === '(string)') { - if (!option.evil && (e.value === 'eval' || e.value === 'execScript')) { - warning("eval is evil.", that); - } - countMember(e.value); - if (!option.sub && ix.test(e.value)) { - s = syntax[e.value]; - if (!s || !s.reserved) { - warning("['{a}'] is better written in dot notation.", - e, e.value); - } - } - } - advance(']', that); - nospace(prevtoken, token); - that.left = left; - that.right = e; - return that; - }, 160, true); - - prefix('[', function () { - var b = token.line !== nexttoken.line; - this.first = []; - if (b) { - indent += option.indent; - if (nexttoken.from === indent + option.indent) { - indent += option.indent; - } - } - while (nexttoken.id !== '(end)') { - while (nexttoken.id === ',') { - warning("Extra comma."); - advance(','); - } - if (nexttoken.id === ']') { - break; - } - if (b && token.line !== nexttoken.line) { - indentation(); - } - this.first.push(expression(10)); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.id === ']' && !option.es5) { - warning("Extra comma.", token); - break; - } - } else { - break; - } - } - if (b) { - indent -= option.indent; - indentation(); - } - advance(']', this); - return this; - }, 160); - - - function property_name() { - var id = optionalidentifier(true); - if (!id) { - if (nexttoken.id === '(string)') { - id = nexttoken.value; - advance(); - } else if (nexttoken.id === '(number)') { - id = nexttoken.value.toString(); - advance(); - } - } - return id; - } - - - function functionparams() { - var i, t = nexttoken, p = []; - advance('('); - nospace(); - if (nexttoken.id === ')') { - advance(')'); - nospace(prevtoken, token); - return; - } - for (;;) { - i = identifier(true); - p.push(i); - addlabel(i, 'parameter'); - if (nexttoken.id === ',') { - comma(); - } else { - advance(')', t); - nospace(prevtoken, token); - return p; - } - } - } - - - function doFunction(i, statement) { - var f, - oldOption = option, - oldScope = scope; - - option = Object.create(option); - scope = Object.create(scope); - - funct = { - '(name)' : i || '"' + anonname + '"', - '(line)' : nexttoken.line, - '(context)' : funct, - '(breakage)' : 0, - '(loopage)' : 0, - '(scope)' : scope, - '(statement)': statement - }; - f = funct; - token.funct = funct; - functions.push(funct); - if (i) { - addlabel(i, 'function'); - } - funct['(params)'] = functionparams(); - - block(false); - scope = oldScope; - option = oldOption; - funct['(last)'] = token.line; - funct = funct['(context)']; - return f; - } - - - (function (x) { - x.nud = function () { - var b, f, i, j, p, seen = {}, t; - - b = token.line !== nexttoken.line; - if (b) { - indent += option.indent; - if (nexttoken.from === indent + option.indent) { - indent += option.indent; - } - } - for (;;) { - if (nexttoken.id === '}') { - break; - } - if (b) { - indentation(); - } - if (nexttoken.value === 'get' && peek().id !== ':') { - advance('get'); - if (!option.es5) { - error("get/set are ES5 features."); - } - i = property_name(); - if (!i) { - error("Missing property name."); - } - t = nexttoken; - adjacent(token, nexttoken); - f = doFunction(); - if (!option.loopfunc && funct['(loopage)']) { - warning("Don't make functions within a loop.", t); - } - p = f['(params)']; - if (p) { - warning("Unexpected parameter '{a}' in get {b} function.", t, p[0], i); - } - adjacent(token, nexttoken); - advance(','); - indentation(); - advance('set'); - j = property_name(); - if (i !== j) { - error("Expected {a} and instead saw {b}.", token, i, j); - } - t = nexttoken; - adjacent(token, nexttoken); - f = doFunction(); - p = f['(params)']; - if (!p || p.length !== 1 || p[0] !== 'value') { - warning("Expected (value) in set {a} function.", t, i); - } - } else { - i = property_name(); - if (typeof i !== 'string') { - break; - } - advance(':'); - nonadjacent(token, nexttoken); - expression(10); - } - if (seen[i] === true) { - warning("Duplicate member '{a}'.", nexttoken, i); - } - seen[i] = true; - countMember(i); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.id === ',') { - warning("Extra comma.", token); - } else if (nexttoken.id === '}' && !option.es5) { - warning("Extra comma.", token); - } - } else { - break; - } - } - if (b) { - indent -= option.indent; - indentation(); - } - advance('}', this); - return this; - }; - x.fud = function () { - error("Expected to see a statement and instead saw a block.", token); - }; - }(delim('{'))); - - var varstatement = stmt('var', function (prefix) { - // JavaScript does not have block scope. It only has function scope. So, - // declaring a variable in a block can have unexpected consequences. - var id, name, value; - - if (funct['(onevar)'] && option.onevar) { - warning("Too many var statements."); - } else if (!funct['(global)']) { - funct['(onevar)'] = true; - } - this.first = []; - for (;;) { - nonadjacent(token, nexttoken); - id = identifier(); - if (funct['(global)'] && predefined[id] === false) { - warning("Redefinition of '{a}'.", token, id); - } - addlabel(id, 'unused'); - if (prefix) { - break; - } - name = token; - this.first.push(token); - if (nexttoken.id === '=') { - nonadjacent(token, nexttoken); - advance('='); - nonadjacent(token, nexttoken); - if (nexttoken.id === 'undefined') { - warning("It is not necessary to initialize '{a}' to 'undefined'.", token, id); - } - if (peek(0).id === '=' && nexttoken.identifier) { - error("Variable {a} was not declared correctly.", - nexttoken, nexttoken.value); - } - value = expression(0); - name.first = value; - } - if (nexttoken.id !== ',') { - break; - } - comma(); - } - return this; - }); - varstatement.exps = true; - - blockstmt('function', function () { - if (inblock) { - warning( -"Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function.", token); - - } - var i = identifier(); - adjacent(token, nexttoken); - addlabel(i, 'unction'); - doFunction(i, true); - if (nexttoken.id === '(' && nexttoken.line === token.line) { - error( -"Function declarations are not invocable. Wrap the whole function invocation in parens."); - } - return this; - }); - - prefix('function', function () { - var i = optionalidentifier(); - if (i) { - adjacent(token, nexttoken); - } else { - nonadjacent(token, nexttoken); - } - doFunction(i); - if (!option.loopfunc && funct['(loopage)']) { - warning("Don't make functions within a loop."); - } - return this; - }); - - blockstmt('if', function () { - var t = nexttoken; - advance('('); - nonadjacent(this, t); - nospace(); - expression(20); - if (nexttoken.id === '=') { - if (!option.boss) - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - expression(20); - } - advance(')', t); - nospace(prevtoken, token); - block(true, true); - if (nexttoken.id === 'else') { - nonadjacent(token, nexttoken); - advance('else'); - if (nexttoken.id === 'if' || nexttoken.id === 'switch') { - statement(true); - } else { - block(true, true); - } - } - return this; - }); - - blockstmt('try', function () { - var b, e, s; - - block(false); - if (nexttoken.id === 'catch') { - advance('catch'); - nonadjacent(token, nexttoken); - advance('('); - s = scope; - scope = Object.create(s); - e = nexttoken.value; - if (nexttoken.type !== '(identifier)') { - warning("Expected an identifier and instead saw '{a}'.", - nexttoken, e); - } else { - addlabel(e, 'exception'); - } - advance(); - advance(')'); - block(false); - b = true; - scope = s; - } - if (nexttoken.id === 'finally') { - advance('finally'); - block(false); - return; - } else if (!b) { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'catch', nexttoken.value); - } - return this; - }); - - blockstmt('while', function () { - var t = nexttoken; - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - expression(20); - if (nexttoken.id === '=') { - if (!option.boss) - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - expression(20); - } - advance(')', t); - nospace(prevtoken, token); - block(true, true); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - }).labelled = true; - - reserve('with'); - - blockstmt('switch', function () { - var t = nexttoken, - g = false; - funct['(breakage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - this.condition = expression(20); - advance(')', t); - nospace(prevtoken, token); - nonadjacent(token, nexttoken); - t = nexttoken; - advance('{'); - nonadjacent(token, nexttoken); - indent += option.indent; - this.cases = []; - for (;;) { - switch (nexttoken.id) { - case 'case': - switch (funct['(verb)']) { - case 'break': - case 'case': - case 'continue': - case 'return': - case 'switch': - case 'throw': - break; - default: - // You can tell JSHint that you don't use break intentionally by - // adding a comment /* falls through */ on a line just before - // the next `case`. - if (!ft.test(lines[nexttoken.line - 2])) { - warning( - "Expected a 'break' statement before 'case'.", - token); - } - } - indentation(-option.indent); - advance('case'); - this.cases.push(expression(20)); - g = true; - advance(':'); - funct['(verb)'] = 'case'; - break; - case 'default': - switch (funct['(verb)']) { - case 'break': - case 'continue': - case 'return': - case 'throw': - break; - default: - if (!ft.test(lines[nexttoken.line - 2])) { - warning( - "Expected a 'break' statement before 'default'.", - token); - } - } - indentation(-option.indent); - advance('default'); - g = true; - advance(':'); - break; - case '}': - indent -= option.indent; - indentation(); - advance('}', t); - if (this.cases.length === 1 || this.condition.id === 'true' || - this.condition.id === 'false') { - warning("This 'switch' should be an 'if'.", this); - } - funct['(breakage)'] -= 1; - funct['(verb)'] = undefined; - return; - case '(end)': - error("Missing '{a}'.", nexttoken, '}'); - return; - default: - if (g) { - switch (token.id) { - case ',': - error("Each value should have its own case label."); - return; - case ':': - statements(); - break; - default: - error("Missing ':' on a case clause.", token); - } - } else { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'case', nexttoken.value); - } - } - } - }).labelled = true; - - stmt('debugger', function () { - if (!option.debug) { - warning("All 'debugger' statements should be removed."); - } - return this; - }).exps = true; - - (function () { - var x = stmt('do', function () { - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - this.first = block(true); - advance('while'); - var t = nexttoken; - nonadjacent(token, t); - advance('('); - nospace(); - expression(20); - if (nexttoken.id === '=') { - if (!option.boss) - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - expression(20); - } - advance(')', t); - nospace(prevtoken, token); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - }); - x.labelled = true; - x.exps = true; - }()); - - blockstmt('for', function () { - var s, t = nexttoken; - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - if (peek(nexttoken.id === 'var' ? 1 : 0).id === 'in') { - if (nexttoken.id === 'var') { - advance('var'); - varstatement.fud.call(varstatement, true); - } else { - switch (funct[nexttoken.value]) { - case 'unused': - funct[nexttoken.value] = 'var'; - break; - case 'var': - break; - default: - warning("Bad for in variable '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance('in'); - expression(20); - advance(')', t); - s = block(true, true); - if (option.forin && (s.length > 1 || typeof s[0] !== 'object' || - s[0].value !== 'if')) { - warning("The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.", this); - } - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - } else { - if (nexttoken.id !== ';') { - if (nexttoken.id === 'var') { - advance('var'); - varstatement.fud.call(varstatement); - } else { - for (;;) { - expression(0, 'for'); - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - } - nolinebreak(token); - advance(';'); - if (nexttoken.id !== ';') { - expression(20); - if (nexttoken.id === '=') { - if (!option.boss) - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - expression(20); - } - } - nolinebreak(token); - advance(';'); - if (nexttoken.id === ';') { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, ')', ';'); - } - if (nexttoken.id !== ')') { - for (;;) { - expression(0, 'for'); - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - advance(')', t); - nospace(prevtoken, token); - block(true, true); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - } - }).labelled = true; - - - stmt('break', function () { - var v = nexttoken.value; - if (funct['(breakage)'] === 0) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - nolinebreak(this); - if (nexttoken.id !== ';') { - if (token.line === nexttoken.line) { - if (funct[v] !== 'label') { - warning("'{a}' is not a statement label.", nexttoken, v); - } else if (scope[v] !== funct) { - warning("'{a}' is out of scope.", nexttoken, v); - } - this.first = nexttoken; - advance(); - } - } - reachable('break'); - return this; - }).exps = true; - - - stmt('continue', function () { - var v = nexttoken.value; - if (funct['(breakage)'] === 0) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - nolinebreak(this); - if (nexttoken.id !== ';') { - if (token.line === nexttoken.line) { - if (funct[v] !== 'label') { - warning("'{a}' is not a statement label.", nexttoken, v); - } else if (scope[v] !== funct) { - warning("'{a}' is out of scope.", nexttoken, v); - } - this.first = nexttoken; - advance(); - } - } else if (!funct['(loopage)']) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - reachable('continue'); - return this; - }).exps = true; - - - stmt('return', function () { - nolinebreak(this); - if (nexttoken.id === '(regexp)') { - warning("Wrap the /regexp/ literal in parens to disambiguate the slash operator."); - } - if (nexttoken.id !== ';' && !nexttoken.reach) { - nonadjacent(token, nexttoken); - this.first = expression(20); - } - reachable('return'); - return this; - }).exps = true; - - - stmt('throw', function () { - nolinebreak(this); - nonadjacent(token, nexttoken); - this.first = expression(20); - reachable('throw'); - return this; - }).exps = true; - -// Superfluous reserved words - - reserve('class'); - reserve('const'); - reserve('enum'); - reserve('export'); - reserve('extends'); - reserve('import'); - reserve('super'); - - reserve('let'); - reserve('yield'); - reserve('implements'); - reserve('interface'); - reserve('package'); - reserve('private'); - reserve('protected'); - reserve('public'); - reserve('static'); - - -// Parse JSON - - function jsonValue() { - - function jsonObject() { - var o = {}, t = nexttoken; - advance('{'); - if (nexttoken.id !== '}') { - for (;;) { - if (nexttoken.id === '(end)') { - error("Missing '}' to match '{' from line {a}.", - nexttoken, t.line); - } else if (nexttoken.id === '}') { - warning("Unexpected comma.", token); - break; - } else if (nexttoken.id === ',') { - error("Unexpected comma.", nexttoken); - } else if (nexttoken.id !== '(string)') { - warning("Expected a string and instead saw {a}.", - nexttoken, nexttoken.value); - } - if (o[nexttoken.value] === true) { - warning("Duplicate key '{a}'.", - nexttoken, nexttoken.value); - } else if (nexttoken.value === '__proto__') { - warning("Stupid key '{a}'.", - nexttoken, nexttoken.value); - } else { - o[nexttoken.value] = true; - } - advance(); - advance(':'); - jsonValue(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - } - advance('}'); - } - - function jsonArray() { - var t = nexttoken; - advance('['); - if (nexttoken.id !== ']') { - for (;;) { - if (nexttoken.id === '(end)') { - error("Missing ']' to match '[' from line {a}.", - nexttoken, t.line); - } else if (nexttoken.id === ']') { - warning("Unexpected comma.", token); - break; - } else if (nexttoken.id === ',') { - error("Unexpected comma.", nexttoken); - } - jsonValue(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - } - advance(']'); - } - - switch (nexttoken.id) { - case '{': - jsonObject(); - break; - case '[': - jsonArray(); - break; - case 'true': - case 'false': - case 'null': - case '(number)': - case '(string)': - advance(); - break; - case '-': - advance('-'); - if (token.character !== nexttoken.from) { - warning("Unexpected space after '-'.", token); - } - adjacent(token, nexttoken); - advance('(number)'); - break; - default: - error("Expected a JSON value.", nexttoken); - } - } - - -// The actual JSHINT function itself. - - var itself = function (s, o, g) { - var a, i, k; - JSHINT.errors = []; - predefined = Object.create(standard); - combine(predefined, g || {}); - if (o) { - a = o.predef; - if (a) { - if (Array.isArray(a)) { - for (i = 0; i < a.length; i += 1) { - predefined[a[i]] = true; - } - } else if (typeof a === 'object') { - k = Object.keys(a); - for (i = 0; i < k.length; i += 1) { - predefined[k[i]] = !!a[k]; - } - } - } - option = o; - } else { - option = {}; - } - option.indent = option.indent || 4; - option.maxerr = option.maxerr || 50; - - tab = ''; - for (i = 0; i < option.indent; i += 1) { - tab += ' '; - } - indent = 1; - global = Object.create(predefined); - scope = global; - funct = { - '(global)': true, - '(name)': '(global)', - '(scope)': scope, - '(breakage)': 0, - '(loopage)': 0 - }; - functions = [funct]; - urls = []; - src = false; - stack = null; - member = {}; - membersOnly = null; - implied = {}; - inblock = false; - lookahead = []; - jsonmode = false; - warnings = 0; - lex.init(s); - prereg = true; - strict_mode = false; - - prevtoken = token = nexttoken = syntax['(begin)']; - assume(); - - try { - advance(); - switch (nexttoken.id) { - case '{': - case '[': - option.laxbreak = true; - jsonmode = true; - jsonValue(); - break; - default: - if (nexttoken.value === 'use strict') { - if (!option.globalstrict) - warning("Use the function form of \"use strict\"."); - use_strict(); - } - statements('lib'); - } - advance('(end)'); - } catch (e) { - if (e) { - JSHINT.errors.push({ - reason : e.message, - line : e.line || nexttoken.line, - character : e.character || nexttoken.from - }, null); - } - } - return JSHINT.errors.length === 0; - }; - - -// Data summary. - - itself.data = function () { - - var data = {functions: []}, fu, globals, implieds = [], f, i, j, - members = [], n, unused = [], v; - if (itself.errors.length) { - data.errors = itself.errors; - } - - if (jsonmode) { - data.json = true; - } - - for (n in implied) { - if (is_own(implied, n)) { - implieds.push({ - name: n, - line: implied[n] - }); - } - } - if (implieds.length > 0) { - data.implieds = implieds; - } - - if (urls.length > 0) { - data.urls = urls; - } - - globals = Object.keys(scope); - if (globals.length > 0) { - data.globals = globals; - } - - for (i = 1; i < functions.length; i += 1) { - f = functions[i]; - fu = {}; - for (j = 0; j < functionicity.length; j += 1) { - fu[functionicity[j]] = []; - } - for (n in f) { - if (is_own(f, n) && n.charAt(0) !== '(') { - v = f[n]; - if (v === 'unction') { - v = 'unused'; - } - if (Array.isArray(fu[v])) { - fu[v].push(n); - if (v === 'unused') { - unused.push({ - name: n, - line: f['(line)'], - 'function': f['(name)'] - }); - } - } - } - } - for (j = 0; j < functionicity.length; j += 1) { - if (fu[functionicity[j]].length === 0) { - delete fu[functionicity[j]]; - } - } - fu.name = f['(name)']; - fu.param = f['(params)']; - fu.line = f['(line)']; - fu.last = f['(last)']; - data.functions.push(fu); - } - - if (unused.length > 0) { - data.unused = unused; - } - - members = []; - for (n in member) { - if (typeof member[n] === 'number') { - data.member = member; - break; - } - } - - return data; - }; - - itself.report = function (option) { - var data = itself.data(); - - var a = [], c, e, err, f, i, k, l, m = '', n, o = [], s; - - function detail(h, array) { - var b, i, singularity; - if (array) { - o.push('
' + h + ' '); - array = array.sort(); - for (i = 0; i < array.length; i += 1) { - if (array[i] !== singularity) { - singularity = array[i]; - o.push((b ? ', ' : '') + singularity); - b = true; - } - } - o.push('
'); - } - } - - - if (data.errors || data.implieds || data.unused) { - err = true; - o.push('
Error:'); - if (data.errors) { - for (i = 0; i < data.errors.length; i += 1) { - c = data.errors[i]; - if (c) { - e = c.evidence || ''; - o.push('

Problem' + (isFinite(c.line) ? ' at line ' + - c.line + ' character ' + c.character : '') + - ': ' + c.reason.entityify() + - '

' + - (e && (e.length > 80 ? e.slice(0, 77) + '...' : - e).entityify()) + '

'); - } - } - } - - if (data.implieds) { - s = []; - for (i = 0; i < data.implieds.length; i += 1) { - s[i] = '' + data.implieds[i].name + ' ' + - data.implieds[i].line + ''; - } - o.push('

Implied global: ' + s.join(', ') + '

'); - } - - if (data.unused) { - s = []; - for (i = 0; i < data.unused.length; i += 1) { - s[i] = '' + data.unused[i].name + ' ' + - data.unused[i].line + ' ' + - data.unused[i]['function'] + ''; - } - o.push('

Unused variable: ' + s.join(', ') + '

'); - } - if (data.json) { - o.push('

JSON: bad.

'); - } - o.push('
'); - } - - if (!option) { - - o.push('
'); - - if (data.urls) { - detail("URLs
", data.urls, '
'); - } - - if (data.json && !err) { - o.push('

JSON: good.

'); - } else if (data.globals) { - o.push('
Global ' + - data.globals.sort().join(', ') + '
'); - } else { - o.push('
No new global variables introduced.
'); - } - - for (i = 0; i < data.functions.length; i += 1) { - f = data.functions[i]; - - o.push('
' + f.line + '-' + - f.last + ' ' + (f.name || '') + '(' + - (f.param ? f.param.join(', ') : '') + ')
'); - detail('Unused', f.unused); - detail('Closure', f.closure); - detail('Variable', f['var']); - detail('Exception', f.exception); - detail('Outer', f.outer); - detail('Global', f.global); - detail('Label', f.label); - } - - if (data.member) { - a = Object.keys(data.member); - if (a.length) { - a = a.sort(); - m = '
/*members ';
-                    l = 10;
-                    for (i = 0; i < a.length; i += 1) {
-                        k = a[i];
-                        n = k.name();
-                        if (l + n.length > 72) {
-                            o.push(m + '
'); - m = ' '; - l = 1; - } - l += n.length + 2; - if (data.member[k] === 1) { - n = '' + n + ''; - } - if (i < a.length - 1) { - n += ', '; - } - m += n; - } - o.push(m + '
*/
'); - } - o.push('
'); - } - } - return o.join(''); - }; - itself.jshint = itself; - - itself.edition = '2011-04-16'; - - return itself; - -}()); - -// Make JSHINT a Node module, if possible. -if (typeof exports == 'object' && exports) - exports.JSHINT = JSHINT; - diff --git a/util/nodejshint.js b/util/nodejshint.js deleted file mode 100644 index e4b3c0943..000000000 --- a/util/nodejshint.js +++ /dev/null @@ -1,37 +0,0 @@ -var JSHINT = require( './jshint.js' ).JSHINT - , fs = require( 'fs' ); - -var nodejshint = function() { - var counter = 0; - - return function( files, callback ) { - if( files.length ) { - var file = files.pop(); - - fs.readFile( file, function( err, data ) { - if (err) { throw err; } - - if( JSHINT(data.toString(), { laxbreak: true }) ) { - counter++; - console.log( '✔ Passed '+ file ); - } - else { - console.log( 'x Failed '+ file ); - JSHINT.errors.forEach( function( err ) { - if( err ) { - console.log( 'line '+ err.line +'\t', err.reason +'' ); - } - }); - } - - return nodejshint( files, callback ); - }); - } - else { - callback && callback( counter ); - counter = 0; - } - }; -}(); - -exports.test = nodejshint; diff --git a/vendor/libgit2 b/vendor/libgit2 deleted file mode 160000 index 7dbf4039a..000000000 --- a/vendor/libgit2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7dbf4039ae0881407fc9ead24c09c1d7cfd4103a