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
1 change: 1 addition & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,7 @@
],
"functions": {
"git_reset": {
"isCollectionRoot": true,
"args": {
"checkout_opts": {
"isOptional": true
Expand Down
2 changes: 2 additions & 0 deletions generate/scripts/generateNativeCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module.exports = function generateNativeCode() {
cppToV8: require("../templates/filters/cpp_to_v8"),
defaultValue: require("../templates/filters/default_value"),
fieldsInfo: require("../templates/filters/fields_info"),
getCPPFunctionForRootProto: require("../templates/filters/get_cpp_function_for_root_proto"),
hasFunctionOnRootProto: require("../templates/filters/has_function_on_root_proto"),
hasReturnType: require("../templates/filters/has_return_type"),
hasReturnValue: require("../templates/filters/has_return_value"),
isArrayType: require("../templates/filters/is_array_type"),
Expand Down
12 changes: 12 additions & 0 deletions generate/templates/filters/get_cpp_function_for_root_proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function(functions) {
if (!functions || functions.length === 0) {
throw new Error("Should not be able to get function from empty function list");
}

const fun = functions.find(function(f) { return f.useAsOnRootProto; });
if (!fun) {
throw new Error("There is no function on the root prototype for this collection");
}

return fun.cppFunctionName;
};
7 changes: 7 additions & 0 deletions generate/templates/filters/has_function_on_root_proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(functions) {
if (!functions || functions.length === 0) {
return false;
}

return functions.some(function(f) { return f.useAsOnRootProto; });
};
16 changes: 14 additions & 2 deletions generate/templates/templates/class_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,27 @@ using namespace node;
void {{ cppClassName }}::InitializeComponent(v8::Local<v8::Object> target) {
Nan::HandleScope scope;

v8::Local<Object> object = Nan::New<Object>();
{% if functions|hasFunctionOnRootProto %}
v8::Local<FunctionTemplate> object = Nan::New<FunctionTemplate>({{ functions|getCPPFunctionForRootProto }});
{% else %}
v8::Local<Object> object = Nan::New<Object>();
{% endif %}

{% each functions as function %}
{% if not function.ignore %}
Nan::SetMethod(object, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }});
{% endif %}
{% endeach %}

Nan::Set(target, Nan::New<String>("{{ jsClassName }}").ToLocalChecked(), object);
Nan::Set(
target,
Nan::New("{{ jsClassName }}").ToLocalChecked(),
{% if functions|hasFunctionOnRootProto %}
Nan::GetFunction(object).ToLocalChecked()
{% else %}
object
{% endif %}
);
}

{% endif %}
Expand Down