void MySQL::JS_Close(const FunctionCallbackInfo<Value> & args){ auto mysql = Instance(args.Holder()); auto mysqlconn = ConnectionInstance(args.Holder()); std::lock_guard<std::mutex> lock{ mysqlconn->lock }; if (mysql->isConnected(mysqlconn->mysql)){ mysql_close(mysqlconn->mysql); } }
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); }); }
void MySQL::JS_Query(const FunctionCallbackInfo<Value> & args){ auto mysql = Instance(args.Holder()); auto mysqlconn = ConnectionInstance(args.Holder()); string query = JS2STRING(args[0]); if (args[1]->IsFunction()){ Persistent<Function, CopyablePersistentTraits<Function>> func; func.Reset(args.GetIsolate(), Local<Function>::Cast(args[1])); mysql->QueryAsync(mysqlconn->id, query, func); return; } }
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); }); }
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 ETW::Status(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); ETW* obj = ObjectWrap::Unwrap<ETW>(args.Holder()); args.GetReturnValue().Set(Number::New(isolate, obj->m_pTraceSession->Status())); }
inline typename boost::enable_if<boost::is_member_function_pointer<TCallback>, TResult >::type invoke (const FunctionCallbackInfo<Value> &info) { typedef typename mpl::begin<TSignature>::type TSeqFirst; typedef typename mpl::next< TSeqFirst >::type TSeqInstanceType; typedef typename boost::remove_const<typename boost::remove_reference<typename TSeqInstanceType::type>::type >::type TInstanceType; /* Retrieve "this" from V8 */ Local<Object> _this = info.Holder(); /* Get address by casting the External saved value. Note that it was saved in NativeClass<TClass>::ctor */ TInstanceType *instance = static_cast<TInstanceType *>(_this->GetAlignedPointerFromInternalField(_this->InternalFieldCount() - 2)); # if N # define BOOST_PP_LOCAL_MACRO(i) V8_BRIDGE_SETUP_ARG(i, TSeqInstanceType) # define BOOST_PP_LOCAL_LIMITS (0, N-1) # include BOOST_PP_LOCAL_ITERATE() # endif return bridge::detail::invoke_native_raw<TResult>( this->m_isolationScope , detail::invoke_tag<TResult, TPointer>() , this->m_callbackPointer , instance BOOST_PP_ENUM_TRAILING_PARAMS(N, resolvedArg) ); }
//! \verbatim //! String Quaternion.toString //! \endverbatim void Quaternion::jsToString( const FunctionCallbackInfo<v8::Value>& args ) { Quaternion* ptr = unwrap( args.Holder() ); char result[128]; sprintf_s<128>( result, "Quaternion[%f,%f,%f,%f]", ptr->w, ptr->x, ptr->y, ptr->z ); args.GetReturnValue().Set( Util::allocString( result ) ); }
void hash(const FunctionCallbackInfo<Value>& args) { if (args.Length() < 1) { Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentCount); return; } if (!args[0]->IsInt32()) { Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentType); return; } QByteArray input = ModuleByteArray::unwrapByteArray(args.GetIsolate(), args.Holder()); int algorithm = args[0]->Int32Value(); HandleScope handle_scope(args.GetIsolate()); QByteArray hashValue; switch (algorithm) { case QCryptographicHash::Md4: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Md4); break; case QCryptographicHash::Md5: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Md5); break; case QCryptographicHash::Sha1: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha1); break; case QCryptographicHash::Sha224: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha224); break; case QCryptographicHash::Sha256: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha256); break; case QCryptographicHash::Sha384: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha384); break; case QCryptographicHash::Sha512: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha512); break; case QCryptographicHash::Sha3_224: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha3_224); break; case QCryptographicHash::Sha3_256: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha3_256); break; case QCryptographicHash::Sha3_384: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha3_384); break; case QCryptographicHash::Sha3_512: hashValue = QCryptographicHash::hash(input, QCryptographicHash::Sha3_512); break; default: { Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentValue); return; } } args.GetReturnValue().Set(ModuleByteArray::wrapByteArray(args.GetIsolate(), hashValue)); }
void broadcast(const FunctionCallbackInfo<Value> &args) { uWS::Server *server = (uWS::Server *) args.Holder()->GetAlignedPointerFromInternalField(0); OpCode opCode = args[1]->BooleanValue() ? BINARY : TEXT; NativeString nativeString(args[0]); server->broadcast(nativeString.getData(), nativeString.getLength(), opCode); }
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 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 LCDWrapper::Home(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); LCDWrapper* temp_obj = ObjectWrap::Unwrap<LCDWrapper>(args.Holder()); temp_obj->lcd->home(); }
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 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 IdPool::clear(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); IdPool* idPool = ObjectWrap::Unwrap<IdPool>(args.Holder()); idPool->_clear(); }
void Bindings::destroy(const FunctionCallbackInfo<Value>& args) { Isolate* isolate(args.GetIsolate()); HandleScope scope(isolate); Bindings* obj = ObjectWrap::Unwrap<Bindings>(args.Holder()); obj->m_session.reset(); }
void TempWrapper::Temperature(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); TempWrapper* temp_obj = ObjectWrap::Unwrap<TempWrapper>(args.Holder()); args.GetReturnValue().Set(Number::New(isolate,temp_obj->tempSensor->getTemperature())); }
//! \verbatim //! Real Quaternion.dot( Quaternion other ) //! \endverbatim void Quaternion::jsDot( const FunctionCallbackInfo<v8::Value>& args ) { Quaternion* ptr = unwrap( args.Holder() ); Quaternion* other = Util::extractQuaternion( 0, args ); if ( !other ) return; args.GetReturnValue().Set( ptr->Dot( *other ) ); }
void ABPFilterParserWrap::Parse(const FunctionCallbackInfo<Value>& args) { String::Utf8Value str(args[0]->ToString()); const char * buffer = *str; ABPFilterParserWrap* obj = ObjectWrap::Unwrap<ABPFilterParserWrap>(args.Holder()); obj->parse(buffer); }
void MySQL::JS_RealEscape(const FunctionCallbackInfo<Value> & args){ auto mysqlconn = ConnectionInstance(args.Holder()); string str = JS2STRING(args[0]); char* tmp = new char[str.length() * 2 + 1]; mysql_real_escape_string(mysqlconn->mysql, tmp, str.c_str(), str.length()); args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), tmp)); }
void MyObject::open(const FunctionCallbackInfo<Value>& args) { Isolate* isolate=Isolate::GetCurrent(); HandleScope scope(isolate); MyObject *obj=ObjectWrap::Unwrap<MyObject>(args.Holder()); obj->leftPort.open(); obj->rightPort.open(); }
//! \verbatim //! Vector3 Quaternion.multiply( Vector3 ) //! Rotate vector by quaternion //! \endverbatim void Quaternion::jsMultiply( const FunctionCallbackInfo<v8::Value>& args ) { Quaternion* ptr = unwrap( args.Holder() ); Vector3* other = Util::extractVector3( 0, args ); if ( !other ) return; Ogre::Vector3 result = (Ogre::Quaternion)*ptr * (Ogre::Vector3)*other; args.GetReturnValue().Set( Vector3::newFrom( result ) ); }
void ETW::Process(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); ETW* obj = ObjectWrap::Unwrap<ETW>(args.Holder()); // TODO: Find out how to unblock main thread args.GetReturnValue().Set(Boolean::New(isolate, obj->m_pTraceSession->Process())); }
void Bindings::info(const FunctionCallbackInfo<Value>& args) { Isolate* isolate(args.GetIsolate()); HandleScope scope(isolate); Bindings* obj = ObjectWrap::Unwrap<Bindings>(args.Holder()); const std::string info(obj->m_session->info()); args.GetReturnValue().Set(String::NewFromUtf8(isolate, info.c_str())); }
void LCDWrapper::Message(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); LCDWrapper* temp_obj = ObjectWrap::Unwrap<LCDWrapper>(args.Holder()); String::Utf8Value msg(args[0]->ToString()); std::string _msg = std::string(*msg); args.GetReturnValue().Set(Number::New(isolate,temp_obj->lcd->message(_msg))); }
void Bindings::construct(const FunctionCallbackInfo<Value>& args) { Isolate* isolate(args.GetIsolate()); HandleScope scope(isolate); if (args.IsConstructCall()) { // Invoked as constructor with 'new'. Bindings* obj = new Bindings(); obj->Wrap(args.Holder()); args.GetReturnValue().Set(args.Holder()); } else { // Invoked as a function, turn into construct call. Local<Function> ctor(Local<Function>::New(isolate, constructor)); args.GetReturnValue().Set(ctor->NewInstance()); } }
void close(const FunctionCallbackInfo<Value> &args) { uWS::Server *server = (uWS::Server *) args.Holder()->GetAlignedPointerFromInternalField(0); if (args.Length()) { // socket, code, data uWS::Socket socket = unwrapSocket(args[0]->ToNumber()); NativeString nativeString(args[2]); socket.close(false, args[1]->IntegerValue(), nativeString.getData(), nativeString.getLength()); } else { server->close(false); } }
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder()); obj->value_ += 1; args.GetReturnValue().Set(Number::New(isolate, obj->value_)); }
void ETW::OpenTrace(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); Local<Function> cb = Local<Function>::Cast(args[0]); Persistent<Function, CopyablePersistentTraits<Function>> callback(isolate, cb); NodeTraceConsumer* consumer = new NodeTraceConsumer(callback); ETW* obj = ObjectWrap::Unwrap<ETW>(args.Holder()); obj->m_traceConsumers.push_back(consumer); args.GetReturnValue().Set(Boolean::New(isolate, obj->m_pTraceSession->OpenTrace(consumer))); }