void Blob::LastIndexOf(const ValueList& args, SharedValue result) { // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/lastIndexOf args.VerifyException("Blob.lastIndexOf", "s,?i"); if (this->length <= 0) { result->SetInt(-1); } else { std::string target = this->buffer; std::string needle = args.at(0)->ToString(); int start = target.size() + 1; if (args.size() > 1) { start = args.GetNumber(1); if (start < 0) { start = 0; } } result->SetInt(target.rfind(needle, start)); } }
void ResultSetBinding::FieldCount(const ValueList& args, SharedValue result) { if (rs.isNull()) { result->SetInt(0); } else { result->SetInt(rs->columnCount()); } }
void Pipe::Write(const ValueList& args, SharedValue result) { if (closed) { throw ValueException::FromString("Pipe is already closed"); } if (!args.at(0)->IsString()) { throw ValueException::FromString("Can only write string data"); } Poco::PipeOutputStream *os = dynamic_cast<Poco::PipeOutputStream*>(pipe); if (os==NULL) { throw ValueException::FromString("Stream is not writeable"); } const char *data = args.at(0)->ToString(); int len = (int)strlen(data); try { os->write(data,len); result->SetInt(len); } catch (Poco::WriteFileException &e) { throw ValueException::FromString(e.what()); } }
void NetworkBinding::AddConnectivityListener(const ValueList& args, SharedValue result) { args.VerifyException("addConnectivityListener", "m"); SharedKMethod target = args.at(0)->ToMethod(); Listener listener = Listener(); listener.id = this->next_listener_id++; listener.callback = target; this->listeners.push_back(listener); result->SetInt(listener.id); }
void UserWindow::_AddEventListener(const ValueList& args, SharedValue result) { args.VerifyException("addEventListener", "m"); SharedKMethod target = args.at(0)->ToMethod(); Listener listener = Listener(); listener.id = this->next_listener_id++; listener.callback = target; this->listeners.push_back(listener); result->SetInt(listener.id); }
void ResultSetBinding::TransformValue(size_t index, SharedValue result) { MetaColumn::ColumnDataType type = rs->columnType(index); Poco::DynamicAny value = rs->value(index); if (value.isEmpty()) { result->SetNull(); } else if (type == MetaColumn::FDT_STRING) { std::string str; value.convert(str); result->SetString(str); } else if (type == MetaColumn::FDT_BOOL) { bool v = false; value.convert(v); result->SetBool(v); } else if (type == MetaColumn::FDT_FLOAT || type == MetaColumn::FDT_DOUBLE) { float f = 0; value.convert(f); result->SetDouble(f); } else if (type == MetaColumn::FDT_BLOB || type == MetaColumn::FDT_UNKNOWN) { std::string str; value.convert(str); result->SetString(str); } else { // the rest of these are ints: // FDT_INT8, // FDT_UINT8, // FDT_INT16, // FDT_UINT16, // FDT_INT32, // FDT_UINT32, // FDT_INT64, // FDT_UINT64, int i; value.convert(i); result->SetInt(i); } }
void TCPSocketBinding::Write(const ValueList& args, SharedValue result) { std::string eprefix = "TCPSocketBinding::Write: "; if (!this->opened) { throw ValueException::FromString(eprefix + "Socket is not open"); } try { std::string buf = args.at(0)->ToString(); int count = this->socket.sendBytes(buf.c_str(),buf.length()); result->SetInt(count); } catch(Poco::Exception &e) { throw ValueException::FromString(eprefix + e.displayText()); } }
void Menu::_GetLength(const ValueList& args, SharedValue result) { result->SetInt(this->children.size()); }
void HttpServerRequest::GetContentLength(const ValueList& args, SharedValue result) { result->SetInt(request.getContentLength()); }
void Blob::Length(const ValueList& args, SharedValue result) { result->SetInt(length); }
void ComponentBinding::_GetType(const ValueList& args, SharedValue result) { result->SetInt((int) this->component->type); }