Repository navigation
Expand file tree
/
Copy pathclass_content.cc
More file actions
112 lines (88 loc) · 3.17 KB
/
Copy pathclass_content.cc
File metadata and controls
112 lines (88 loc) · 3.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <nan.h>
#include <string.h>
extern "C" {
#include <git2.h>
{% each cDependencies as dependency %}
#include <{{ dependency }}>
{% endeach %}
}
#include "../include/lock_master.h"
#include "../include/functions/copy.h"
#include "../include/{{ filename }}.h"
#include "nodegit_wrapper.cc"
#include "../include/async_libgit2_queue_worker.h"
{% each dependencies as dependency %}
#include "{{ dependency }}"
{% endeach %}
#include <iostream>
using namespace std;
using namespace v8;
using namespace node;
{% if cType %}
{{ cppClassName }}::~{{ cppClassName }}() {
// this will cause an error if you have a non-self-freeing object that also needs
// to save values. Since the object that will eventually free the object has no
// way of knowing to free these values.
{% each functions as function %}
{% if not function.ignore %}
{% each function.args as arg %}
{% if arg.saveArg %}
{{ function.cppFunctionName }}_{{ arg.name }}).Reset();
{% endif %}
{% endeach %}
{% endif %}
{% endeach %}
}
void {{ cppClassName }}::InitializeComponent(Local<v8::Object> target) {
Nan::HandleScope scope;
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(JSNewFunction);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(Nan::New("{{ jsClassName }}").ToLocalChecked());
{% each functions as function %}
{% if not function.ignore %}
{% if function.isPrototypeMethod %}
Nan::SetPrototypeMethod(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }});
{% else %}
Nan::SetMethod(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }});
{% endif %}
{% endif %}
{% endeach %}
{% each fields as field %}
{% if not field.ignore %}
Nan::SetPrototypeMethod(tpl, "{{ field.jsFunctionName }}", {{ field.cppFunctionName }});
{% endif %}
{% endeach %}
InitializeTemplate(tpl);
Local<Function> _constructor_template = Nan::GetFunction(tpl).ToLocalChecked();
constructor_template.Reset(_constructor_template);
Nan::Set(target, Nan::New("{{ jsClassName }}").ToLocalChecked(), _constructor_template);
}
{% else %}
void {{ cppClassName }}::InitializeComponent(Local<v8::Object> target) {
Nan::HandleScope scope;
Local<Object> object = Nan::New<Object>();
{% each functions as function %}
{% if not function.ignore %}
Nan::SetMethod(object, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }});
{% endif %}
{% endeach %}
Nan::Set(target, Nan::New<String>("{{ jsClassName }}").ToLocalChecked(), object);
}
{% endif %}
{% each functions as function %}
{% if not function.ignore %}
{% if function.isManual %}
{{= function.implementation =}}
{% elsif function.isAsync %}
{% partial asyncFunction function %}
{% else %}
{% partial syncFunction function %}
{% endif %}
{% endif %}
{% endeach %}
{% partial fields . %}
{%if cType %}
// force base class template instantiation, to make sure we get all the
// methods, statics, etc.
template class NodeGitWrapper<{{ cppClassName }}Traits>;
{% endif %}