void jsCreateMyClass(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { args.GetIsolate()->ThrowException( String::NewFromUtf8(args.GetIsolate(), "Bad parameters", NewStringType::kNormal).ToLocalChecked()); return; } Isolate* isolate = args.GetIsolate(); Local<ObjectTemplate> myClassTemplate = Local<ObjectTemplate>::New(isolate, gMyClassTemplate); Local<Object> myClassObj = myClassTemplate->NewInstance( isolate->GetCurrentContext()).ToLocalChecked(); int numValue = args[0]->Int32Value(isolate->GetCurrentContext()).FromMaybe(0); gMyClass = new ObjectWrap(numValue); gMyClass->Wrap(myClassObj); args.GetReturnValue().Set(myClassObj); }
// DISCONNECT SYNC void disconnectSync(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); SQLRETURN retcode; // define callback Local<Function> cb = Local<Function>::Cast(args[0]); // Free handles // Statement if (hstmt != SQL_NULL_HSTMT) SQLFreeHandle(SQL_HANDLE_STMT, hstmt); // Connection retcode = SQLDisconnect(hdbc); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLDISCONNECT\n"); extract_error(hdbc, SQL_HANDLE_DBC); } SQLFreeHandle(SQL_HANDLE_DBC, hdbc); /* // Environment if (henv != SQL_NULL_HENV) SQLFreeHandle(SQL_HANDLE_ENV, henv); */ Local<Value> argv[1] = { Number::New(isolate, retcode)}; cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); }
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)); }
void EModuleHelper::SetLogHandler( const FunctionCallbackInfo< Value >& args ) { Isolate* isolate = args.GetIsolate( ); HandleScope scope( isolate ); Local< Context > context = isolate->GetCurrentContext( ); if( args[ 0 ]->IsNull( ) ) { s_bLogEnabled = false; } else if( args[ 0 ]->IsFunction( ) ) { s_bLogEnabled = true; s_fnLogHandler.Reset( isolate, args[ 0 ].As< Function >( ) ); } else { std::wostringstream stream; { stream << __FUNCTIONW__ << L" Invalid input type"; } ThrowV8Exception( isolate, stream ); } }
void Method(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); const char * cstr; String::Utf8Value str(args[0]->ToString()); cstr = *str; CTime curTime; CRTime deliLimit; vector<CDriver> drivers; vector<CTask> tasks; vector<CPath> paths; vector<CScheduleItem> schedule; schedule.clear(); if (parseInput(cstr, curTime, deliLimit, drivers, tasks, paths)) { int ret = ALG::findScheduleGreedy(curTime, deliLimit, drivers, tasks, paths, schedule); if (ret != E_NORMAL) { printf("search algorithm returned %d.\n", ret); } } Local<String> schd_string = String::NewFromUtf8(isolate, prepareOutput(schedule).c_str()); //args.GetReturnValue().Set(schd_string); Local<Function> cb = Local<Function>::Cast(args[1]); const unsigned int argc = 1; Local<Value> argv[argc] = {schd_string}; cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); }
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()); }
void* JsVlcPlayer::onFrameSetup( const I420VideoFrame& videoFrame ) { using namespace v8; if( 0 == videoFrame.width() || 0 == videoFrame.height() || 0 == videoFrame.uPlaneOffset() || 0 == videoFrame.vPlaneOffset() || 0 == videoFrame.size() ) { assert( false ); return nullptr; } Isolate* isolate = Isolate::GetCurrent(); HandleScope scope( isolate ); Local<Object> global = isolate->GetCurrentContext()->Global(); Local<Value> abv = global->Get( String::NewFromUtf8( isolate, "Uint8Array", v8::String::kInternalizedString ) ); Local<Value> argv[] = { Integer::NewFromUnsigned( isolate, videoFrame.size() ) }; Local<Uint8Array> jsArray = Handle<Uint8Array>::Cast( Handle<Function>::Cast( abv )->NewInstance( 1, argv ) ); Local<Integer> jsWidth = Integer::New( isolate, videoFrame.width() ); Local<Integer> jsHeight = Integer::New( isolate, videoFrame.height() ); Local<Integer> jsPixelFormat = Integer::New( isolate, static_cast<int>( PixelFormat::I420 ) ); jsArray->ForceSet( String::NewFromUtf8( isolate, "width", v8::String::kInternalizedString ), jsWidth, static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) ); jsArray->ForceSet( String::NewFromUtf8( isolate, "height", v8::String::kInternalizedString ), jsHeight, static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) ); jsArray->ForceSet( String::NewFromUtf8( isolate, "pixelFormat", v8::String::kInternalizedString ), jsPixelFormat, static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) ); jsArray->ForceSet( String::NewFromUtf8( isolate, "uOffset", v8::String::kInternalizedString ), Integer::New( isolate, videoFrame.uPlaneOffset() ), static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) ); jsArray->ForceSet( String::NewFromUtf8( isolate, "vOffset", v8::String::kInternalizedString ), Integer::New( isolate, videoFrame.vPlaneOffset() ), static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) ); _jsFrameBuffer.Reset( isolate, jsArray ); callCallback( CB_FrameSetup, { jsWidth, jsHeight, jsPixelFormat, jsArray } ); #ifdef USE_ARRAY_BUFFER return jsArray->Buffer()->GetContents().Data(); #else return jsArray->GetIndexedPropertiesExternalArrayData(); #endif }
void onConnection(const FunctionCallbackInfo<Value> &args) { uWS::Server *server = (uWS::Server *) args.Holder()->GetAlignedPointerFromInternalField(0); Isolate *isolate = args.GetIsolate(); Persistent<Function> *connectionCallback = (Persistent<Function> *) args.Holder()->GetAlignedPointerFromInternalField(CONNECTION_CALLBACK); connectionCallback->Reset(isolate, Local<Function>::Cast(args[0])); server->onConnection([isolate, connectionCallback](uWS::Socket socket) { HandleScope hs(isolate); Local<Value> argv[] = {wrapSocket(socket, isolate)}; node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), Local<Function>::New(isolate, *connectionCallback), 1, argv); }); }
Local<Object> CreateDelegate(UObject* Object, UProperty* Property) { //@HACK CollectGarbageDelegates(); auto payload = new FJavascriptDelegate(Object, Property); auto created = payload->Initialize(isolate_->GetCurrentContext()); Delegates.Add(payload); return created; }
void parse2json(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments.", NewStringType::kNormal).ToLocalChecked())); } // Use maybe version std::string csv(*String::Utf8Value(isolate, args[0]->ToString(isolate->GetCurrentContext()).ToLocalChecked())); // std::string csv(*String::Utf8Value(isolate, args[0]->ToString())); std::string json = csv2json_str(csv); args.GetReturnValue().Set(String::NewFromUtf8(isolate, json.c_str(), NewStringType::kNormal).ToLocalChecked()); }
void _gum_v8_module_realize (GumV8Module * self) { static gsize gonce_value = 0; if (g_once_init_enter (&gonce_value)) { Isolate * isolate = self->core->isolate; Local<Context> context = isolate->GetCurrentContext (); Local<String> type (String::NewFromUtf8 (isolate, "type")); Local<String> name (String::NewFromUtf8 (isolate, "name")); Local<String> module (String::NewFromUtf8 (isolate, "module")); Local<String> address (String::NewFromUtf8 (isolate, "address")); Local<String> function (String::NewFromUtf8 (isolate, "function")); Local<String> variable (String::NewFromUtf8 (isolate, "variable")); Local<String> empty_string = String::NewFromUtf8 (isolate, ""); Local<Object> imp (Object::New (isolate)); Maybe<bool> result = imp->ForceSet (context, type, function); g_assert (result.IsJust ()); result = imp->ForceSet (context, name, empty_string, DontDelete); g_assert (result.IsJust ()); result = imp->ForceSet (context, module, empty_string); g_assert (result.IsJust ()); result = imp->ForceSet (context, address, _gum_v8_native_pointer_new ( GSIZE_TO_POINTER (NULL), self->core)); g_assert (result.IsJust ()); Local<Object> exp (Object::New (isolate)); result = exp->ForceSet (context, type, function, DontDelete); g_assert (result.IsJust ()); result = exp->ForceSet (context, name, empty_string, DontDelete); g_assert (result.IsJust ()); result = exp->ForceSet (context, address, _gum_v8_native_pointer_new ( GSIZE_TO_POINTER (NULL), self->core), DontDelete); g_assert (result.IsJust ()); eternal_imp.Set (isolate, imp); eternal_exp.Set (isolate, exp); eternal_type.Set (isolate, type); eternal_name.Set (isolate, name); eternal_module.Set (isolate, module); eternal_address.Set (isolate, address); eternal_variable.Set (isolate, variable); g_once_init_leave (&gonce_value, 1); } }
void queryAfter(uv_work_t* req, int status) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); query_data* data = (query_data *)(req->data); Local<Value> argv[1] = { Number::New(isolate, data->result)}; Local<Function> cb = Local<Function>::New(isolate, data->cb); cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); free(data); free(req); }
void onMessage(const FunctionCallbackInfo<Value> &args) { uWS::Server *server = (uWS::Server *) args.Holder()->GetAlignedPointerFromInternalField(0); Isolate *isolate = args.GetIsolate(); Persistent<Function> *messageCallback = (Persistent<Function> *) args.Holder()->GetAlignedPointerFromInternalField(MESSAGE_CALLBACK); messageCallback->Reset(isolate, Local<Function>::Cast(args[0])); server->onMessage([isolate, messageCallback](uWS::Socket socket, const char *message, size_t length, uWS::OpCode opCode) { HandleScope hs(isolate); Local<Value> argv[] = {wrapSocket(socket, isolate), node::Buffer::New(isolate, (char *) message, length, [](char *data, void *hint) {}, nullptr).ToLocalChecked(), Boolean::New(isolate, opCode == BINARY), getDataV8(socket, isolate)}; node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), Local<Function>::New(isolate, *messageCallback), 4, argv); }); }
void selectAfter(uv_work_t* req, int status) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); select_data* data = (select_data *)(req->data); Local<Value> argv[2] = { Number::New(isolate, data->result), String::NewFromUtf8(isolate, data->records) }; Local<Function> cb = Local<Function>::New(isolate, data->cb); cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); free(data->records); free(data); free(req); }
void onDisconnection(const FunctionCallbackInfo<Value> &args) { uWS::Server *server = (uWS::Server *) args.Holder()->GetAlignedPointerFromInternalField(0); Isolate *isolate = args.GetIsolate(); Persistent<Function> *disconnectionCallback = (Persistent<Function> *) args.Holder()->GetAlignedPointerFromInternalField(DISCONNECTION_CALLBACK); disconnectionCallback->Reset(isolate, Local<Function>::Cast(args[0])); server->onDisconnection([isolate, disconnectionCallback](uWS::Socket socket, int code, char *message, size_t length) { HandleScope hs(isolate); Local<Value> argv[] = {wrapSocket(socket, isolate), Integer::New(isolate, code), node::Buffer::New(isolate, (char *) message, length, [](char *data, void *hint) {}, nullptr).ToLocalChecked(), getDataV8(socket, isolate)}; node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), Local<Function>::New(isolate, *disconnectionCallback), 4, argv); }); }
static gboolean gum_v8_module_handle_export_match (const GumExportDetails * details, gpointer user_data) { GumV8ExportsContext * ctx = static_cast<GumV8ExportsContext *> (user_data); Isolate * isolate = ctx->isolate; Local<Context> jc = isolate->GetCurrentContext (); PropertyAttribute attrs = static_cast<PropertyAttribute> (ReadOnly | DontDelete); Local<Object> exp (ctx->exp->Clone ()); if (details->type != GUM_EXPORT_FUNCTION) { Maybe<bool> success = exp->ForceSet (jc, ctx->type, ctx->variable, attrs); g_assert (success.IsJust ()); } Maybe<bool> success = exp->ForceSet (jc, ctx->name, String::NewFromOneByte (isolate, reinterpret_cast<const uint8_t *> (details->name)), attrs); g_assert (success.IsJust ()); success = exp->ForceSet (jc, ctx->address, _gum_v8_native_pointer_new (GSIZE_TO_POINTER (details->address), ctx->self->core), attrs); g_assert (success.IsJust ()); Handle<Value> argv[] = { exp }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
static void SnifferAsyncComplete(uv_work_t *req,int status) { Isolate * isolate = Isolate::GetCurrent(); v8::HandleScope handleScope(isolate); //Local<Array> result_list = Array::New(isolate); Work *work = static_cast<Work *>(req->data); uv_cond_destroy(&work->cond); uv_mutex_destroy(&work->mutex); Local<Value> argv[] = { Integer::New(isolate, work->value), Integer::New(isolate, work->delay) }; Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 2, argv); delete work; }
void EModuleHelper::RequestNextChunk( const FunctionCallbackInfo< Value >& args ) { Isolate* isolate = args.GetIsolate( ); HandleScope scope( isolate ); Local< Context > context = isolate->GetCurrentContext( ); CAsyncReader* pRead = new CAsyncReader; { pRead->SetParams( isolate, reinterpret_cast< CQuery* >( args[ 0 ]->IntegerValue( context ).FromJust( ) ), static_cast< SQLUSMALLINT >( args[ 1 ]->Uint32Value( context ).FromJust( ) ), args[ 2 ].As<Function>( ) ); } pRead->RunOperation( ); }
void EModuleHelper::ProcessNextChunk( const FunctionCallbackInfo< Value >& args ) { Isolate* isolate = args.GetIsolate( ); HandleScope scope( isolate ); Local< Context > context = isolate->GetCurrentContext( ); CAsyncWriter* pWrite = new CAsyncWriter; { pWrite->SetParams( isolate, reinterpret_cast< CQuery* >( args[ 0 ]->IntegerValue( context ).FromJust( ) ), args[ 1 ].As< Uint8Array >( ), args[ 2 ].As< Function >( ) ); } pWrite->RunOperation( ); }
// CONNECT SYNC void connectSync(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); SQLCHAR dsn[10], uname[20], pass[20]; unsigned int i; SQLRETURN retcode; // extract argument 1 (DSN-name) v8::String::Utf8Value param1(args[0]->ToString()); std::string dsnRaw = std::string(*param1); for(i=0;i<dsnRaw.length();i++) dsn[i] = dsnRaw[i]; dsn[i] = '\0'; // extract argument 2 (username) v8::String::Utf8Value param2(args[1]->ToString()); std::string unameRaw = std::string(*param2); for(i=0;i<unameRaw.length();i++) uname[i] = unameRaw[i]; uname[i] = '\0'; // extract argument 3 (password) v8::String::Utf8Value param3(args[2]->ToString()); std::string passRaw = std::string(*param3); for(i=0;i<passRaw.length();i++) pass[i] = passRaw[i]; pass[i] = '\0'; // define callback Local<Function> cb = Local<Function>::Cast(args[3]); // Allocate a connection handle retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT ALLOCATING CONNECTION HANDLE\n"); extract_error(hdbc, SQL_HANDLE_DBC); } // Connect to the data source retcode = SQLConnect(hdbc, dsn, SQL_NTS, uname, SQL_NTS, pass, SQL_NTS); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLCONNECT\n"); extract_error(hdbc, SQL_HANDLE_DBC); } Local<Value> argv[1] = { Number::New(isolate, retcode)}; cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); }
void jsMyFunction2(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { args.GetIsolate()->ThrowException( String::NewFromUtf8(args.GetIsolate(), "Bad parameters", NewStringType::kNormal).ToLocalChecked()); return; } Isolate* isolate = args.GetIsolate(); int numValue = args[0]->Int32Value(isolate->GetCurrentContext()).FromMaybe(0); const char* result = myFunction2(numValue); Local<String> str = String::NewFromUtf8(isolate, result); args.GetReturnValue().Set(str); }
void Factorial(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.Length() != 2) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments"))); } else { if (!(args[0]->IsNumber() && args[1]->IsFunction())) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments type"))); } else { int result = factorial(args[0]->Int32Value()); Local<Function> callbackFunction = Local<Function>::Cast(args[1]); const unsigned argc = 1; Local<Value> argv[argc] = { Number::New(isolate, result) }; callbackFunction->Call(isolate->GetCurrentContext()->Global(), argc, argv); } } }
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); }
// INSERT, UPDATE, DELETE SYNC void querySync(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); char query[1000]; unsigned int i; // extract argument 1 (Query) v8::String::Utf8Value param1(args[0]->ToString()); std::string queryRaw = std::string(*param1); for(i=0;i<queryRaw.length();i++) query[i] = queryRaw[i]; query[i] = '\0'; // define callback Local<Function> cb = Local<Function>::Cast(args[1]); SQLRETURN retcode; // Allocate a statement handle retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT ALLOCATING STATEMENT HANDLE\n"); extract_error(hstmt, SQL_HANDLE_STMT); } // query statement retcode = SQLExecDirect(hstmt, (SQLCHAR *)query, SQL_NTS); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLEXECDIRECT\n"); extract_error(hstmt, SQL_HANDLE_STMT); } SQLFreeHandle(SQL_HANDLE_STMT, hstmt); Local<Value> argv[1] = { Number::New(isolate, retcode)}; cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); }
// SELECT SYNC void selectSync(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); char query[1000]; unsigned int i,limit; int j,temp; SQLRETURN retcode; SQLSMALLINT colCount = 0; SQLLEN indicator; SQLINTEGER *intData[30]; SQLCHAR *charData[30]; SQLDOUBLE *doubleData[30]; // extract argument 1 (Query) v8::String::Utf8Value param1(args[0]->ToString()); std::string queryRaw = std::string(*param1); for(i=0;i<queryRaw.length();i++) query[i] = queryRaw[i]; query[i] = '\0'; //extracting SQL limit temp = (int)args[1]->NumberValue(); if(temp < 0){ limit = 4294967294; } else{ limit = temp; } // define callback Local<Function> cb = Local<Function>::Cast(args[2]); // Allocate a statement handle retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT ALLOCATING STATEMENT HANDLE\n"); extract_error(hstmt, SQL_HANDLE_STMT); } // select statement retcode = SQLPrepare(hstmt, (SQLCHAR *)query, SQL_NTS); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLPREPARE\n"); extract_error(hstmt, SQL_HANDLE_STMT); } Column* columns = GetColumns(&colCount); for(j=0;j<colCount;j++) { if(columns[j].type == SQL_C_LONG) { intData[j] = (SQLINTEGER *) malloc (columns[j].size+1); retcode = SQLBindCol(hstmt, columns[j].index, columns[j].type, intData[j], columns[j].size, &indicator); } else if(columns[j].type == SQL_C_DOUBLE) { doubleData[j] = (SQLDOUBLE *) malloc (columns[j].size+1); retcode = SQLBindCol(hstmt, columns[j].index, columns[j].type, doubleData[j], columns[j].size, &indicator); } else if(columns[j].type == SQL_C_CHAR) { charData[j] = (SQLCHAR *) malloc (columns[j].size+1); retcode = SQLBindCol(hstmt, columns[j].index, columns[j].type, charData[j], columns[j].size, &indicator); } if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT BINDING COLUMNS\n"); extract_error(hstmt, SQL_HANDLE_STMT); break; } } // Execute the statement handle retcode = SQLExecute (hstmt); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLEXECUTE\n"); extract_error(hstmt, SQL_HANDLE_STMT); } // Array of Records Local<Array> result = Array::New(isolate); Local<Object> obj; // Fetch and print each row of data until SQL_NO_DATA returned. for(i=0;i<limit; i++) { retcode = SQLFetch(hstmt); if (retcode == SQL_NO_DATA) { break; } if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLFETCH\n"); extract_error(hstmt, SQL_HANDLE_STMT); break; } // Retrieve individual Records and store in the object obj = Object::New(isolate); for(j=0;j<colCount;j++) { if (columns[j].type == SQL_C_LONG) { obj->Set(String::NewFromUtf8(isolate, (char *) columns[j].name), Number::New(isolate, (long) *intData[j])); } else if(columns[j].type == SQL_C_DOUBLE) { obj->Set(String::NewFromUtf8(isolate, (char *) columns[j].name), Number::New(isolate, (double) *doubleData[j])); } else if(columns[j].type == SQL_C_CHAR) { obj->Set(String::NewFromUtf8(isolate, (char *) columns[j].name), String::NewFromUtf8(isolate, (char *) charData[j])); } } result->Set(i,obj); } Local<Value> argv[2] = { Number::New(isolate, retcode), result }; cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); }
static gboolean gum_v8_module_handle_import_match (const GumImportDetails * details, gpointer user_data) { GumV8ImportsContext * ctx = static_cast<GumV8ImportsContext *> (user_data); Isolate * isolate = ctx->isolate; Local<Context> jc = isolate->GetCurrentContext (); PropertyAttribute attrs = static_cast<PropertyAttribute> (ReadOnly | DontDelete); Local<Object> imp (ctx->imp->Clone ()); switch (details->type) { case GUM_IMPORT_FUNCTION: { /* the default value in our template */ break; } case GUM_IMPORT_VARIABLE: { Maybe<bool> success = imp->ForceSet (jc, ctx->type, ctx->variable, attrs); g_assert (success.IsJust ()); break; } case GUM_IMPORT_UNKNOWN: { Maybe<bool> success = imp->Delete (jc, ctx->type); g_assert (success.IsJust ()); break; } default: { g_assert_not_reached (); break; } } Maybe<bool> success = imp->ForceSet (jc, ctx->name, String::NewFromOneByte (isolate, reinterpret_cast<const uint8_t *> (details->name)), attrs); g_assert (success.IsJust ()); if (details->module != NULL) { success = imp->ForceSet (jc, ctx->module, String::NewFromOneByte (isolate, reinterpret_cast<const uint8_t *> (details->module)), attrs); g_assert (success.IsJust ()); } else { success = imp->Delete (jc, ctx->module); g_assert (success.IsJust ()); } if (details->address != 0) { success = imp->ForceSet (jc, ctx->address, _gum_v8_native_pointer_new (GSIZE_TO_POINTER (details->address), ctx->self->core), attrs); g_assert (success.IsJust ()); } else { success = imp->Delete (jc, ctx->address); g_assert (success.IsJust ()); } Handle<Value> argv[] = { imp }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
void Proxy::proxyConstructor(const v8::FunctionCallbackInfo<v8::Value>& args) { LOGD(TAG, "proxy constructor callback!"); Isolate* isolate = args.GetIsolate(); EscapableHandleScope scope(isolate); JNIEnv *env = JNIScope::getEnv(); Local<Object> jsProxy = args.This(); // First things first, we need to wrap the object in case future calls need to unwrap proxy! Proxy* proxy = new Proxy(NULL); proxy->wrap(isolate, jsProxy); // every instance gets a special "_properties" object for us to use internally for get/setProperty jsProxy->DefineOwnProperty(isolate->GetCurrentContext(), propertiesSymbol.Get(isolate), Object::New(isolate), static_cast<PropertyAttribute>(DontEnum)); // Now we hook up a java Object from the JVM... jobject javaProxy = ProxyFactory::unwrapJavaProxy(args); // do we already have one that got passed in? bool deleteRef = false; if (!javaProxy) { // No passed in java object, so let's create an instance // Look up java class from prototype... Local<Object> prototype = jsProxy->GetPrototype()->ToObject(isolate); Local<Function> constructor = prototype->Get(constructorSymbol.Get(isolate)).As<Function>(); Local<External> wrap = constructor->Get(javaClassSymbol.Get(isolate)).As<External>(); jclass javaClass = static_cast<jclass>(wrap->Value()); // Now we create an instance of the class and hook it up JNIUtil::logClassName("Creating java proxy for class %s", javaClass); javaProxy = ProxyFactory::createJavaProxy(javaClass, jsProxy, args); deleteRef = true; } proxy->attach(javaProxy); int length = args.Length(); if (length > 0 && args[0]->IsObject()) { bool extend = true; Local<Object> createProperties = args[0].As<Object>(); Local<String> constructorName = createProperties->GetConstructorName(); if (strcmp(*titanium::Utf8Value(constructorName), "Arguments") == 0) { extend = false; int32_t argsLength = createProperties->Get(STRING_NEW(isolate, "length"))->Int32Value(); if (argsLength > 1) { Local<Value> properties = createProperties->Get(1); if (properties->IsObject()) { extend = true; createProperties = properties.As<Object>(); } } } if (extend) { Local<Array> names = createProperties->GetOwnPropertyNames(); int length = names->Length(); Local<Object> properties = jsProxy->Get(propertiesSymbol.Get(isolate))->ToObject(isolate); for (int i = 0; i < length; ++i) { Local<Value> name = names->Get(i); Local<Value> value = createProperties->Get(name); bool isProperty = true; if (name->IsString()) { Local<String> nameString = name.As<String>(); if (!jsProxy->HasRealNamedCallbackProperty(nameString) && !jsProxy->HasRealNamedProperty(nameString)) { jsProxy->Set(name, value); isProperty = false; } } if (isProperty) { properties->Set(name, value); } } } } if (!args.Data().IsEmpty() && args.Data()->IsFunction()) { Local<Function> proxyFn = args.Data().As<Function>(); Local<Value> *fnArgs = new Local<Value>[length]; for (int i = 0; i < length; ++i) { fnArgs[i] = args[i]; } proxyFn->Call(isolate->GetCurrentContext(), jsProxy, length, fnArgs); } if (deleteRef) { JNIEnv *env = JNIScope::getEnv(); if (env) { env->DeleteLocalRef(javaProxy); } } args.GetReturnValue().Set(scope.Escape(jsProxy)); }