void APIBinding::_CreateKList(const ValueList& args, KValueRef result) { args.VerifyException("createKList", "?l"); if (args.size() <= 0) { result->SetList(new StaticBoundList()); } else { KListRef wrapped = args.GetList(0); result->SetList(new KListWrapper(wrapped)); } }
void Clipboard::_GetData(const ValueList& args, KValueRef result) { args.VerifyException("getData", "s"); std::string mimeType(args.GetString(0)); DataType type = MimeTypeToDataType(mimeType); if (type == URI_LIST) { std::vector<std::string>& list = this->GetURIList(); if (mimeType == "url") { std::string url; if (list.size() > 0) url = list.at(0); result->SetString(url.c_str()); } else { result->SetList(StaticBoundList::FromStringVector(list)); } } else if (type == IMAGE) { result->SetObject(this->GetImage(mimeType)); } else { result->SetString(this->GetText()); } }
void ApplicationBinding::_GetAvailableModules(const ValueList& args, KValueRef result) { std::vector<SharedComponent> components; this->application->GetAvailableComponents(components); KListRef componentList = APIBinding::ComponentVectorToKList(components, MODULE); result->SetList(componentList); }
void ApplicationBinding::_GetBundledRuntimes(const ValueList& args, KValueRef result) { std::vector<SharedComponent> components; this->application->GetAvailableComponents(components, true); KListRef componentList = APIBinding::ComponentVectorToKList(components, RUNTIME); result->SetList(componentList); }
void Bytes::_Split(const ValueList& args, KValueRef result) { // This method now follows the spec located at: // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/split // Except support for regular expressions args.VerifyException("Bytes.split", "?s,i"); KListRef list = new StaticBoundList(); result->SetList(list); std::string target = ""; if (this->size > 0) { target = this->buffer; } else { list->Append(Value::NewString(target)); return; } if (args.size() <= 0) { list->Append(Value::NewString(target)); return; } std::string separator = args.GetString(0); int limit = args.GetInt(1, INT_MAX); // We could use Poco's tokenizer here, but it doesn't split strings // like "abc,def,," -> ['abc', 'def', '', ''] correctly. It produces // ['abc', 'def', ''] which is a different behavior than the JS split. // So we roll our own for now -- it's not very efficient right now, but // it should be correct. size_t next = target.find(separator); while (target.size() > 0 && next != std::string::npos) { std::string token; if (separator.size() == 0) { token = target.substr(0, 1); } else { token = target.substr(0, next); } target = target.substr(next + 1); next = target.find(separator); if ((int) list->Size() >= limit) return; list->Append(Value::NewString(token)); } if ((int) list->Size() < limit && separator.size() != 0) list->Append(Value::NewString(target)); }
void ApplicationBinding::_GetManifest(const ValueList& args, KValueRef result) { vector<pair<string, string> > manifest = BootUtils::ReadManifestFile(this->application->manifestPath); KListRef manifestList = APIBinding::ManifestToKList(manifest); result->SetList(manifestList); }
void APIBinding::_GetInstalledComponentsImpl( KComponentType type, const ValueList& args, KValueRef result) { bool force = args.GetBool(0, false); vector<SharedComponent>& components = BootUtils::GetInstalledComponents(force); KListRef componentList = ComponentVectorToKList(components, type); result->SetList(componentList); }
void UIBinding::_GetOpenWindows(const ValueList& args, KValueRef result) { KListRef list = new StaticBoundList(); std::vector<AutoUserWindow>::iterator w = openWindows.begin(); while (w != openWindows.end()) { list->Append(Value::NewObject(*w++)); } result->SetList(list); }
void HostBinding::GetAliases(const ValueList& args, KValueRef result) { KListRef list = new StaticBoundList(); std::vector<std::string> aliases = this->host.aliases(); std::vector<std::string>::iterator iter = aliases.begin(); while (iter!=aliases.end()) { std::string alias = (*iter++); list->Append(Value::NewString(alias)); } result->SetList(list); }
void AppBinding::GetArguments(const ValueList& args, KValueRef result) { static KListRef argList(0); if (argList.isNull()) { // Skip the first argument which is the filename to the executable argList = new StaticBoundList(); for (int i = 1; i < host->GetCommandLineArgCount(); i++) argList->Append(Value::NewString(host->GetCommandLineArg(i))); } result->SetList(argList); }
void HostBinding::GetAddresses(const ValueList& args, KValueRef result) { KListRef list = new StaticBoundList(); std::vector<IPAddress> addresses = this->host.addresses(); std::vector<IPAddress>::iterator iter = addresses.begin(); while (iter!=addresses.end()) { IPAddress address = (*iter++); KObjectRef obj = new IPAddressBinding(address); KValueRef addr = Value::NewObject(obj); list->Append(addr); } result->SetList(list); }
void AppBinding::GetArguments(const ValueList& args, KValueRef result) { static KListRef argList(0); if (argList.isNull()) { // Skip the first argument which is the filename of the executable. std::vector<std::string>& args = host->GetApplication()->GetArguments(); argList = new StaticBoundList(); for (size_t i = 1; i < args.size(); i++) argList->Append(Value::NewString(args.at(i))); } result->SetList(argList); }
void Properties::ListProperties(const ValueList& args, KValueRef result) { std::vector<std::string> keys; config->keys(keys); KListRef property_list = new StaticBoundList(); for (size_t i = 0; i < keys.size(); i++) { std::string property_name = keys.at(i); KValueRef name_value = Value::NewString(property_name.c_str()); property_list->Append(name_value); } result->SetList(property_list); }
void ApplicationBinding::_GetComponents(const ValueList& args, KValueRef result) { // Do not use a reference here, because we don't want to modify the // application's modules list. std::vector<SharedComponent> components = this->application->modules; if (!this->application->runtime.isNull()) { components.push_back(this->application->runtime); } for (size_t i = 0; i < this->application->sdks.size(); i++) { components.push_back(this->application->sdks[i]); } KListRef componentList = APIBinding::ComponentVectorToKList(components); result->SetList(componentList); }
void PropertiesBinding::GetList(const ValueList& args, KValueRef result) { KValueRef stringValue = Value::Null; GetString(args, stringValue); if (!stringValue->IsNull()) { KListRef list = new StaticBoundList(); std::string string = stringValue->ToString(); Poco::StringTokenizer t(string, ",", Poco::StringTokenizer::TOK_TRIM); for (size_t i = 0; i < t.count(); i++) { KValueRef token = Value::NewString(t[i].c_str()); list->Append(token); } KListRef list2 = list; result->SetList(list2); } }
void FilesystemBinding::GetRootDirectories(const ValueList& args, KValueRef result) { try { Poco::Path path; std::vector<std::string> roots; path.listRoots(roots); KListRef rootList = new StaticBoundList(); for(size_t i = 0; i < roots.size(); i++) { ti::File* file = new ti::File(roots.at(i)); KValueRef value = Value::NewObject((KObjectRef) file); rootList->Append(value); } KListRef list = rootList; result->SetList(list); } catch (Poco::Exception& exc) { throw ValueException::FromString(exc.displayText()); } }
void APIBinding::_GetComponentSearchPaths(const ValueList& args, KValueRef result) { vector<string>& paths = BootUtils::GetComponentSearchPaths(); KListRef pathList = StaticBoundList::FromStringVector(paths); result->SetList(pathList); }
void Process::_GetArguments(const ValueList& args, KValueRef result) { result->SetList(this->args); }
void ApplicationBinding::_GetModules(const ValueList& args, KValueRef result) { std::vector<SharedComponent>& components = this->application->modules; KListRef componentList = APIBinding::ComponentVectorToKList(components); result->SetList(componentList); }
void ApplicationBinding::_ResolveDependencies(const ValueList& args, KValueRef result) { std::vector<SharedDependency> unresolved = this->application->ResolveDependencies(); result->SetList(APIBinding::DependencyVectorToKList(unresolved)); }
void ApplicationBinding::_GetDependencies(const ValueList& args, KValueRef result) { result->SetList(APIBinding::DependencyVectorToKList( this->application->dependencies)); }
void ApplicationBinding::_GetArguments(const ValueList& args, KValueRef result) { std::vector<std::string> arguments = this->application->GetArguments(); KListRef argumentList = StaticBoundList::FromStringVector(arguments); result->SetList(argumentList); }
void Network::_GetInterfaces(const ValueList& args, KValueRef result) { result->SetList(interfaceList); }