Skip to content

Commit 7eb2108

Browse files
author
John Haley
committed
Add ClearValue method to structs and classes
1 parent be57dcb commit 7eb2108

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

generate/templates/partials/sync_function.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ from_{{ arg.name }}
7474
{%endif%}
7575

7676
{% if cppFunctionName == "Free" %}
77-
// FIXME Stuck here unable to NULL out this->repo
78-
// ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->SetValue(NULL);
77+
ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->ClearValue();
7978
}
8079
{% endif %}
8180

generate/templates/templates/class_content.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ using namespace node;
113113
}
114114

115115
{{ cType }} **{{ cppClassName }}::GetRefValue() {
116-
return &this->raw;
116+
return this->raw == NULL ? NULL : &this->raw;
117+
}
118+
119+
void {{ cppClassName }}::ClearValue() {
120+
this->raw = NULL;
117121
}
118122

119123
{% else %}

generate/templates/templates/class_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class {{ cppClassName }} : public ObjectWrap {
3838
{%if cType%}
3939
{{ cType }} *GetValue();
4040
{{ cType }} **GetRefValue();
41+
void ClearValue();
4142

4243
static Handle<v8::Value> New(void *raw, bool selfFreeing);
4344
{%endif%}

generate/templates/templates/struct_content.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ Handle<v8::Value> {{ cppClassName }}::New(void* raw, bool selfFreeing) {
138138
}
139139

140140
{{ cType }} **{{ cppClassName }}::GetRefValue() {
141-
return &this->raw;
141+
return this->raw == NULL ? NULL : &this->raw;
142+
}
143+
144+
void {{ cppClassName }}::ClearValue() {
145+
this->raw = NULL;
142146
}
143147

144148
{% partial fieldAccessors . %}

generate/templates/templates/struct_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class {{ cppClassName }} : public ObjectWrap {
2626

2727
{{ cType }} *GetValue();
2828
{{ cType }} **GetRefValue();
29+
void ClearValue();
2930

3031
static Handle<v8::Value> New(void *raw, bool selfFreeing);
3132

0 commit comments

Comments
 (0)