void CRF::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (args.IsConstructCall()) { // Invoked as constructor: `new CRF(...)` CRF* obj = new CRF(); CRFPP::Tagger* tag = CRFPP::createTagger(get(args[0])); if(!tag){ isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, (const char *) CRFPP::getTaggerError()))); return; } v8::Local<v8::External> handle = v8::External::New(isolate, tag); v8::Persistent<v8::External, v8::CopyablePersistentTraits<v8::External> > tagger(isolate, handle); obj -> tagger = tagger; obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { 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)); } }
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); }
void MySQL::JS_New(const FunctionCallbackInfo<Value> & args){ auto mysql = Instance(args.Holder()); auto conn_tmpl = ObjectTemplate::New(args.GetIsolate()); conn_tmpl->SetInternalFieldCount(1); MYSQL *mysql2 = mysql_init(NULL); auto conn = mysql->createConnection(); JS_Object jsconn(conn_tmpl->NewInstance()); jsconn.Set("connect", JS_Connect); jsconn.Set("query", JS_Query); jsconn.Set("escape", JS_RealEscape); jsconn.Set("close", JS_Close); jsconn.Set("connected", JS_Connected); jsconn.Set("ping", JS_Connected); jsconn.get()->SetInternalField(0, External::New(args.GetIsolate(), conn)); JS_Object parentConn(Local<Object>::Cast(args[0])); parentConn.Set("internal", jsconn.get()); }
void printable(const FunctionCallbackInfo<Value>& args) { QByteArray data = ModuleByteArray::unwrapByteArray(args.GetIsolate(), args.Holder()); QString placeholder = "."; if (args.Length() >= 1) { if (!args[0]->IsString()) { Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentType); return; } placeholder = Utility::toString(args[0]); } QString result; result.reserve(data.length()); for (int i = 0; i < data.length(); i++) { char c = data.at(i); if (QChar::isPrint(c)) result.append(c); else result.append(placeholder); } args.GetReturnValue().Set(Utility::toV8String(args.GetIsolate(), result)); }
void getAddress(const FunctionCallbackInfo<Value> &args) { uWS::Socket::Address address = unwrapSocket(args[0]->ToNumber()).getAddress(); Local<Array> array = Array::New(args.GetIsolate(), 3); array->Set(0, Integer::New(args.GetIsolate(), address.port)); array->Set(1, String::NewFromUtf8(args.GetIsolate(), address.address)); array->Set(2, String::NewFromUtf8(args.GetIsolate(), address.family)); args.GetReturnValue().Set(array); }
void Server::JS_ReloadScript(const FunctionCallbackInfo<Value> & args){ if (args.Length() < 1) return; if (!args[0]->IsString()) return; JS_SCOPE(args.GetIsolate()); string file = JS2STRING(args[0]); auto server = Server::GetInstance(args.GetIsolate()->GetCallingContext()); Reload(file, server->GetAMX()); }
//! \verbatim //! Quaternion() //! Quaternion( Radian rotation, Vector3 axis ) //! Quaternion( Real w, Real x, Real y, Real z ) //! Quaternion([Real w, Real x, Real y, Real z]) //! Quaternion({Real w, Real x, Real y, Real z}) //! \endverbatim void Quaternion::create( const FunctionCallbackInfo<v8::Value>& args ) { HandleScope handleScope( args.GetIsolate() ); if ( !args.IsConstructCall() ) { args.GetIsolate()->ThrowException( Util::allocString( "Function called as non-constructor" ) ); return; } Ogre::Quaternion qtn( Ogre::Quaternion::IDENTITY ); if ( args.Length() == 4 ) { qtn.w = args[0]->NumberValue(); qtn.x = args[1]->NumberValue(); qtn.y = args[2]->NumberValue(); qtn.z = args[3]->NumberValue(); } else if ( args.Length() == 2 ) { Vector3* axis = Util::extractVector3( 1, args ); qtn.FromAngleAxis( Ogre::Radian( args[0]->NumberValue() ), *axis ); } else if ( args.Length() == 1 ) { if ( args[0]->IsArray() ) { v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast( args[0] ); if ( arr->Length() == 4 ) { qtn.w = arr->Get( 0 )->NumberValue(); qtn.x = arr->Get( 1 )->NumberValue(); qtn.y = arr->Get( 2 )->NumberValue(); qtn.z = arr->Get( 3 )->NumberValue(); } } else if ( args[0]->IsObject() ) { v8::Local<v8::Value> val = args[0]->ToObject()->Get( Util::allocString( "w" ) ); if ( val->IsNumber() ) qtn.w = val->NumberValue(); val = args[0]->ToObject()->Get( Util::allocString( "x" ) ); if ( val->IsNumber() ) qtn.x = val->NumberValue(); val = args[0]->ToObject()->Get( Util::allocString( "y" ) ); if ( val->IsNumber() ) qtn.y = val->NumberValue(); val = args[0]->ToObject()->Get( Util::allocString( "z" ) ); if ( val->IsNumber() ) qtn.z = val->NumberValue(); } } Quaternion* object = new Quaternion( qtn ); object->wrap( args.This() ); args.GetReturnValue().Set( args.This() ); }
void register_master_timer(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 3) { LOG_ERROR("register_master_timer args error, length: %d\n", args.Length()); return; } int timer_id = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); int interval = args[1]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); int first_tick_internal = args[2]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); LOG_ERROR("register_master_timer,timer_id:%d, interval:%dms, first_tick_internal:%ds\n", timer_id, interval, first_tick_internal); MASTER_TIMER->register_v8_handler(timer_id, interval, first_tick_internal); }
void push_master_client_buffer(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 2) { LOG_ERROR("push_master_client_buffer args error, length: %d\n", args.Length()); return; } int cid = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); Block_Buffer *buf= unwrap_buffer(args[1]->ToObject(args.GetIsolate()->GetCurrentContext()).ToLocalChecked()); if (buf) { MASTER_GATE_SERVER->push_block(cid, buf); } }
void Server::JS_GetMemory(const FunctionCallbackInfo<Value> & args){ size_t peak = sampjs::getPeakRSS(); size_t current = sampjs::getCurrentRSS(); Local<Object> mem = Object::New(args.GetIsolate()); mem->Set(String::NewFromUtf8(args.GetIsolate(), "current"), Integer::New(args.GetIsolate(),current)); mem->Set(String::NewFromUtf8(args.GetIsolate(), "peak"), Integer::New(args.GetIsolate(), peak)); args.GetReturnValue().Set(mem); }
void Texture2D::New(const FunctionCallbackInfo<Value>& args) { HandleScope scope(args.GetIsolate()); ScriptHelper helper(args.GetIsolate()); auto filepath = ScriptEngine::current().resolvePath( helper.GetString(args[0])); try { auto texture = new Texture2D(args.GetIsolate(), filepath); args.GetReturnValue().Set(texture->v8Object()); } catch (std::exception& ex) { ScriptEngine::current().ThrowTypeError(ex.what()); } }
void game_player_respond_success_result(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 2) { LOG_ERROR("respond_success_result args error, length: %d\n", args.Length()); return; } Game_Player *player = unwrap_game_player(args.Holder()); if (!player) { return; } int msg_id = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); Block_Buffer *buf = unwrap_buffer(args[1]->ToObject(args.GetIsolate()->GetCurrentContext()).ToLocalChecked()); player->respond_success_result(msg_id, buf); }
void sync_data_to_game(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 2) { LOG_ERROR("sync_data_to_game args error, length: %d\n", args.Length()); return; } Master_Player *player = unwrap_master_player(args.Holder()); if (!player) { return; } int msg_id = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); Block_Buffer *buf = unwrap_buffer(args[1]->ToObject(args.GetIsolate()->GetCurrentContext()).ToLocalChecked()); player->sync_data_to_game(msg_id, buf); }
void jsMyFunction1(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { args.GetIsolate()->ThrowException( String::NewFromUtf8(args.GetIsolate(), "Bad parameters", NewStringType::kNormal).ToLocalChecked()); return; } String::Utf8Value str(args[0]); const char* cstr = ToCString(str); myFunction1(cstr); }
void setData(const FunctionCallbackInfo<Value> &args) { uWS::Socket socket = unwrapSocket(args[0]->ToNumber()); if (socket.getData()) { /* reset data when only specifying the socket */ if (args.Length() == 1) { ((Persistent<Value> *) socket.getData())->Reset(); delete (Persistent<Value> *) socket.getData(); } else { ((Persistent<Value> *) socket.getData())->Reset(args.GetIsolate(), args[1]); } } else { socket.setData(new Persistent<Value>(args.GetIsolate(), args[1])); } }
void game_player_respond_error_result(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 2) { LOG_ERROR("respond_error_result args error, length: %d\n", args.Length()); return; } Game_Player *player = unwrap_game_player(args.Holder()); if (!player) { return; } int msg_id = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); int error_code = args[1]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0); player->respond_error_result(msg_id, error_code); }
void APIModule::log(const FunctionCallbackInfo<Value>& args) { HandleScope scope(args.GetIsolate()); if (args.Length() == 1) { titanium::Utf8Value message(args[0]); APIModule::logInternal(LOG_LEVEL_INFO, LCAT, *message); } else { titanium::Utf8Value level(args[0]); titanium::Utf8Value message(APIModule::combineLogMessages(args, 1)); if (strcasecmp(*level, "TRACE") == 0) { APIModule::logInternal(LOG_LEVEL_TRACE, LCAT, *message); } else if (strcasecmp(*level, "DEBUG") == 0) { APIModule::logInternal(LOG_LEVEL_DEBUG, LCAT, *message); } else if (strcasecmp(*level, "INFO") == 0) { APIModule::logInternal(LOG_LEVEL_INFO, LCAT, *message); } else if (strcasecmp(*level, "NOTICE") == 0) { APIModule::logInternal(LOG_LEVEL_NOTICE, LCAT, *message); } else if (strcasecmp(*level, "WARN") == 0) { APIModule::logInternal(LOG_LEVEL_WARN, LCAT, *message); } else if (strcasecmp(*level, "ERROR") == 0) { APIModule::logInternal(LOG_LEVEL_ERROR, LCAT, *message); } else if (strcasecmp(*level, "CRITICAL") == 0) { APIModule::logInternal(LOG_LEVEL_CRITICAL, LCAT, *message); } else if (strcasecmp(*level, "FATAL") == 0) { APIModule::logInternal(LOG_LEVEL_FATAL, LCAT, *message); } else { int size = strlen(*level) + strlen(*message) + 4; char *fmessage = new char[size]; snprintf(fmessage, size, "[%s] %s", *level, *message); APIModule::logInternal(LOG_LEVEL_INFO, LCAT, fmessage); delete [] fmessage; } } }
/** * TJSオブジェクトのオーバライド処理 * @param args 引数 * @return 結果 */ void TJSInstance::tjsOverride(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { if (args.Length() > 0) { Local<Value> func = args.Length() > 1 ? args[1] : args.This()->Get(args[0]); if (func->IsFunction()) { tTJSVariant value = toVariant(isolate, func->ToObject(), args.This()); String::Value methodName(args[0]); tjs_error error; if (TJS_FAILED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *methodName, NULL, &value, NULL))) { args.GetReturnValue().Set(ERROR_KRKR(isolate, error)); return; } args.GetReturnValue().Set(Undefined(isolate)); return; } } args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "not function"))); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void checkNextEvent(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); Local<Boolean> ret; /*********************************** C++ CODE : BEGIN ***********************************/ state = IEE_EngineGetNextEvent(eEvent); if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); // Log the EmoState if it has been updated if (eventType == IEE_EmoStateUpdated) { IEE_EmoEngineEventGetEmoState(eEvent, eState); ret = Boolean::New(isolate, true); } else{ ret = Boolean::New(isolate, false); } } else{ ret = Boolean::New(isolate, false); } /*********************************** C++ CODE : END ***********************************/ args.GetReturnValue().Set(ret); }
/* * Prototype: * Module.findBaseAddress(module_name) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_find_base_address ( const FunctionCallbackInfo<Value> & info) { GumV8Module * self = static_cast<GumV8Module *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); Local<Value> module_name_val = info[0]; if (!module_name_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findBaseAddress: argument must be a string " "specifying module name"))); return; } String::Utf8Value module_name (module_name_val); GumAddress raw_address = gum_module_find_base_address (*module_name); if (raw_address != 0) { info.GetReturnValue ().Set ( _gum_v8_native_pointer_new (GSIZE_TO_POINTER (raw_address), self->core)); } else { info.GetReturnValue ().SetNull (); } }
void WeakRef::GettertCallback(const FunctionCallbackInfo<Value>& args) { try { auto holder = args.This(); auto poTarget = reinterpret_cast<Persistent<Object>*>(holder->GetHiddenValue(V8StringConstants::GetTarget()).As<External>()->Value()); auto isolate = args.GetIsolate(); if (poTarget != nullptr) { auto target = Local<Object>::New(isolate, *poTarget); args.GetReturnValue().Set(target); } else { args.GetReturnValue().Set(Null(isolate)); } } 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(); } }
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 BookWrap::Each(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Book* book = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book; if (args.Length() == 1) { if (args[0]->IsFunction()) { Local<Function> fun = Local<Function>::Cast(args[0]); for(uint32_t i = 0; i < book->size(); ++i) { Local<Object> pw = PersonWrap::New(isolate, book, i); Local<Value> argv[1] = { pw }; fun->Call(Null(isolate), 1, argv); } args.GetReturnValue().SetUndefined(); return; } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Function expected"))); args.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected"))); args.GetReturnValue().SetUndefined(); return; } }
void NodeOSXTheme::GetMode(const FunctionCallbackInfo<Value>& iArgs) { Isolate* isolate = iArgs.GetIsolate(); Local<String> mode = String::NewFromUtf8(isolate, OSXTheme::GetMode().c_str()); iArgs.GetReturnValue().Set(mode); }
/* * Prototype: * Stalker.addCallProbe(target_address, callback) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_stalker_on_add_call_probe (const FunctionCallbackInfo<Value> & info) { GumV8Stalker * self = static_cast<GumV8Stalker *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); GumV8CallProbe * probe; GumProbeId id; gpointer target_address; if (!_gum_v8_native_pointer_get (info[0], &target_address, self->core)) return; Local<Value> callback_value = info[1]; if (!callback_value->IsFunction ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Stalker.addCallProbe: second argument must be a function"))); return; } Local<Function> callback = Local<Function>::Cast (callback_value); probe = g_slice_new (GumV8CallProbe); probe->parent = self; probe->callback = new GumPersistent<Function>::type (isolate, callback); probe->receiver = new GumPersistent<Value>::type (isolate, info.This ()); id = gum_stalker_add_call_probe (_gum_v8_stalker_get (self), target_address, gum_v8_call_probe_fire, probe, reinterpret_cast<GDestroyNotify> (gum_v8_call_probe_free)); info.GetReturnValue ().Set (id); }
void IdPool::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (args.IsConstructCall()) { // Invoked as constructor: `new IdPool(...)` double value = args[0]->IsUndefined() || !args[0]->IsNumber()? 0 : args[0]->NumberValue() / 8; if (value > DEFAULT_CTOR_MAX_POSSIBLE_SIZE) { JS_THROW(isolate, "Size too large"); return; } // ceil size_t poolSize = value + (size_t)((size_t)value != value); try { IdPool* obj = new IdPool(poolSize); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } catch (std::Exception e) { JS_THROW(isolate, e.what()); return; } } else { // Invoked as plain function `IdPool(...)`, 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)); } }
void ABPFilterParserWrap::Serialize(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); ABPFilterParserWrap* obj = ObjectWrap::Unwrap<ABPFilterParserWrap>(args.Holder()); int totalSize = 0; // Serialize data char* data = obj->serialize(&totalSize); if (nullptr == data) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Could not serialize"))); return; } MaybeLocal<Object> buffer = node::Buffer::New(isolate, totalSize); Local<Object> localBuffer; if (!buffer.ToLocal(&localBuffer)) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Could not convert MaybeLocal to Local"))); return; } memcpy(node::Buffer::Data(localBuffer), data, totalSize); delete[] data; args.GetReturnValue().Set(localBuffer); }
void IdPool::clear(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); IdPool* idPool = ObjectWrap::Unwrap<IdPool>(args.Holder()); idPool->_clear(); }
void IdPool::length(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); IdPool* idPool = ObjectWrap::Unwrap<IdPool>(args.Holder()); args.GetReturnValue().Set(Number::New(isolate, idPool->_reserved)); }
void Bus::Watch(const FunctionCallbackInfo<Value>& info) { //g_print("watching\n"); Isolate *isolate = info.GetIsolate(); Bus *bus = ObjectWrap::Unwrap<Bus>(info.This()); GstBus *gstBus = bus->gstBus(); GstMessage *msg; gboolean terminate = FALSE; do { msg = gst_bus_timed_pop_filtered(gstBus, GST_CLOCK_TIME_NONE, GstMessageType(GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_STATE_CHANGED: g_print("state changed\n"); /*bus->Emit(info, String::NewFromUtf8(isolate, "stateChanged"), String::NewFromUtf8(isolate, "data")); */ break; } } while(!terminate); /*WatchHelper *watchHelper = new WatchHelper(); watchHelper->bus = bus; guint watchId = gst_bus_add_watch(bus->gstBus(), bus->BusCallback, (void*)watchHelper); bus->watchId(watchId);*/ }