Skip to content

Commit 408d904

Browse files
committed
Merge pull request #423 from nodegit/fix-save-props-part-deux
Clean up the persisting of props
2 parents 396a039 + ce574a5 commit 408d904

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

generate/templates/partials/sync_function.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
1919
{%if not arg.payloadFor %}
2020
{%partial convertFromV8 arg %}
2121
{%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);
22+
Handle<Object> {{ arg.name }}(args[{{ arg.jsArg }}]->ToObject());
2523
{{ cppClassName }} *thisObj = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This());
2624

27-
if (thisObj->{{ cppFunctionName }}_{{ arg.name }} != NULL) {
28-
NanDisposePersistent(*thisObj->{{ cppFunctionName }}_{{ arg.name }});
29-
}
25+
NanDisposePersistent(thisObj->{{ cppFunctionName }}_{{ arg.name }});
3026

31-
thisObj->{{ cppFunctionName }}_{{ arg.name }} = &{{ arg.name }};
27+
NanAssignPersistent(thisObj->{{ cppFunctionName }}_{{ arg.name }}, {{ arg.name }});
3228
{%endif%}
3329
{%endif%}
3430
{%endif%}

generate/templates/templates/class_content.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ 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 %}
4232
}
4333

4434
{{ cppClassName }}::~{{ cppClassName }}() {
@@ -51,17 +41,18 @@ using namespace node;
5141
// this will cause an error if you have a non-self-freeing object that also needs
5242
// to save values. Since the object that will eventually free the object has no
5343
// way of knowing to free these values.
54-
{% each function as function %}
44+
{% each functions as function %}
5545
{% if not function.ignore %}
5646
{% each function.args as arg %}
5747
{% if arg.saveArg %}
58-
if ({{ function.cppFunctionName }}_{{ arg.name }} != NULL) {
59-
NanDisposePersistent(&{{ function.cppFunctionName }}_{{ arg.name }});
60-
}
48+
49+
NanDisposePersistent({{ function.cppFunctionName }}_{{ arg.name }});
50+
6151
{% endif %}
6252
{% endeach %}
6353
{% endif %}
6454
{% endeach %}
55+
6556
}
6657

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

generate/templates/templates/class_header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class {{ cppClassName }} : public ObjectWrap {
8787
{% if not function.ignore %}
8888
{% each function.args as arg %}
8989
{% if arg.saveArg %}
90-
Persistent<Object> *{{ function.cppFunctionName }}_{{ arg.name }};
90+
Persistent<Object> {{ function.cppFunctionName }}_{{ arg.name }};
9191
{% endif %}
9292
{% endeach %}
9393
{% endif %}

0 commit comments

Comments
 (0)