本文整理汇总了C++中FunctionCallbackInfo类的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo类的具体用法?C++ FunctionCallbackInfo怎么用?C++ FunctionCallbackInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FunctionCallbackInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EnableProvider
void ETW::EnableProvider(const FunctionCallbackInfo<Value>& args)
{
GUID nodeGuid;
int wchars_num = MultiByteToWideChar(CP_UTF8 , 0 , *String::Utf8Value(args[0]), -1, NULL , 0 );
wchar_t* szGuid = new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, *String::Utf8Value(args[0]), -1, szGuid, wchars_num);
ZeroMemory(&nodeGuid, sizeof(GUID));
if (IIDFromString(szGuid, &nodeGuid) != S_OK)
{
delete[] szGuid;
Nan::ThrowTypeError("First argument must be a valid GUID in the form of \"{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\"");
return;
}
delete[] szGuid;
UCHAR logLevel = args[1]->Uint32Value();
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
ETW* obj = ObjectWrap::Unwrap<ETW>(args.Holder());
args.GetReturnValue().Set(Boolean::New(isolate, obj->m_pTraceSession->EnableProvider(nodeGuid, logLevel)));
}
示例2: PassArray
void PassArray(const FunctionCallbackInfo<Value>& args) {
Isolate * isolate = args.GetIsolate();
Local<Array> array = Local<Array>::Cast(args[0]);
if ( args.Length() < 1 || ! args[0]->IsArray()) {
return;
}
if (array->Length() < 3) {
return;
}
Local<String> prop = String::NewFromUtf8(isolate, "not_index");
if (array->Get(prop)->IsUndefined() ){
return;
}
for (unsigned int i = 0; i < 3; i++ ) {
if (array->Has(i)) {
Local<Value> v = array->Get(i);
if ( !v->IsNumber()) return;
double value = v->NumberValue();
array->Set(i, Number::New(isolate, value + 1));
}
else {
return;
}
}
Local<Array> a = Array::New(isolate);
a->Set(0, array->Get(0));
a->Set(1, array->Get(prop));
a->Set(2, array->Get(2));
args.GetReturnValue().Set(a);
}
示例3: gum_script_process_on_enumerate_threads
static void
gum_script_process_on_enumerate_threads (
const FunctionCallbackInfo<Value> & info)
{
GumScriptMatchContext ctx;
ctx.self = static_cast<GumScriptProcess *> (
info.Data ().As<External> ()->Value ());
ctx.isolate = info.GetIsolate ();
Local<Value> callbacks_value = info[0];
if (!callbacks_value->IsObject ())
{
ctx.isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (
ctx.isolate, "Process.enumerateThreads: argument must be "
"a callback object")));
return;
}
Local<Object> callbacks = Local<Object>::Cast (callbacks_value);
if (!_gum_script_callbacks_get (callbacks, "onMatch", &ctx.on_match,
ctx.self->core))
{
return;
}
if (!_gum_script_callbacks_get (callbacks, "onComplete", &ctx.on_complete,
ctx.self->core))
{
return;
}
ctx.receiver = info.This ();
gum_process_enumerate_threads (gum_script_process_thread_match, &ctx);
ctx.on_complete->Call (ctx.receiver, 0, 0);
}
示例4: JS_Connect
void MySQL::JS_Connect(const FunctionCallbackInfo<Value> & args){
auto mysql = Instance(args.Holder());
auto mysqlconn = ConnectionInstance(args.Holder());
string host = JS2STRING(args[0]);
string user = JS2STRING(args[1]);
string password = JS2STRING(args[2]);
string database = JS2STRING(args[3]);
if (args[4]->IsFunction()){
Persistent<Function,CopyablePersistentTraits<Function>> func;
func.Reset(args.GetIsolate(), Local<Function>::Cast(args[4]));
thread( [mysql, mysqlconn, host, user, password, database,func](){
mysql_thread_init();
std::lock_guard<std::mutex> lock{ mysqlconn->lock };
mysql->ConnectAsync(mysqlconn->id, host, user, password, database,func);
mysql_thread_end();
}).detach();
}
else {
if (mysql_real_connect(
mysqlconn->mysql,
host.c_str(),
user.c_str(),
password.c_str(),
database.c_str(),
0,
NULL,
0) == NULL){
sjs::logger::error("MySQL Connect Error: %s", mysql_error(mysqlconn->mysql));
args.GetReturnValue().Set(false);
return;
}
}
args.GetReturnValue().Set(true);
}
示例5: exec
void Query::exec(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() != 1) {
Local<String> str = String::NewFromUtf8(isolate, "Baloo.Query.exec expects 1 agument");
isolate->ThrowException(Exception::TypeError(str));
return;
}
if (!args[0]->IsFunction()) {
Local<String> str = String::NewFromUtf8(isolate, "Argument must be a callback function");
isolate->ThrowException(Exception::TypeError(str));
return;
}
Query* query = ObjectWrap::Unwrap<Query>(args.Holder());
Baloo::Query q = query->m_query;
Baloo::ResultIterator it = q.exec();
QStringList results;
while (it.next()) {
results << it.filePath();
}
Handle<Array> array = Array::New(isolate, results.size());
for (int i = 0; i < results.length(); i++) {
const QByteArray arr = results[i].toUtf8();
Local<String> str = String::NewFromUtf8(isolate, arr.constData());
array->Set(i, str);
}
Local<Function> cb = Local<Function>::Cast(args[0]);
Local<Value> argv[1] = { array };
cb->Call(isolate->GetCurrentContext()->Global(), 1, argv);
}
示例6: New
void BoilerControlWrapper::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.IsConstructCall()) {
// Invoked as constructor: `new MyObject(...)`
int pin = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
BoilerControlWrapper* obj;
if(args[1]->IsUndefined()) {
obj = new BoilerControlWrapper(pin);
}
else {
obj = new BoilerControlWrapper(pin, args[1]->NumberValue());
}
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
// Invoked as plain function `MyObject(...)`, turn into construct call.
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
args.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例7: New
void LCDWrapper::New(const FunctionCallbackInfo<Value>& args){
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
uint8_t _add = 0x01;
// If there are two params: First Param => i2c address, second => Port number
// - Only one Param, this means that the given param is the Port Number,
LCDWrapper* obj;
uint8_t _argc = args.Length();
if(args.IsConstructCall()){
// Invoked as constructor: `new MyObject(...)`
switch(_argc){
case 0:
obj = new LCDWrapper();
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
break;
case 1:
_add = (uint8_t) args[0]->NumberValue();
obj = new LCDWrapper(_add);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
break;
default:
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong arguments...")));
}
}else{
// Invoked as plain function `MyObject(...)`, turn into construct call.
if(_argc > 1){
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong arguments...")));
}
Local<Value>* argv = new Local<Value>[_argc];
for(uint8_t i = 0; i < _argc; i++){
argv[i] = args[i];
}
Local<Function> cons = Local<Function>::New(isolate, constructor);
args.GetReturnValue().Set(cons->NewInstance(_argc, argv));
}
}
示例8: JS_GlobalEvent
void SAMPJS::JS_GlobalEvent(const FunctionCallbackInfo<Value> &args){
for (auto scriptv : scripts){
//Isolate *isolate = script.second->GetIsolate();
// Local<Context> context = Local<Context>::New(isolate, script.second->GetContext());
auto script = scripts_map[scriptv];
string name;
if (args.Length() > 0){
if (!args[0]->IsString()){
return;
}
name = JS2STRING(args[0]);
Local<Value> * argv = NULL;
int argc = args.Length() - 1;
if (args.Length() > 1){
argv = new Local<Value>[args.Length() - 1];
for (int i = 1; i < args.Length(); i++){
argv[i-1] = args[i];
}
}
script->Server()->FireEvent(name, argc, argv );
}
}
}
示例9: ClearCallback
void WeakRef::ClearCallback(const FunctionCallbackInfo<Value>& args)
{
try
{
auto holder = args.This();
auto isolate = args.GetIsolate();
holder->SetHiddenValue(V8StringConstants::GetTarget(), External::New(isolate, nullptr));
}
catch (NativeScriptException& e)
{
e.ReThrowToV8();
}
catch (std::exception e) {
stringstream ss;
ss << "Error: c++ exception: " << e.what() << endl;
NativeScriptException nsEx(ss.str());
nsEx.ReThrowToV8();
}
catch (...) {
NativeScriptException nsEx(std::string("Error: c++ exception!"));
nsEx.ReThrowToV8();
}
}
示例10: PassString
void PassString(const FunctionCallbackInfo<Value>& args) {
Isolate * isolate = args.GetIsolate();
if ( args.Length() < 1 ) {
return;
}
else if ( args[0]->IsNull() ) {
return;
}
else if ( args[0]->IsUndefined() ) {
return;
}
else if (!args[0]->IsString()) {
// This clause would catch IsNull and IsUndefined too...
return ;
}
v8::String::Utf8Value s(args[0]);
std::string str(*s, s.length());
std::reverse(str.begin(), str.end());
Local<String> retval = String::NewFromUtf8(isolate, str.c_str());
args.GetReturnValue().Set(retval);
}
示例11: gum_v8_stalker_on_unfollow
/*
* Prototype:
* Stalker.unfollow(thread_id)
*
* Docs:
* TBW
*
* Example:
* TBW
*/
static void
gum_v8_stalker_on_unfollow (const FunctionCallbackInfo<Value> & info)
{
GumV8Stalker * self = static_cast<GumV8Stalker *> (
info.Data ().As<External> ()->Value ());
GumStalker * stalker;
GumThreadId thread_id;
stalker = _gum_v8_stalker_get (self);
if (info.Length () > 0)
thread_id = info[0]->IntegerValue ();
else
thread_id = gum_process_get_current_thread_id ();
if (thread_id == gum_process_get_current_thread_id ())
{
self->pending_follow_level--;
}
else
{
gum_stalker_unfollow (stalker, thread_id);
}
}
示例12: constructByteArray
void constructByteArray(const FunctionCallbackInfo<Value>& args)
{
if (!args.IsConstructCall()) {
Utility::throwException(args.GetIsolate(), Utility::ExceptionMustCallAsConstructor);
return;
}
if (args.Length() == 0) {
Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentCount);
return;
}
QByteArray data;
if (args[0]->IsArrayBuffer()) {
data = Utility::toByteArray(args[0]);
}
else if (args[0]->IsString()) {
int format = 0;
if (args.Length() >= 2 && args[1]->IsInt32())
format = args[1]->Int32Value();
if (format < 0 || format > 3) {
Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentValue);
return;
}
data = byteArrayFromString(Utility::toString(args[0]).toLatin1(), format);
}
else {
Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentType);
return;
}
HandleScope handle_scope(args.GetIsolate());
// Return the constructed object
args.GetReturnValue().Set(ModuleByteArray::wrapByteArray(args.GetIsolate(), data));
}
示例13: GetProcessByName
void GetProcessByName(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
/*if (args.Length() < 1)
{
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
if (!args[0]->IsString())
{
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong arguments")));
return;
}*/
String::Utf8Value procName(args[0]->ToString());
HANDLE hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
BOOL rval;
for (rval = Process32First(hdl, &pe32);
rval == TRUE && strcmpi(pe32.szExeFile, *procName) != 0;
rval = Process32Next(hdl, &pe32));
if (hdl != INVALID_HANDLE_VALUE)
{
CloseHandle(hdl);
}
Local<Number> num;
if (rval == TRUE)
{
num = Number::New(isolate, pe32.th32ProcessID);
}
else
{
num = Number::New(isolate, 0);
}
args.GetReturnValue().Set(num);
}
示例14: PointConstructor
// Defines a Point() JS Object
void PointConstructor( const FunctionCallbackInfo<v8::Value>& args )
{
//Locker lock;
HandleScope scope;
Handle<ObjectTemplate> t = v8::ObjectTemplate::New();
//The JavaScript point object only has 1 C++ object
t->SetInternalFieldCount(1);
// Create x and y members with starting values of 0
//t->Set(String::New("x"), Number::New(0));
t->SetAccessor(String::New("x"),
(AccessorGetterCallback)GetPointX,
(AccessorSetterCallback)SetPointX);
//t->Set(String::New("y"), Number::New(0));
t->SetAccessor(String::New("y"),
(AccessorGetterCallback)GetPointY,
(AccessorSetterCallback)SetPointY);
// Create a mul(number) function that scales the point
t->Set(String::New("mul"), FunctionTemplate::New(MulCallback));
// for use in the if statement
Point *p = NULL;
Local<Object> obj;
// If Point(x, y) ctor was passed in values assign them
if(!args[0].IsEmpty() && args[0]->IsNumber() &&
!args[1].IsEmpty() && args[1]->IsNumber()) {
//t->Set(String::New("x"), args[0]);
//t->Set(String::New("y"), args[1]);
p = new Point(args[0]->Int32Value(), args[1]->Int32Value());
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
} else {
/**
* Wrap a point object
*/
p = new Point(0, 0);
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
}
// Return this newly created object
args.GetReturnValue().Set(obj);
}
示例15: get_master_player_by_cid
void get_master_player_by_cid(const FunctionCallbackInfo<Value>& args) {
if (args.Length() != 2) {
LOG_ERROR("get_master_player_by_cid args error, length: %d\n", args.Length());
args.GetReturnValue().SetNull();
return;
}
int gate_cid = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0);
int player_cid = args[1]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0);
Master_Player *player = MASTER_MANAGER->find_gate_cid_master_player(gate_cid * 10000 + player_cid);
if (player) {
args.GetReturnValue().Set(wrap_master_player(args.GetIsolate(), player));
} else {
//设置对象为空
args.GetReturnValue().SetNull();
MASTER_MANAGER->close_client(gate_cid, player_cid, ERROR_CLIENT_PARAM);
}
}