forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_function.cc
More file actions
81 lines (74 loc) · 2.02 KB
/
Copy pathsync_function.cc
File metadata and controls
81 lines (74 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{%partial doc .%}
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
NanEscapableScope();
{%partial guardArguments .%}
{%each .|returnsInfo 'true' as _return %}
{%if _return.shouldAlloc %}
{{ _return.cType }}{{ _return.name }} = ({{ _return.cType }})malloc(sizeof({{ _return.cType|unPointer }}));
{%else%}
{{ _return.cType|unPointer }} {{ _return.name }} = {{ _return.cType|unPointer|defaultValue }};
{%endif%}
{%endeach%}
{%each args|argsInfo as arg %}
{%if not arg.isSelf %}
{%if not arg.isReturn %}
{%partial convertFromV8 arg %}
{%endif%}
{%endif%}
{%endeach%}
{%if .|hasReturns %}
{{ return.cType }} result = {%endif%}{{ cFunctionName }}(
{%each args|argsInfo as arg %}
{%if arg.isReturn %}
{%if not arg.shouldAlloc %}&{%endif%}
{%endif%}
{%if arg.isSelf %}
ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue()
{%elsif arg.isReturn %}
{{ arg.name }}
{%else%}
from_{{ arg.name }}
{%endif%}
{%if not arg.lastArg %},{%endif%}
{%endeach%}
);
{%if return.isErrorCode %}
if (result != GIT_OK) {
{%each args|argsInfo as arg %}
{%if arg.shouldAlloc %}
free({{ arg.name }});
{%endif%}
{%endeach%}
if (giterr_last()) {
return NanThrowError(giterr_last()->message);
} else {
return NanThrowError("Unknown Error");
}
}
{%endif%}
{%if not .|returnsCount %}
NanReturnUndefined();
{%else%}
{%if return.cType | isPointer %}
// null checks on pointers
if (!result) {
NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
}
{%endif%}
Handle<Value> to;
{%if .|returnsCount > 1 %}
Handle<Object> toReturn = NanNew<Object>();
{%endif%}
{%each .|returnsInfo as _return %}
{%partial convertToV8 _return %}
{%if .|returnsCount > 1 %}
toReturn->Set(NanNew<String>("{{ _return.jsNameOrName }}"), to);
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
NodeGitPsueodoNanReturnEscapingValue(to);
{%else%}
NodeGitPsueodoNanReturnEscapingValue(toReturn);
{%endif%}
{%endif%}
}