本文整理汇总了C++中nan::FunctionCallbackInfo::GetReturnValue方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo::GetReturnValue方法的具体用法?C++ FunctionCallbackInfo::GetReturnValue怎么用?C++ FunctionCallbackInfo::GetReturnValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nan::FunctionCallbackInfo
的用法示例。
在下文中一共展示了FunctionCallbackInfo::GetReturnValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: New
void SecureCellSeal::New(const Nan::FunctionCallbackInfo<v8::Value>& args)
{
if (args.IsConstructCall()) {
if (args.Length() < 1) {
ThrowParameterError("Secure Cell (Seal) constructor",
"not enough arguments, expected master key");
args.GetReturnValue().SetUndefined();
return;
}
if (!args[0]->IsUint8Array()) {
ThrowParameterError("Secure Cell (Seal) constructor",
"master key is not a byte buffer, use ByteBuffer or Uint8Array");
args.GetReturnValue().SetUndefined();
return;
}
if (node::Buffer::Length(args[0]) == 0) {
ThrowParameterError("Secure Cell (Seal) constructor", "master key is empty");
args.GetReturnValue().SetUndefined();
return;
}
std::vector<uint8_t> key((uint8_t*)(node::Buffer::Data(args[0])),
(uint8_t*)(node::Buffer::Data(args[0]) + node::Buffer::Length(args[0])));
SecureCellSeal* obj = new SecureCellSeal(key);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {args[0]};
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
}
}
示例2: Det
/**
* Det:
* Compute the determinant of an array.
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
*
* Return value: a Number represent the determinant of the given matrix.
*/
void Det(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
v8::Local<v8::Number> num = Nan::New(inputMat.determinant());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例3: Eye
/**
* Eye:
* Creates a new nXm matrix with ones on the diagonal
* and zeros elsewhere.
*
* arguments:
* info[0]: Number n which represents the number of rows in the newly built matrix
* info[1]: Number m which represents the number of cols in the newly built matrix
* info[2]: Buffer(object created by Float64Array) for return value(eye matrix nXm).
*/
void Eye(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
Nan::ThrowTypeError("Wrong argument given, should be a number");
return;
}
if (info[2]->IsFloat64Array()) {
size_t rowsMatrix(info[0]->Uint32Value());
size_t colsMatrix(info[1]->Uint32Value());
double *refResData = *(Nan::TypedArrayContents<double>(info[2]));
Md res(refResData, rowsMatrix, colsMatrix);
res = Md::Identity(rowsMatrix, colsMatrix);
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例4: Rank
/**
* Rank:
* Return matrix rank of array using SVD method
* Rank of the array is the number of SVD singular values of the array that are greater than threshold(info[3]).
*
* arguments:
* info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Optional - Number represent the threshold which SVD values are considered zero.
* If this arg is not given, and S is an array with singular values for M,
* and eps is the epsilon value for datatype of S, then tol is set to S.max() * max(M.shape) * eps
*
* Return value: a Number represent the matrix rank of the given matrix .
*/
void Rank(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
Local<Object> matrixBuffer = info[0].As<Object>();
if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat);
if (info.Length() == 4 && info[3]->IsNumber()){
svd.setThreshold((float)info[3]->NumberValue());
}
v8::Local<v8::Number> num = Nan::New((int)svd.rank());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例5: Rank
/**
* Rank:
* Return matrix rank of array using SVD method
* Rank of the array is the number of SVD singular values of the array that are greater than threshold(info[3]).
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Optional - Number represent the threshold which SVD values are considered zero.
* If this arg is not given, and S is an array with singular values for M,
* and eps is the epsilon value for datatype of S, then tol is set to S.max() * max(M.shape) * eps
*
* Return value: a Number represent the matrix rank of the given matrix .
*/
void Rank(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat);
if (info.Length() == 4 && info[3]->IsNumber()){
svd.setThreshold((float)info[3]->NumberValue());
}
v8::Local<v8::Number> num = Nan::New((int)svd.rank());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例6: MatrixPower
/**
* MatrixPower:
* Raise a square matrix to the (integer) power n.
*
* arguments:
* info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be "powered".
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Number m represent the exponent. Can be any integer or long integer, positive, negative, or zero.
* info[4]: Buffer(object created by smalloc) for return value(M**m).
If the exponent is positive or zero then the type of the elements is the same as those of M.
If the exponent is negative the elements are floating-point.
*/
void MatrixPower(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 5) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber() || !info[3]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
Local<Object> matrixBuffer = info[0].As<Object>();
if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
double expParam(info[3]->NumberValue());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Local<Object> resBuffer = info[4].As<Object>();
if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
Md res(refResData, rowsMatrix, colsMatrix);
if(expParam == 0){
res = inputMat.Identity(rowsMatrix, colsMatrix);
}
else{
res = inputMat;
if(expParam < 0){
res = res.inverse();
}
for (int i=1; i< abs(expParam); i++)
{
res *= inputMat;
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments3");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例7: MatrixPower
/**
* MatrixPower:
* Raise a square matrix to the (integer) power n.
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be "powered".
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Number m represent the exponent. Can be any integer or long integer, positive, negative, or zero.
* info[4]: Buffer(object created by Float64Array) for return value(M**m).
If the exponent is positive or zero then the type of the elements is the same as those of M.
If the exponent is negative the elements are floating-point.
*/
void MatrixPower(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 5) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber() || !info[3]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
double expParam(info[3]->NumberValue());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
if (info[4]->IsFloat64Array()) {
double *refResData = *(Nan::TypedArrayContents<double>(info[4]));
Md res(refResData, rowsMatrix, colsMatrix);
if(expParam == 0){
res = inputMat.Identity(rowsMatrix, colsMatrix);
}
else{
res = inputMat;
if(expParam < 0){
res = res.inverse();
}
for (int i=1; i< abs(expParam); i++)
{
res *= inputMat;
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments3");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例8: New
void SecureCellContextImprint::New(const Nan::FunctionCallbackInfo<v8::Value>& args) {
if (args.IsConstructCall()) {
std::vector<uint8_t> key((uint8_t*)(node::Buffer::Data(args[0])), (uint8_t*)(node::Buffer::Data(args[0])+node::Buffer::Length(args[0])));
SecureCellContextImprint* obj = new SecureCellContextImprint(key);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = { args[0]};
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
args.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例9: New
void MeCab_Tagger::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.IsConstructCall()) {
v8::String::Utf8Value option(info[0]);
MeCab_Tagger* mecabTagger = new MeCab_Tagger(*option);
mecabTagger->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = { info[0] };
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
info.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例10: Triu
/**
* Triu:
* Creates a copy of a given matrix with all elements below the diagonal zeroed
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be converted to lower diagonal matrix
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Buffer(object created by Float64Array) for return value(M**m).
*/
void Triu(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 4) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
if (info[3]->IsFloat64Array()) {
double *refResData = *(Nan::TypedArrayContents<double>(info[3]));
Md res(refResData, rowsMatrix, colsMatrix);
for (int i = 0; i < rowsMatrix; i++) {
for (int j = 0; j < colsMatrix; j++) {
if (j < i) {
res(i, j) = 0;
} else {
res(i, j) = inputMat(i, j);
}
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong argument - output matrix data should be float64array");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong argument - input matrix data should be float64array");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例11: readPort
void readPort(const Nan::FunctionCallbackInfo<Value>& args){
char address = args[0]->NumberValue();
char port = args[1]->NumberValue();
int value = read_port(address, port);
Local<Number> num = Nan::New(value);
args.GetReturnValue().Set(num);
}
示例12: ParseAsync
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 2) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
if (!args[1]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback")));
return;
}
Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
anitomyJs::Worker *worker = new anitomyJs::Worker(callback);
if (args_length >= 3) {
Local<Value> options = args[2];
if (!ValidateOptions(options, isolate) ||
!worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
worker->GetAnitomy()->SetInput(input, isolate);
Nan::AsyncQueueWorker(worker);
args.GetReturnValue().Set(Nan::Undefined());
}
示例13: ParseSync
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 1) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
anitomyJs::AnitomyJs anitomy;
if (args_length >= 2) {
Local<Value> options = args[1];
if (!ValidateOptions(options, isolate) ||
!anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
anitomy.SetInput(input, isolate);
anitomy.Parse();
args.GetReturnValue().Set(anitomy.ParsedResult(isolate));
}
示例14: Cas
void Client::Cas(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 5, "5")
CHECK_N_ARGS_IS_A_STRING(info, 0, "0")
CHECK_N_ARGS_IS_A_STRING(info, 1, "1")
CHECK_N_ARGS_IS_A_NUMBER(info, 2, "2")
CHECK_N_ARGS_IS_A_STRING(info, 3, "3")
CHECK_N_ARGS_IS_A_FUNCTION(info, 4, "4")
const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
const string memcached_value = GET_STRING_FROM_PARAM(info[1]);
time_t ttl = info[2]->NumberValue();
// String to uint64_t
const string casString = GET_STRING_FROM_PARAM(info[3]);
uint64_t cas;
sscanf(casString.c_str(), "%" PRIu64, &cas);
Callback* callback = GET_CALLBACK_FROM_PARAM(info[4]);
JobBase* job = new CasJob(callback, memcached_key, memcached_value, ttl, cas);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例15: New
void Client::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.IsConstructCall()) {
v8::String::Utf8Value param0(info[0]->ToString());
std::string* param0String = new std::string(*param0);
const char* conf = param0String->c_str();
Client* obj = new Client(conf);
obj->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = { info[0] };
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
info.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}