-
-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathsetcallhandler.cpp
46 lines (37 loc) · 1.25 KB
/
setcallhandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#include <nan.h>
using namespace Nan; // NOLINT(build/namespaces)
NAN_METHOD(CallHandler) {
info.GetReturnValue().Set(12);
}
NAN_METHOD(CallHandlerSetter) {
v8::Local<v8::FunctionTemplate> tpl = New<v8::FunctionTemplate>();
SetCallHandler(tpl, CallHandler);
info.GetReturnValue().Set(GetFunction(tpl).ToLocalChecked());
}
NAN_METHOD(CallAsFunctionHandler) {
info.GetReturnValue().Set(15);
}
NAN_METHOD(CallAsFunctionHandlerSetter) {
v8::Local<v8::ObjectTemplate> tpl = New<v8::ObjectTemplate>();
SetCallAsFunctionHandler(tpl, CallAsFunctionHandler);
info.GetReturnValue().Set(NewInstance(tpl).ToLocalChecked());
}
NAN_MODULE_INIT(Init) {
Set(target
, New("a").ToLocalChecked()
, GetFunction(New<v8::FunctionTemplate>(CallHandlerSetter)).ToLocalChecked()
);
Set(target
, New("b").ToLocalChecked()
, GetFunction(New<v8::FunctionTemplate>(CallAsFunctionHandlerSetter))
.ToLocalChecked()
);
}
NODE_MODULE(setcallhandler, Init)