mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 06:53:52 +00:00

* Get rid of recursive `make` when building the node binary. An earlier commit makes GYP write out rules that we can use for proper dependency tracking. * Use module name 'binding' in addons.md and addons-napi/*/binding.gyp. This massively simplifies the logic for generating the build rules. * Check in auto-generated add-on tests from `doc/api/addons.md`. The files change rarely and generating them dynamically causes no end of race conditions and special-casing during the build. PR-URL: https://github.com/nodejs/node/pull/17407 Reviewed-By: Richard Lau <riclau@uk.ibm.com>
40 lines
984 B
C++
40 lines
984 B
C++
// 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
|