summaryrefslogtreecommitdiff
path: root/test/addons/04_function_factory/binding.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/addons/04_function_factory/binding.cc')
-rw-r--r--test/addons/04_function_factory/binding.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/addons/04_function_factory/binding.cc b/test/addons/04_function_factory/binding.cc
new file mode 100644
index 0000000000..4891aa6b7b
--- /dev/null
+++ b/test/addons/04_function_factory/binding.cc
@@ -0,0 +1,39 @@
+// Auto-generated by `node tools/doc/addon-verify.js`
+// binding.cc
+#include <node.h>
+
+namespace demo {
+
+using v8::Function;
+using v8::FunctionCallbackInfo;
+using v8::FunctionTemplate;
+using v8::Isolate;
+using v8::Local;
+using v8::Object;
+using v8::String;
+using v8::Value;
+
+void MyFunction(const FunctionCallbackInfo<Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+ args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
+}
+
+void CreateFunction(const FunctionCallbackInfo<Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
+ Local<Function> fn = tpl->GetFunction();
+
+ // omit this to make it anonymous
+ fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
+
+ args.GetReturnValue().Set(fn);
+}
+
+void Init(Local<Object> exports, Local<Object> module) {
+ NODE_SET_METHOD(module, "exports", CreateFunction);
+}
+
+NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
+
+} // namespace demo