Skip to content

Commit 17ef8ba

Browse files
John Haleytbranyen
authored andcommitted
Fixed seg faults for callback functions
1 parent f45726f commit 17ef8ba

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

generate/partials/field_accessors.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) {
3131
NanDisposePersistent(wrapper->{{ field.name }});
3232

3333
wrapper->raw->{{ field.name }} = *ObjectWrap::Unwrap<{{ field.cppClassName }}>(value->ToObject())->GetValue();
34-
{%elsif field.isFunction | or field.payloadFor %}
34+
{%elsif field.isFunction %}
3535
if (value->IsFunction()) {
3636
wrapper->credentials = new NanCallback(value.As<Function>());
3737
}
38+
{%elsif field.payloadFor %}
39+
NanAssignPersistent(wrapper->{{ field.name }}, value);
3840
{%elsif field.cppClassName == 'String' %}
3941
if (wrapper->GetValue()->{{ field.name }}) {
4042
//free(wrapper->{{ field.name }});

generate/templates/struct_content.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ void {{ cppClassName }}::ConstructFields() {
4747
{%if field.hasConstructor %}
4848
Local<Object> test = {{ field.cppClassName }}::New(&this->raw->{{ field.name }})->ToObject();
4949
NanAssignPersistent(this->{{ field.name }}, test);
50+
5051
{%elsif field.isFunction %}
52+
5153
// Set the static method call and set the payload for this function to be
5254
// the current instance
5355
this->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
5456
this->raw->{{ fields|payloadFor field.name }} = (void *)this;
57+
this->{{ field.name }} = new NanCallback();
58+
{%elsif field.payloadFor %}
59+
60+
Local<Value> {{ field.name }} = NanUndefined();
61+
NanAssignPersistent(this->{{ field.name }}, {{ field.name }});
5562
{%endif%}
5663
{%endeach%}
5764
}

0 commit comments

Comments
 (0)