Skip to content

Commit 099bb11

Browse files
committed
First attempt at a fix for unallocated raw values
This will only handle string defaults, to satisfy the test, although moving forward we should think about reasonable defaults for all uninitialized properties. Another potential issue with this is that I'm treating all strings as uninitialized, which is probably not what we want, or is it? I could envision a supplemental property that indicates this value should be NULL initialized on `New` of its respective type.
1 parent ee8a8af commit 099bb11

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎generate/templates/partials/field_accessors.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
}
1919

2020
{% elsif field.cppClassName == 'String' %}
21-
if (wrapper->GetValue()->{{ field.name }}) {
21+
if (wrapper->GetValue()->{{ field.name }} != NULL) {
2222
info.GetReturnValue().Set(Nan::New<String>(wrapper->GetValue()->{{ field.name }}).ToLocalChecked());
2323
}
2424
else {
25-
return;
25+
info.GetReturnValue().Set(Nan::New<String>("").ToLocalChecked());
2626
}
2727

2828
{% elsif field.cppClassName|isV8Value %}

‎generate/templates/templates/struct_content.cc‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ NAN_METHOD({{ cppClassName }}::JSNewFunction) {
123123

124124
instance->Wrap(info.This());
125125

126+
// Set default uninitialized property values.
127+
{% each fields as field %}
128+
{% if not field.ignore %}
129+
{% if not field | isPayload %}
130+
{% if field.cppClassName == "String" %}
131+
instance->raw->{{ field.name }} = NULL;
132+
{% endif %}
133+
{% endif %}
134+
{% endif %}
135+
{% endeach %}
136+
126137
info.GetReturnValue().Set(info.This());
127138
}
128139

0 commit comments

Comments
 (0)