MCPcopy Create free account
hub / github.com/nodejs/nan / NAN_MODULE_INIT

Function NAN_MODULE_INIT

test/cpp/settemplate.cpp:35–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33void Foo(FunctionCallbackInfo<v8::Value> const&) {}
34
35NAN_MODULE_INIT(MyObject::Init) {
36 // Prepare constructor template
37 v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
38 tpl->SetClassName(Nan::New<v8::String>("MyObject").ToLocalChecked());
39 tpl->InstanceTemplate()->SetInternalFieldCount(1);
40
41 // Prototype
42 SetPrototypeTemplate(
43 tpl
44 , "prototypeProp"
45 , Nan::New<v8::String>("a prototype property").ToLocalChecked());
46
47 // Instance
48 SetInstanceTemplate(
49 tpl
50 , "instanceProp"
51 , Nan::New<v8::String>("an instance property").ToLocalChecked());
52
53 // PropertyAttributes
54 SetInstanceTemplate(
55 tpl
56 , Nan::New<v8::String>("none").ToLocalChecked()
57 , Nan::New<v8::String>("none").ToLocalChecked()
58 , v8::None);
59 SetInstanceTemplate(
60 tpl
61 , Nan::New<v8::String>("readOnly").ToLocalChecked()
62 , Nan::New<v8::String>("readOnly").ToLocalChecked()
63 , v8::ReadOnly);
64 SetInstanceTemplate(
65 tpl
66 , Nan::New<v8::String>("dontEnum").ToLocalChecked()
67 , Nan::New<v8::String>("dontEnum").ToLocalChecked()
68 , v8::DontEnum);
69 SetInstanceTemplate(
70 tpl
71 , Nan::New<v8::String>("dontDelete").ToLocalChecked()
72 , Nan::New<v8::String>("dontDelete").ToLocalChecked()
73 , v8::DontDelete);
74
75 v8::Local<v8::Function> function = Nan::GetFunction(tpl).ToLocalChecked();
76 constructor.Reset(function);
77 Set(target
78 , Nan::New<v8::String>("MyObject").ToLocalChecked()
79 , function);
80
81
82 //=== SetMethod ==============================================================
83
84 v8::Local<v8::Object> obj = Nan::New<v8::Object>();
85 SetMethod(obj, "foo", Foo);
86
87 // https://github.com/nodejs/nan/issues/564
88 v8::Local<v8::Function> func = Nan::New<v8::Function>(Foo);
89 SetMethod(func, "foo", Foo);
90
91 v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(Foo);
92 SetMethod(t, "foo", Foo);

Callers

nothing calls this directly

Calls 7

SetPrototypeTemplateFunction · 0.85
SetInstanceTemplateFunction · 0.85
SetMethodFunction · 0.85
ToLocalCheckedMethod · 0.80
GetFunctionFunction · 0.50
SetFunction · 0.50
ResetMethod · 0.45

Tested by

no test coverage detected