Skip to content

Commit 396a039

Browse files
committed
Merge pull request nodegit#421 from nodegit/fix-saved-props
Allow for saving of props to an object
2 parents 082e1aa + 3e00abf commit 396a039

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

generate/input/descriptor.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,13 @@
13721372
"git_remote_rename": {
13731373
"ignore": true
13741374
},
1375+
"git_remote_set_callbacks": {
1376+
"args": {
1377+
"callbacks": {
1378+
"saveArg": true
1379+
}
1380+
}
1381+
},
13751382
"git_remote_set_fetch_refspecs": {
13761383
"ignore": true
13771384
},

generate/templates/partials/sync_function.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
1818
{%if not arg.isCallbackFunction %}
1919
{%if not arg.payloadFor %}
2020
{%partial convertFromV8 arg %}
21+
{%if arg.saveArg %}
22+
Persistent<Object> {{ arg.name }};
23+
Handle<Object> {{ arg.name }}Handle(args[{{ arg.jsArg }}]->ToObject());
24+
NanAssignPersistent({{ arg.name }}, {{ arg.name }}Handle);
25+
{{ cppClassName }} *thisObj = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This());
26+
27+
if (thisObj->{{ cppFunctionName }}_{{ arg.name }} != NULL) {
28+
NanDisposePersistent(*thisObj->{{ cppFunctionName }}_{{ arg.name }});
29+
}
30+
31+
thisObj->{{ cppFunctionName }}_{{ arg.name }} = &{{ arg.name }};
32+
{%endif%}
2133
{%endif%}
2234
{%endif%}
2335
{%endif%}

generate/templates/templates/class_content.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ using namespace node;
2929
{{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw, bool selfFreeing) {
3030
this->raw = raw;
3131
this->selfFreeing = selfFreeing;
32+
33+
{% each functions as function %}
34+
{% if not function.ignore %}
35+
{% each function.args as arg %}
36+
{% if arg.saveArg %}
37+
{{ function.cppFunctionName }}_{{ arg.name }} = NULL;
38+
{% endif %}
39+
{% endeach %}
40+
{% endif %}
41+
{% endeach %}
3242
}
3343

3444
{{ cppClassName }}::~{{ cppClassName }}() {
@@ -37,6 +47,21 @@ using namespace node;
3747
{{ freeFunctionName }}(this->raw);
3848
}
3949
{% endif %}
50+
51+
// this will cause an error if you have a non-self-freeing object that also needs
52+
// to save values. Since the object that will eventually free the object has no
53+
// way of knowing to free these values.
54+
{% each function as function %}
55+
{% if not function.ignore %}
56+
{% each function.args as arg %}
57+
{% if arg.saveArg %}
58+
if ({{ function.cppFunctionName }}_{{ arg.name }} != NULL) {
59+
NanDisposePersistent(&{{ function.cppFunctionName }}_{{ arg.name }});
60+
}
61+
{% endif %}
62+
{% endeach %}
63+
{% endif %}
64+
{% endeach %}
4065
}
4166

4267
void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) {

generate/templates/templates/class_header.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,26 @@ class {{ cppClassName }} : public ObjectWrap {
7373
{% endeach %}
7474
{% endif %}
7575
{% endeach %}
76+
77+
7678
private:
79+
80+
7781
{%if cType%}
7882
{{ cppClassName }}({{ cType }} *raw, bool selfFreeing);
7983
~{{ cppClassName }}();
8084
{%endif%}
8185

86+
{% each functions as function %}
87+
{% if not function.ignore %}
88+
{% each function.args as arg %}
89+
{% if arg.saveArg %}
90+
Persistent<Object> *{{ function.cppFunctionName }}_{{ arg.name }};
91+
{% endif %}
92+
{% endeach %}
93+
{% endif %}
94+
{% endeach %}
95+
8296
static NAN_METHOD(JSNewFunction);
8397

8498
{%each fields as field%}

0 commit comments

Comments
 (0)