Skip to content
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
Clean up the persisting of props
  • Loading branch information
John Haley committed Feb 24, 2015
commit ce574a5a61000ef2f46d6a58480c8ae1f3ced2a3
10 changes: 3 additions & 7 deletions generate/templates/partials/sync_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
{%if not arg.payloadFor %}
{%partial convertFromV8 arg %}
{%if arg.saveArg %}
Persistent<Object> {{ arg.name }};
Handle<Object> {{ arg.name }}Handle(args[{{ arg.jsArg }}]->ToObject());
NanAssignPersistent({{ arg.name }}, {{ arg.name }}Handle);
Handle<Object> {{ arg.name }}(args[{{ arg.jsArg }}]->ToObject());
{{ cppClassName }} *thisObj = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This());

if (thisObj->{{ cppFunctionName }}_{{ arg.name }} != NULL) {
NanDisposePersistent(*thisObj->{{ cppFunctionName }}_{{ arg.name }});
}
NanDisposePersistent(thisObj->{{ cppFunctionName }}_{{ arg.name }});

thisObj->{{ cppFunctionName }}_{{ arg.name }} = &{{ arg.name }};
NanAssignPersistent(thisObj->{{ cppFunctionName }}_{{ arg.name }}, {{ arg.name }});
{%endif%}
{%endif%}
{%endif%}
Expand Down
19 changes: 5 additions & 14 deletions generate/templates/templates/class_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ using namespace node;
{{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw, bool selfFreeing) {
this->raw = raw;
this->selfFreeing = selfFreeing;

{% each functions as function %}
{% if not function.ignore %}
{% each function.args as arg %}
{% if arg.saveArg %}
{{ function.cppFunctionName }}_{{ arg.name }} = NULL;
{% endif %}
{% endeach %}
{% endif %}
{% endeach %}
}

{{ cppClassName }}::~{{ cppClassName }}() {
Expand All @@ -51,17 +41,18 @@ using namespace node;
// 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 function as function %}
{% each functions as function %}
{% if not function.ignore %}
{% each function.args as arg %}
{% if arg.saveArg %}
if ({{ function.cppFunctionName }}_{{ arg.name }} != NULL) {
NanDisposePersistent(&{{ function.cppFunctionName }}_{{ arg.name }});
}

NanDisposePersistent({{ function.cppFunctionName }}_{{ arg.name }});

{% endif %}
{% endeach %}
{% endif %}
{% endeach %}

}

void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) {
Expand Down
2 changes: 1 addition & 1 deletion generate/templates/templates/class_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class {{ cppClassName }} : public ObjectWrap {
{% if not function.ignore %}
{% each function.args as arg %}
{% if arg.saveArg %}
Persistent<Object> *{{ function.cppFunctionName }}_{{ arg.name }};
Persistent<Object> {{ function.cppFunctionName }}_{{ arg.name }};
{% endif %}
{% endeach %}
{% endif %}
Expand Down