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) 2016 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()
, New<v8::FunctionTemplate>(CallHandlerSetter)->GetFunction()
);
Set(target
, New("b").ToLocalChecked()
, New<v8::FunctionTemplate>(CallAsFunctionHandlerSetter)->GetFunction()
);
}
NODE_MODULE(setcallhandler, Init)
|