/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License
********************************************************************/
#include
using namespace Nan; // NOLINT(build/namespaces)
static Global global;
NAN_METHOD(ReturnAValue) {
const FunctionCallbackInfo &cbinfo = info;
ReturnValue ret = cbinfo.GetReturnValue();
if (cbinfo.Length() == 1) {
ret.Set(To(info[0]).ToLocalChecked());
} else {
ret.Set(New("default").ToLocalChecked());
}
}
NAN_METHOD(ReturnPrimitive) {
info.GetReturnValue().Set(true);
}
NAN_METHOD(ReturnGlobal) {
info.GetReturnValue().Set(global);
global.Reset();
}
NAN_METHOD(ReturnUnsigned) {
info.GetReturnValue().Set(0x80000000u);
}
NAN_MODULE_INIT(Init) {
global.Reset(New(true));
Set(target
, New("r").ToLocalChecked()
, GetFunction(New(ReturnAValue)).ToLocalChecked()
);
Set(target
, New("p").ToLocalChecked()
, GetFunction(New(ReturnPrimitive)).ToLocalChecked()
);
Set(target
, New("q").ToLocalChecked()
, GetFunction(New(ReturnGlobal)).ToLocalChecked()
);
Set(target
, New("u").ToLocalChecked()
, GetFunction(New(ReturnUnsigned)).ToLocalChecked()
);
}
NODE_MODULE(returnvalue, Init)