本文整理汇总了C++中nan::FunctionCallbackInfo::Holder方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo::Holder方法的具体用法?C++ FunctionCallbackInfo::Holder怎么用?C++ FunctionCallbackInfo::Holder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nan::FunctionCallbackInfo
的用法示例。
在下文中一共展示了FunctionCallbackInfo::Holder方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: DictionaryInfo
void MeCab_Tagger::DictionaryInfo(const Nan::FunctionCallbackInfo<v8::Value>& info) {
MeCab_Tagger* obj = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
v8::Local<v8::Function> callback = info[0].As<v8::Function>();
const MeCab::DictionaryInfo *dic = obj->tagger->dictionary_info();
std::vector<v8::Local<v8::Object>> info_list;
for (; dic; dic = dic->next) {
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New("filename").ToLocalChecked(), Nan::New(dic->filename).ToLocalChecked());
obj->Set(Nan::New("charset").ToLocalChecked(), Nan::New(dic->charset).ToLocalChecked());
obj->Set(Nan::New("size").ToLocalChecked(), Nan::New(dic->size));
obj->Set(Nan::New("type").ToLocalChecked(), Nan::New(dic->type));
obj->Set(Nan::New("lsize").ToLocalChecked(), Nan::New(dic->lsize));
obj->Set(Nan::New("rsize").ToLocalChecked(), Nan::New(dic->rsize));
obj->Set(Nan::New("version").ToLocalChecked(), Nan::New(dic->version));
info_list.push_back(obj);
}
v8::Local<v8::Array> results = Nan::New<v8::Array>(info_list.size());
for(unsigned int i = 0; i < results->Length(); ++i) {
results->Set(i, info_list.at(i));
}
const unsigned argc = 2;
v8::Local<v8::Value> argv[] = {
Nan::Null(),
results
};
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
示例3: Debug
void Client::Debug(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 1, "1")
CHECK_N_ARGS_IS_A_BOOLEAN(info, 0, "0")
memClient->debug = info[0]->ToBoolean()->Value();
info.GetReturnValue().Set(Nan::Undefined());
}
示例4: Stop
void Client::Stop(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 1, "1")
CHECK_N_ARGS_IS_A_FUNCTION(info, 0, "0")
Callback* callback = new Callback(info[0].As<v8::Function>());
memClient->progressWorker->setCallback(callback);
memClient->isRunning = false;
}
示例5: Parse
void MeCab_Tagger::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) {
MeCab_Tagger* mecabTagger = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
v8::String::Utf8Value input(info[0]);
v8::Local<v8::Function> callback = info[1].As<v8::Function>();
const char *result = mecabTagger->tagger->parse(*input);
const unsigned argc = 2;
v8::Local<v8::Value> argv[] = {
Nan::Null(),
Nan::New(result).ToLocalChecked()
};
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
示例6: FetchResult
void Client::FetchResult(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 1, "1")
CHECK_N_ARGS_IS_A_FUNCTION(info, 0, "0")
Callback* callback = GET_CALLBACK_FROM_PARAM(info[0]);
JobBase* job = new FetchResultJob(callback);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例7: Exist
void Client::Exist(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 2, "2")
CHECK_N_ARGS_IS_A_STRING(info, 0, "0")
CHECK_N_ARGS_IS_A_FUNCTION(info, 1, "1")
const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
Callback* callback = GET_CALLBACK_FROM_PARAM(info[1]);
JobBase* job = new ExistJob(callback, memcached_key);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例8: Delete
void Client::Delete(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 3, "3")
CHECK_N_ARGS_IS_A_STRING(info, 0, "0")
CHECK_N_ARGS_IS_AN_UNSIGNED_INTEGER(info, 1, "1")
CHECK_N_ARGS_IS_A_FUNCTION(info, 2, "2")
const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
uint32_t expirationTime = (uint32_t) GET_NUMBER_FROM_PARAM(info[1]);
Callback* callback = GET_CALLBACK_FROM_PARAM(info[2]);
JobBase* job = new DeleteJob(callback, memcached_key, expirationTime);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例9: Replace
void Client::Replace(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 4, "4")
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_FUNCTION(info, 3, "3")
const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
const string memcached_value = GET_STRING_FROM_PARAM(info[1]);
time_t ttl = (time_t) GET_NUMBER_FROM_PARAM(info[2]);
Callback* callback = GET_CALLBACK_FROM_PARAM(info[3]);
JobBase* job = new ReplaceJob(callback, memcached_key, memcached_value, ttl);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例10: ParseToNode
void MeCab_Tagger::ParseToNode(const Nan::FunctionCallbackInfo<v8::Value>& info) {
MeCab_Tagger* mecabTagger = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
v8::String::Utf8Value input(info[0]);
v8::Local<v8::Function> callback = info[1].As<v8::Function>();
std::vector<v8::Local<v8::Object>> node_list;
const MeCab::Node* node = mecabTagger->tagger->parseToNode(*input);
for (; node; node = node->next) {
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New("word").ToLocalChecked(), Nan::New(std::string(node->surface, node->length)).ToLocalChecked());
obj->Set(Nan::New("id").ToLocalChecked(), Nan::New(node->id));
obj->Set(Nan::New("surface").ToLocalChecked(), Nan::New(node->surface).ToLocalChecked());
obj->Set(Nan::New("feature").ToLocalChecked(), Nan::New(node->feature).ToLocalChecked());
obj->Set(Nan::New("len").ToLocalChecked(), Nan::New(node->length));
obj->Set(Nan::New("rcAttr").ToLocalChecked(), Nan::New(node->rcAttr));
obj->Set(Nan::New("lcAttr").ToLocalChecked(), Nan::New(node->lcAttr));
obj->Set(Nan::New("posid").ToLocalChecked(), Nan::New(node->posid));
obj->Set(Nan::New("char_type").ToLocalChecked(), Nan::New(node->char_type));
obj->Set(Nan::New("stat").ToLocalChecked(), Nan::New(node->stat));
obj->Set(Nan::New("isbest").ToLocalChecked(), Nan::New(node->isbest));
obj->Set(Nan::New("alpha").ToLocalChecked(), Nan::New(node->alpha));
obj->Set(Nan::New("beta").ToLocalChecked(), Nan::New(node->beta));
obj->Set(Nan::New("prob").ToLocalChecked(), Nan::New(node->prob));
obj->Set(Nan::New("cost").ToLocalChecked(), Nan::New((int)node->cost));
node_list.push_back(obj);
}
v8::Local<v8::Array> results = Nan::New<v8::Array>(node_list.size());
for(unsigned int i = 0; i < results->Length(); ++i) {
results->Set(i, node_list.at(i));
}
const unsigned argc = 2;
v8::Local<v8::Value> argv[] = {
Nan::Null(),
results
};
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
示例11: MGetAndFetchAll
void Client::MGetAndFetchAll(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 2, "2")
CHECK_N_ARGS_IS_AN_ARRAY(info, 0, "0")
CHECK_N_ARGS_IS_A_FUNCTION(info, 1, "1")
v8::Local<v8::Object> arr = info[0]->ToObject();
size_t number_of_keys = arr->GetOwnPropertyNames()->Length();
memClient->debug && printf("%s %lu %s\n", "Array with", number_of_keys, "keys");
std::vector<string> keys;
for(size_t i = 0; i < number_of_keys; i++) {
keys.push_back(GET_STRING_FROM_PARAM(arr->Get(i)));
}
Callback* callback = GET_CALLBACK_FROM_PARAM(info[1]);
JobBase* job = new MGetAndFetchAllJob(callback, keys);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例12: Start
void Client::Start(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
memClient->isRunning = true;
memClient->progressWorker = new MemcachedAsyncProgressWorker(memClient, new Callback());
Nan::AsyncQueueWorker(memClient->progressWorker);
}
示例13: asyncForTiles
inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
ParameterParser argsToParams,
ServiceMemFn service,
bool requires_multiple_coordinates)
{
auto params = argsToParams(info, requires_multiple_coordinates);
if (!params)
return;
auto pluginParams = argumentsToPluginParameters(info);
BOOST_ASSERT(params->IsValid());
if (!info[info.Length() - 1]->IsFunction())
return Nan::ThrowTypeError("last argument must be a callback function");
auto *const self = Nan::ObjectWrap::Unwrap<Engine>(info.Holder());
using ParamPtr = decltype(params);
struct Worker final : Nan::AsyncWorker
{
using Base = Nan::AsyncWorker;
Worker(std::shared_ptr<osrm::OSRM> osrm_,
ParamPtr params_,
ServiceMemFn service,
Nan::Callback *callback,
PluginParameters pluginParams_)
: Base(callback), osrm{std::move(osrm_)}, service{std::move(service)},
params{std::move(params_)}, pluginParams{std::move(pluginParams_)}
{
}
void Execute() override try
{
const auto status = ((*osrm).*(service))(*params, result);
ParseResult(status, result);
}
catch (const std::exception &e)
{
SetErrorMessage(e.what());
}
void HandleOKCallback() override
{
Nan::HandleScope scope;
const constexpr auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), render(result)};
callback->Call(argc, argv);
}
// Keeps the OSRM object alive even after shutdown until we're done with callback
std::shared_ptr<osrm::OSRM> osrm;
ServiceMemFn service;
const ParamPtr params;
const PluginParameters pluginParams;
std::string result;
};
auto *callback = new Nan::Callback{info[info.Length() - 1].As<v8::Function>()};
Nan::AsyncQueueWorker(
new Worker{self->this_, std::move(params), service, callback, std::move(pluginParams)});
}