Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 31 additions & 32 deletions 63 build/codegen/templates/asyncFunction.cc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@
/**
<% include doc.cc.ejs -%>
*/
Handle<Value> <%- cppClassName %>::<%- functionInfo.cppFunctionName %>(const Arguments& args) {
HandleScope scope;
NAN_METHOD(<%- cppClassName %>::<%- functionInfo.cppFunctionName %>) {
NanScope();
<% var jsArg; -%>
<% include guardArguments.cc.ejs -%>

if (args.Length() == <%- jsArg %> || !args[<%- jsArg %>]->IsFunction()) {
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
return NanThrowError("Callback is required and must be a Function.");
}

<%- functionInfo.cppFunctionName %>Baton* baton = new <%- functionInfo.cppFunctionName %>Baton;
baton->error_code = GIT_OK;
baton->error = NULL;
baton->request.data = baton;
<%
for (var cArg = 0, jsArg = 0; cArg < functionInfo.args.length; cArg++) {
var arg = functionInfo.args[cArg];
-%>
<% if (!arg.isReturn) { -%>
<% if (arg.isSelf) { -%>
baton-><%- arg.name %>Reference = Persistent<Value>::New(args.This());
baton-><%- arg.name %> = ObjectWrap::Unwrap<<%- cppClassName %>>(args.This())->GetValue();
<% } else { -%>
baton-><%- arg.name %>Reference = Persistent<Value>::New(args[<%- jsArg %>]);
<% include convertFromV8.cc.ejs -%>
<% if (!arg.isPayload) { -%>
baton-><%- arg.name %> = from_<%- arg.name %>;
Expand All @@ -35,19 +32,32 @@ Handle<Value> <%- cppClassName %>::<%- functionInfo.cppFunctionName %>(const Arg
<% } else { -%>
<% if (arg.shouldAlloc) { -%>
baton-><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- arg.cType.replace('*', '') %>));
<% } else { -%>
<% } -%>
<% } -%>
<% } -%>
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[<%- jsArg %>]));

uv_queue_work(uv_default_loop(), &baton->request, <%- functionInfo.cppFunctionName %>Work, (uv_after_work_cb)<%- functionInfo.cppFunctionName %>AfterWork);
NanCallback *callback = new NanCallback(Local<Function>::Cast(args[<%- jsArg %>]));
<%- functionInfo.cppFunctionName %>Worker *worker = new <%- functionInfo.cppFunctionName %>Worker(baton, callback);
<%
for (var cArg = 0, jsArg = 0; cArg < functionInfo.args.length; cArg++) {
var arg = functionInfo.args[cArg];
-%>
<% if (!arg.isReturn) { -%>
<% if (arg.isSelf) { -%>
worker->SaveToPersistent("<%- arg.name %>", args.This());
<% } else { -%>
if (!args[<%- jsArg %>]->IsUndefined() && !args[<%- jsArg %>]->IsNull())
worker->SaveToPersistent("<%- arg.name %>", args[<%- jsArg %>]->ToObject());
<% } -%>
<% if (!(arg.isReturn || arg.isSelf || arg.isPayload)) jsArg++; -%>
<% } -%>
<% } -%>

return Undefined();
NanAsyncQueueWorker(worker);
NanReturnUndefined();
}

void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Work(uv_work_t *req) {
<%- functionInfo.cppFunctionName %>Baton *baton = static_cast<<%- functionInfo.cppFunctionName %>Baton *>(req->data);
void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Worker::Execute() {
<% if (functionInfo.return.cType != "void" || functionInfo.return.isErrorCode) { %><%- functionInfo.return.cType %> result = <% } %><%- functionInfo.cFunctionName %>(
<%
for (var i = 0; i < functionInfo.args.length; i++) {
Expand All @@ -66,46 +76,43 @@ void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Work(uv_work_t *req
<% } -%>
}

void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>AfterWork(uv_work_t *req) {
HandleScope scope;
<%- functionInfo.cppFunctionName %>Baton *baton = static_cast<<%- functionInfo.cppFunctionName %>Baton *>(req->data);

void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>Worker::HandleOKCallback() {
TryCatch try_catch;
if (baton->error_code == GIT_OK) {
<% if (!returns.length) { -%>
Handle<Value> result = Local<Value>::New(Undefined());
Handle<Value> result = NanUndefined();
<% } else if (returns.length == 1) { -%>
<% var to = {}; to.__proto__ = returns[0]; to.name = "baton->" + to.name; -%>
Handle<Value> to;
<% include convertToV8.cc.ejs -%>
Handle<Value> result = to;
<% } else { -%>
Handle<Object> result = Object::New();
Handle<Object> result = NanNew<Object>();
Handle<Value> to;
<%
for (r in returns) {
var to = returns[r];
-%>
<% include convertToV8.cc.ejs -%>
result->Set(String::NewSymbol("<%- to.jsName || to.name %>"), to);
result->Set(NanNew<String>("<%- to.jsName || to.name %>"), to);
<% } -%>
<% } -%>
Handle<Value> argv[2] = {
Local<Value>::New(Null()),
NanNull(),
result
};
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
callback->Call(2, argv);
} else {
if (baton->error) {
Handle<Value> argv[1] = {
Exception::Error(String::New(baton->error->message))
NanError(baton->error->message)
};
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv);
callback->Call(1, argv);
if (baton->error->message)
free((void *)baton->error->message);
free((void *)baton->error);
} else {
baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL);
callback->Call(0, NULL);
}
<%
for (var i = 0; i < functionInfo.args.length; i++) {
Expand All @@ -119,14 +126,6 @@ void <%- cppClassName %>::<%- functionInfo.cppFunctionName %>AfterWork(uv_work_t
if (try_catch.HasCaught()) {
node::FatalException(try_catch);
}
<%
for (var i = 0, j = 0; i < functionInfo.args.length; i++) {
var arg = functionInfo.args[i];
if (arg.isReturn) continue;
-%>
baton-><%- arg.name %>Reference.Dispose();
<% } -%>
baton->callback.Dispose();
<%
for (var i = 0; i < functionInfo.args.length; i++) {
var arg = functionInfo.args[i];
Expand Down
39 changes: 19 additions & 20 deletions 39 build/codegen/templates/class.cc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
/**
* This code is auto-generated; unless you know what you're doing, do not modify!
**/
#include <v8.h>
#include <node.h>
#include <nan.h>
#include <string.h>

#include "git2.h"
Expand Down Expand Up @@ -56,12 +55,12 @@ using namespace node;
}

void <%- cppClassName %>::Initialize(Handle<v8::Object> target) {
HandleScope scope;
NanScope();

Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);

tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(String::NewSymbol("<%- jsClassName %>"));
tpl->SetClassName(NanNew<String>("<%- jsClassName %>"));

<% if (typeof functions != 'undefined') { -%>
<%
Expand All @@ -87,49 +86,49 @@ void <%- cppClassName %>::Initialize(Handle<v8::Object> target) {
<% } -%>
<% } -%>

constructor_template = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("<%- jsClassName %>"), constructor_template);
Local<Function> _constructor_template = tpl->GetFunction();
NanAssignPersistent(constructor_template, _constructor_template);
target->Set(NanNew<String>("<%- jsClassName %>"), _constructor_template);
}

Handle<Value> <%- cppClassName %>::New(const Arguments& args) {
HandleScope scope;
NAN_METHOD(<%- cppClassName %>::New) {
NanScope();

if (args.Length() == 0 || !args[0]->IsExternal()) {
return ThrowException(Exception::Error(String::New("<%= cType %> is required.")));
return NanThrowError("<%= cType %> is required.");
}

<%- cppClassName %>* object = new <%- cppClassName %>((<%= cType%> *) External::Unwrap(args[0]));
<%- cppClassName %>* object = new <%- cppClassName %>(static_cast<<%= cType%> *>(Handle<External>::Cast(args[0])->Value()));
object->Wrap(args.This());

return scope.Close(args.This());
NanReturnValue(args.This());
}

Handle<Value> <%- cppClassName %>::New(void *raw) {
HandleScope scope;
Handle<Value> argv[1] = { External::New((void *)raw) };
return scope.Close(<%- cppClassName %>::constructor_template->NewInstance(1, argv));
NanEscapableScope();
Handle<Value> argv[1] = { NanNew<External>((void *)raw) };
return NanEscapeScope(NanNew<Function>(<%- cppClassName %>::constructor_template)->NewInstance(1, argv));
}

<%- cType %> *<%- cppClassName %>::GetValue() {
return this->raw;
}
<% } else { -%>
void <%- cppClassName %>::Initialize(Handle<v8::Object> target) {
HandleScope scope;
NanScope();

Persistent<Object> object = Persistent<Object>::New(Object::New());
Local<Object> object = NanNew<Object>();

<% if (typeof functions != 'undefined') { -%>
<%
for (var i in functions) {
var functionInfo = functions[i];
if (functionInfo.ignore) continue;
-%>
object->Set(String::NewSymbol("<%- functionInfo.jsFunctionName %>"), FunctionTemplate::New(<%- functionInfo.cppFunctionName %>)->GetFunction());
NODE_SET_METHOD(object, "<%- functionInfo.jsFunctionName %>", <%- functionInfo.cppFunctionName %>);
<% } -%>
<% } -%>

target->Set(String::NewSymbol("<%- jsClassName %>"), object);
target->Set(NanNew<String>("<%- jsClassName %>"), object);
}
<% } -%>

Expand Down
3 changes: 1 addition & 2 deletions 3 build/codegen/templates/convertFromV8.cc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
<%
// FIXME: should recursively call convertFromv8.
%>
from_<%- arg.name %>[i] = ObjectWrap::Unwrap<<%- arg.arrayElementCppClassName %>>(tmp_<%- arg.name %>->Get(Number::New(static_cast<double>(i)))->ToObject())->GetValue();
from_<%- arg.name %>[i] = ObjectWrap::Unwrap<<%- arg.arrayElementCppClassName %>>(tmp_<%- arg.name %>->Get(NanNew<Number>(static_cast<double>(i)))->ToObject())->GetValue();
}
<% } else if (arg.cppClassName == "Function") { -%>
Persistent<Function>::New(Local<Function>::Cast(args[<%- jsArg %>]));
<% } else if (arg.cppClassName == 'Buffer') { -%>
from_<%- arg.name %> = Buffer::Data(args[<%- jsArg %>]->ToObject());
<% } else if (isV8Value(arg.cppClassName)) { -%>
Expand Down
19 changes: 12 additions & 7 deletions 19 build/codegen/templates/convertToV8.cc.ejs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
<% toName = to.name || 'result' -%>
<% if (to.cppClassName == "String") { -%>
<% if (typeof to.size != 'undefined') { -%>
to = String::New(<%- toName %>, <%- to.size %>);
to = NanNew<String>(<%- toName %>, <%- to.size %>);
<% } else { -%>
to = String::New(<%- toName %>);
to = NanNew<String>(<%- toName %>);
<% } -%>
<% if (to.freeFunctionName) { -%>
<%- to.freeFunctionName %>(<%- toName %>);
<% } -%>
<% } else if (isV8Value(to.cppClassName)) { -%>
to = <%- to.cppClassName %>::New(<%- toName %>);
<% if (~['Uint32', 'Int32'].indexOf(to.cppClassName)) { -%>
<% var className = to.cppClassName.toLowerCase()+'_t' -%>
to = NanNew<<%- to.cppClassName %>>((<%- className %>)<%- toName %>);
<% } else { -%>
to = NanNew<<%- to.cppClassName %>>(<%- toName %>);
<% } -%>
<% } else if (to.cppClassName == "External") { -%>
to = External::New((void *)<%- toName %>);
to = NanNew<External>((void *)<%- toName %>);
<% } else if (to.cppClassName == 'Array') { -%>
<%
// FIXME this is not general purpose enough.
%>
Local<Array> tmpArray = Array::New(<%- toName %>-><%- to.size %>);
Local<Array> tmpArray = NanNew<Array>(<%- toName %>-><%- to.size %>);
for (unsigned int i = 0; i < <%- toName %>-><%- to.size %>; i++) {
tmpArray->Set(Number::New(i), String::New(<%- toName %>-><%- to.key %>[i]));
tmpArray->Set(NanNew<Number>(i), NanNew<String>(<%- toName %>-><%- to.key %>[i]));
}
to = tmpArray;
<% } else { -%>
Expand All @@ -30,6 +35,6 @@
if (<%- toName %> != NULL) {
to = <%- to.cppClassName %>::New((void *)<%- toName %>);
} else {
to = Null();
to = NanNull();
}
<% } -%>
6 changes: 3 additions & 3 deletions 6 build/codegen/templates/fields.cc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
if (fieldInfo.ignore) continue;
-%>

Handle<Value> <%- cppClassName %>::<%- fieldInfo.cppFunctionName %>(const Arguments& args) {
HandleScope scope;
NAN_METHOD(<%- cppClassName %>::<%- fieldInfo.cppFunctionName %>) {
NanScope();
<% var to = fieldInfo; -%>
Handle<Value> to;

<%- fieldInfo.cType %> <% if (!isV8Value(fieldInfo.cppClassName)) { %>*<% } %><%- fieldInfo.name %> =
<% if (!isV8Value(fieldInfo.cppClassName)) { %>&<% } %>ObjectWrap::Unwrap<<%- cppClassName %>>(args.This())->GetValue()-><%- fieldInfo.name %>;

<% include convertToV8.cc.ejs -%>
return scope.Close(to);
NanReturnValue(to);
}
<% } -%>
<% } -%>
2 changes: 1 addition & 1 deletion 2 build/codegen/templates/guardArguments.cc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-%>
<% if (!arg.isOptional) { -%>
if (args.Length() == <%- jsArg %> || !args[<%- jsArg %>]->Is<%- cppClassName2v8ValueClassName(arg.cppClassName) %>()) {
return ThrowException(Exception::Error(String::New("<%- arg.jsClassName %> <%- arg.name %> is required.")));
return NanThrowError("<%- arg.jsClassName %> <%- arg.name %> is required.");
}
<% } -%>
<% jsArg++; -%>
Expand Down
29 changes: 18 additions & 11 deletions 29 build/codegen/templates/header.h.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#ifndef <%- cppClassName.toUpperCase() %>_H
#define <%- cppClassName.toUpperCase() %>_H

#include <v8.h>
#include <node.h>
#include <nan.h>
#include <string>

#include "git2.h"
Expand All @@ -32,31 +31,26 @@ class <%- cppClassName %> : public ObjectWrap {
~<%- cppClassName %>();
<% } -%>

static Handle<Value> New(const Arguments& args);
static NAN_METHOD(New);

<% if (typeof fields != 'undefined') { -%>
<%
for (var i in fields) {
var fieldInfo = fields[i];
if (fieldInfo.ignore) continue;
-%>
static Handle<Value> <%- fieldInfo.cppFunctionName %>(const Arguments& args);
static NAN_METHOD(<%- fieldInfo.cppFunctionName %>);
<% } -%>
<% } -%>

<% if (typeof functions != 'undefined') { -%>
<%
for (var i in functions) {
var functionInfo = functions[i];
if (functionInfo.ignore) continue;
-%>
static Handle<Value> <%- functionInfo.cppFunctionName %>(const Arguments& args);
<% if (functionInfo.isAsync) { -%>
static void <%- functionInfo.cppFunctionName %>Work(uv_work_t* req);
static void <%- functionInfo.cppFunctionName %>AfterWork(uv_work_t* req);

struct <%- functionInfo.cppFunctionName %>Baton {
uv_work_t request;
int error_code;
const git_error* error;
<%
Expand All @@ -66,13 +60,26 @@ class <%- cppClassName %> : public ObjectWrap {
<% if (arg.isReturn) { -%>
<%- arg.cType.replace('**', '*') %> <%- arg.name %>;
<% } else { -%>
Persistent<Value> <%- arg.name %>Reference;
<%- arg.cType %> <%- arg.name %>;
<% } -%>
<% } -%>
Persistent<Function> callback;
};
class <%- functionInfo.cppFunctionName %>Worker : public NanAsyncWorker {
public:
<%- functionInfo.cppFunctionName %>Worker(
<%- functionInfo.cppFunctionName %>Baton *_baton,
NanCallback *callback
) : NanAsyncWorker(callback)
, baton(_baton) {};
~<%- functionInfo.cppFunctionName %>Worker() {};
void Execute();
void HandleOKCallback();

private:
<%- functionInfo.cppFunctionName %>Baton *baton;
};
<% } -%>
static NAN_METHOD(<%- functionInfo.cppFunctionName %>);
<% } -%>
<% } -%>
<% if (typeof cType != 'undefined') { -%>
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.