Skip to content

Commit 6419faf

Browse files
committed
Enable setting arbitrary parameters as memory owner
1 parent 1be9c37 commit 6419faf

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

generate/templates/filters/fields_info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = function(fields) {
99
fieldInfo.parsedName = field.name || "result";
1010
fieldInfo.isCppClassIntType = ~["Uint32", "Int32"].indexOf(field.cppClassName);
1111
fieldInfo.parsedClassName = (field.cppClassName || '').toLowerCase() + "_t";
12+
fieldInfo.hasOwner = !!fieldInfo.ownedByThis;
1213

1314
result.push(fieldInfo);
1415
});

generate/templates/filters/returns_info.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
3434
return_info.returnNameOrName = return_info.returnName || return_info.name;
3535
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;
3636
return_info.isOutParam = true;
37-
return_info.hasOwner = return_info.ownedBy || return_info.ownedByThis;
37+
return_info.hasOwner = !!(return_info.ownedBy || return_info.ownedByThis);
3838
return_info.ownedByIndex = -1;
3939

4040
// Here we convert ownedBy, which is the name of the parameter
@@ -57,6 +57,8 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
5757
return_info.__proto__ = fn.return;
5858

5959
return_info.isAsync = isAsync;
60+
return_info.hasOwner = !!return_info.ownedByThis;
61+
return_info.ownedByIndex = -1;
6062
return_info.parsedName = return_info.name && isAsync ? "baton->" + return_info.name : "result";
6163
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
6264
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";

generate/templates/partials/convert_to_v8.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,20 @@
6565
{% if cppClassName == 'Wrapper' %}
6666
to = {{ cppClassName }}::New({{= parsedName =}});
6767
{% else %}
68-
to = {{ cppClassName }}::New({{= parsedName =}}, {{ selfFreeing|toBool }} {% if ownedByThis %}, info.This(){% endif %});
68+
to = {{ cppClassName }}::New(
69+
{{= parsedName =}},
70+
{{ selfFreeing|toBool }}
71+
{% if hasOwner %}
72+
,
73+
{% if ownedByThis %}
74+
info.This()
75+
{% elsif isAsync %}
76+
this->GetFromPersistent("{{= ownedBy =}}")
77+
{% else %}
78+
info[{{= ownedByIndex =}}]->ToObject()
79+
{% endif %}
80+
{% endif %}
81+
);
6982
{% endif %}
7083
}
7184
else {

0 commit comments

Comments
 (0)