Example #1
0
Func_BezierPrototype::Func_BezierPrototype(Environment &env, const ValueList &nums) :
				Function(env, Gura_Symbol(_anonymous_), FUNCTYPE_Function, FLAG_None)
{
	_nums.reserve(nums.size());
	if (nums.size() == 3) {
		Number num0 = nums[0].GetNumber();
		Number num1 = nums[1].GetNumber();
		Number num2 = nums[2].GetNumber();
		_nums.push_back(num0);
		_nums.push_back(2 * num1 - 2 * num0);
		_nums.push_back(num2 - 2 * num1 + num0);
	} else if (nums.size() == 4) {
		Number num0 = nums[0].GetNumber();
		Number num1 = nums[1].GetNumber();
		Number num2 = nums[2].GetNumber();
		Number num3 = nums[3].GetNumber();
		_nums.push_back(num0);
		_nums.push_back(3 * num1 - 3 * num0);
		_nums.push_back(3 * num2 - 6 * num1 + 3 * num0);
		_nums.push_back(num3 - 3 * num2 + 3 * num1 - num0);
	} else {
		foreach_const (ValueList, pValue, nums) {
			_nums.push_back(pValue->GetNumber());
		}
	}
Example #2
0
	SharedValue KRubyMethod::Call(const ValueList& args)
	{
		// Bloody hell, Ruby will segfault if we try to pass a number
		// of args to a method that is greater than its arity
		int arity = MethodArity(this->method);
		VALUE ruby_args = rb_ary_new();

		if (this->arg != Qnil)
			rb_ary_push(ruby_args, this->arg);

		// A negative arity means that this method can take a
		// variable number of arguments, so pass all args
		if (arity < 0)
			arity = args.size();

		for (size_t i = 0; i < args.size() && (int) i < arity; i++)
			rb_ary_push(ruby_args, RubyUtils::ToRubyValue(args[i]));

		int error;
		VALUE do_call_args = rb_ary_new();
		rb_ary_push(do_call_args, this->method);
		rb_ary_push(do_call_args, ruby_args);
		VALUE result = rb_protect(DoMethodCall, do_call_args, &error);

		if (error != 0)
		{
			ValueException e = RubyUtils::GetException();
			SharedString ss = e.DisplayString();
			std::cout << "Error: " << *ss << std::endl;
			throw e;
		}

		return RubyUtils::ToKrollValue(result);
	}
Example #3
0
    KValueRef KPythonMethod::Call(const ValueList& args)
    {
        PyLockGIL lock;
        PyObject *arglist = NULL;

        if (args.size() > 0)
        {
            arglist = PyTuple_New(args.size());
            for (size_t i = 0; i < args.size(); i++)
            {
                PyObject *pv = PythonUtils::ToPyObject(args[i]);
                PyTuple_SetItem(arglist, i, pv);
            }
        }

        PyObject *response = PyObject_CallObject(this->method, arglist);
        Py_XDECREF(arglist);

        KValueRef value = Value::Undefined;
        if (response == NULL && PyErr_Occurred() != NULL)
        {
            THROW_PYTHON_EXCEPTION
        }
        else if (response != NULL)
        {
            value = PythonUtils::ToKrollValue(response);
            Py_DECREF(response);
        }

        return value;
    }
Example #4
0
	SharedValue KKJSMethod::Call(const ValueList& args)
	{
		JSValueRef* js_args = new JSValueRef[args.size()];
		for (int i = 0; i < (int) args.size(); i++)
		{
			SharedValue arg = args.at(i);
			js_args[i] = KJSUtil::ToJSValue(arg, this->context);
		}

		JSValueRef exception = NULL;
		JSValueRef js_value = JSObjectCallAsFunction(
			this->context,
			this->object,
			this->this_obj,
			args.size(),
			js_args,
			&exception);

		delete [] js_args; // clean up args

		if (js_value == NULL && exception != NULL) //exception thrown
		{
			SharedValue tv_exp = KJSUtil::ToKrollValue(exception, this->context, NULL);
			throw ValueException(tv_exp);
		}

		return KJSUtil::ToKrollValue(js_value, this->context, NULL);
	}
Example #5
0
	void HTTPClientBinding::Open(const ValueList& args, SharedValue result)
	{
		if (args.size()<2)
		{
			throw ValueException::FromString("invalid arguments");
		}
		this->method = args.at(0)->ToString();
		this->url = args.at(1)->ToString();
		if (args.size()>=3)
		{
			GET_BOOL_PROP(args.at(2),this->async)
		}
		if (args.size()>=4)
		{
			this->user = args.at(3)->ToString();
		}
		if (args.size()>4)
		{
			this->password = args.at(4)->ToString();
		}
		// assign it here (helps prevent deadlock)
		SharedValue v = this->Get("onreadystatechange");
		if (v->IsMethod())
		{
			this->readystate = v->ToMethod();
		}
		SharedValue vc = this->Get("onchange");
		if (vc->IsMethod())
		{
			this->onchange = vc->ToMethod();
		}
		this->ChangeState(1); // opened
	}
SharedValue LuaEvaluator::Call(const ValueList& args)
{
	debug( "LuaEvaluator::Call: %u\r\n", (unsigned int) args.size() );

	if( 	args.size() != 3
		|| !args.at( 1 )->IsString()
		|| !args.at( 2 )->IsObject() )
	{
		return Value::Undefined;
	}
	
	SharedStringList s = args.at( 2 )->ToObject()->GetPropertyNames();
	for( size_t i = 0; i < s->size(); i++ )
	{
		debug( "toplevel: %s\r\n", s->at(i)->c_str() );
	}
	
	lua_State *L = LuaModule::L();
	if( KLuaUtil::toLua( L, args.at( 2 ) ) == 1 )
	{
		lua_setfield( L, LUA_GLOBALSINDEX, "current" );  
		if( luaL_dostring( L, args.at( 1 )->ToString() ) == 1 )
		{
			debug( "LuaEvaluator::Call: error\r\n%s\r\n", lua_tostring( L, -1 ) );

		}
		else
		{
			debug( "LuaEvaluator::Call: success\r\n" );
			
		} // if	
	} // if	
	return Value::Undefined;
}
Example #7
0
void UserWindow::_CreateWindow(const ValueList& args, SharedValue result)
{
	//TODO: wrap in sharedptr
	WindowConfig *config = NULL;

	if (args.size() > 0 && args.at(0)->IsObject())
	{
		SharedKObject props = SharedKObject(new StaticBoundObject());
		config = new WindowConfig();
		props = args.at(0)->ToObject();
		config->UseProperties(props);
	}
	else if (args.size() > 0 && args.at(0)->IsString())
	{
		// String might match a url spec
		std::string url = args.at(0)->ToString();
		WindowConfig* matchedConfig = AppConfig::Instance()->GetWindowByURL(url);

		url = AppConfig::Instance()->InsertAppIDIntoURL(url);
		config = new WindowConfig(matchedConfig, url);
	}
	else
	{
		config = new WindowConfig();
	}

	SharedUserWindow new_window = this->binding->CreateWindow(config, shared_this);
	result->SetObject(new_window);
}
	void PropertiesBinding::Getter(const ValueList& args, KValueRef result, Type type)
	{
		if (args.size() > 0 && args.at(0)->IsString())
		{
			std::string eprefix = "PropertiesBinding::Get: ";
			try
			{
				std::string property = args.at(0)->ToString();
				if (args.size() == 1)
				{
					switch (type)
					{
						case Bool: 
							result->SetBool(config->getBool(property));
							break;
						case Double:
							result->SetDouble(config->getDouble(property));
							break;
						case Int:
							result->SetInt(config->getInt(property));
							break;
						case String:
							result->SetString(config->getString(property).c_str());
							break;
						default:
							break;
					}
					return;
				}

				else if (args.size() >= 2)
				{
					switch (type)
					{
						case Bool:
							result->SetBool(config->getBool(property, args.at(1)->ToBool()));
							break;
						case Double:
							result->SetDouble(config->getDouble(property, args.at(1)->ToDouble()));
							break;
						case Int:
							result->SetInt(config->getInt(property, args.at(1)->ToInt()));
							break;
						case String:
							result->SetString(config->getString(property, args.at(1)->ToString()).c_str());
							break;
						default: break;
					}
					return;
				}
			}
			catch(Poco::Exception &e)
			{
				throw ValueException::FromString(eprefix + e.displayText());
			}
		}
	}
Example #9
0
	void FileStream::Open(const ValueList& args, SharedValue result)
	{
		FileStreamMode mode = MODE_READ;
		bool binary = false;
		bool append = false;
		if (args.size()>=1) mode = (FileStreamMode)args.at(0)->ToInt();
		if (args.size()>=2) binary = args.at(1)->ToBool();
		if (args.size()>=3) append = args.at(2)->ToBool();
		bool opened = this->Open(mode,binary,append);
		result->SetBool(opened);
	}
Example #10
0
	void MenuItem::_AddSubMenu(const ValueList& args, SharedValue result)
	{
		SharedValue label = Value::Undefined;
		SharedValue icon_url = Value::Undefined;

		if (args.size() > 0 && args.at(0)->IsString())
			label = args.at(0);

		if (args.size() > 1 && args.at(1)->IsString())
			icon_url = args.at(1);

		SharedValue new_item = this->AddSubMenu(label, icon_url);
		result->SetValue(new_item);
	}
Example #11
0
void PointToDrawer::printToDot(raw_ostream &O) {
  IDAssigner &IDA = getAnalysis<IDAssigner>();
  PointerAnalysis &PA = getAnalysis<PointerAnalysis>();

  O << "strict digraph PointTo {\n";

  set<unsigned> PointerVids, PointeeVids;
  ValueList Pointers;
  PA.getAllPointers(Pointers);
  for (size_t i = 0; i < Pointers.size(); ++i) {
    Value *Pointer = Pointers[i];
    assert(Pointer != NULL);
    assert(Pointer->getType()->isPointerTy());

    unsigned PointerVid = IDA.getValueID(Pointer);
    assert(PointerVid != IDAssigner::InvalidID);
    PointerVids.insert(PointerVid);

    ValueList Pointees;
    PA.getPointees(Pointer, Pointees);

    for (size_t j = 0; j < Pointees.size(); ++j) {
      Value *Pointee = Pointees[j];
      assert(Pointee != NULL);

      unsigned PointeeVid = IDA.getValueID(Pointee);
      assert(PointeeVid != IDAssigner::InvalidID);
      PointeeVids.insert(PointeeVid);
      
      O << "TopLevel" << PointerVid << " -> AddrTaken" << PointeeVid << "\n";
    }
  }
  
  for (set<unsigned>::iterator I = PointerVids.begin(); I != PointerVids.end();
       ++I) {
    O << "TopLevel" << *I << " ";
    O << "[label = " << *I << "]\n";
  }

  for (set<unsigned>::iterator I = PointeeVids.begin(); I != PointeeVids.end();
       ++I) {
    O << "AddrTaken" << *I << " ";
    O << "[label = " << *I << ", ";
    O << "style = filled, ";
    O << "fillcolor = yellow]\n";
  }

  O << "}\n";
}
Example #12
0
 void APIBinding::_Log(const ValueList& args, KValueRef result)
 {
     if (args.size() == 1)
     {
         KValueRef v = args.at(0);
         this->Log(Logger::LINFO, v);
     }
     else if (args.size() == 2)
     {
         KValueRef arg1 = args.at(0);
         
         KValueRef v = args.at(1);
         this->Log(ValueToLevel(arg1), v);
     }
 }
Example #13
0
	void ZipFile::DecompressAll(const ValueList& args, KValueRef result)
	{
		std::string destDir;
		if (args.size() < 2)
		{
			throw ValueException::FromString("please provide at least 2 args");
		}
		if (args.at(0)->IsString())
		{
			destDir = args.at(0)->ToString();
		}
		else
		{
			throw ValueException::FromString("invalid argument - first argument must be destDir(string)");
		}

		KMethodRef onCompleteCallback = NULL;
		if (args.at(1)->IsMethod())
		{
			onCompleteCallback = args.at(1)->ToMethod();
		}
		else
		{
			throw ValueException::FromString("invalid argument - second argument must be method callback");
		}

		KMethodRef progressCallback = NULL;
		if (args.size() > 2)
		{
			if (args.at(2)->IsMethod())
			{
				progressCallback = args.at(2)->ToMethod();
			}
			else
			{
				throw ValueException::FromString("invalid argument - third argument must be method callback");
			}
		}

		if(this->onDecompressCompleteCallback)
		{
			throw ValueException::FromString("Another decompress is already in progress please try after some time.");
		}

		this->onDecompressCompleteCallback = onCompleteCallback;
		this->decompressProgressCallback = progressCallback;
		DecompressAll(destDir);
	}
	void AppBinding::CreateProperties(const ValueList& args, SharedValue result)
	{
		AutoPtr<PropertiesBinding> properties = new PropertiesBinding();
		result->SetObject(properties);
		
		if (args.size() > 0 && args.at(0)->IsObject())
		{
			SharedKObject p = args.at(0)->ToObject();
			SharedStringList names = p->GetPropertyNames();
			for (size_t i = 0; i < names->size(); i++)
			{
				SharedValue value = p->Get(names->at(i));
				ValueList setterArgs;
				setterArgs.push_back(Value::NewString(names->at(i)));
				setterArgs.push_back(value);
				PropertiesBinding::Type type;
				
				if (value->IsList()) type = PropertiesBinding::List;
				else if (value->IsInt()) type = PropertiesBinding::Int;
				else if (value->IsDouble()) type = PropertiesBinding::Double;
				else if (value->IsBool()) type = PropertiesBinding::Bool;
				else type = PropertiesBinding::String;
				
				properties->Setter(setterArgs, type);
			}
		}
	}
	void HttpServerRequest::Read(const ValueList& args, SharedValue result)
	{
		std::istream &in = request.stream();
		if (in.eof() || in.fail())
		{
			result->SetNull();
			return;
		}
		int max_size = 8096;
		if (args.size()==1)
		{
			max_size = args.at(0)->ToInt();
		}
		char *buf = new char[max_size];
		in.read(buf,max_size);
		std::streamsize count = in.gcount();
		if (count == 0)
		{
			result->SetNull();
		}
		else
		{
			result->SetObject(new Blob(buf,count));
		}
		delete [] buf;
	}
Example #16
0
	void AppBinding::GetStreamURL(const ValueList& args, SharedValue result)
	{
		const SharedApplication app = this->host->GetApplication();
		std::string stream = app->stream;
		
		// TODO: switch to HTTPS once the ti.Network XHR supports it
		std::string url = "http://api.appcelerator.net/";
		if (stream == "production")
		{
			url+="p/v1";
		}
		else if (stream == "dev")
		{
			url+="d/v1";
		}
		else if (stream == "test")
		{
			url+="t/v1";
		}
		else
		{
			url+=stream;
			url+="/v1";
		}
		for (size_t c = 0; c < args.size(); c++)
		{
			SharedValue arg = args.at(c);
			if (arg->IsString())
			{
				url+="/";
				url+=arg->ToString();
			}
		}
		result->SetString(url);
	}
Example #17
0
        boost::optional<Point>
        filterPointList(
                const ValueList& valueList,
                const PointList& pointList,
                std::vector<Point>& newPointList) const
        {
            typedef typename PointList::const_iterator PointIterator;
            typedef std::vector<SplittingValue<PointIterator>> SplittingValues;
            typedef typename SplittingValues::const_iterator SplittingValueIterator;

            SplittingValues splittingValues;
            splittingValues.reserve(valueList.size());
            for (PointIterator it = std::begin(pointList);
                    it != std::end(pointList); ++it) {
                auto splittingValue = calculateSplittingValue(it, valueList);
                splittingValues.push_back(std::move(splittingValue));
            }
            boost::sort(splittingValues, betterSplittingValue<PointIterator>);

            if (splittingValues.empty() || splittingValues.front().trueNum_ == 0) {
                return boost::optional<Point>();
            }
            Point result = *splittingValues.front().arg_;
            SplittingValueIterator begin = ++splittingValues.begin();
            SplittingValueIterator end = boost::find_if(splittingValues,
                    [](const SplittingValue<PointIterator>& value)
                    { return value.trueNum_ == 0; });
            if (begin != end) {
                newPointList.reserve(std::distance(begin, end));
                std::transform(begin, end, std::back_inserter(newPointList),
                        [](const SplittingValue<PointIterator>& value)
                        { return *(value.arg_); });
            }
            return result;
        } // filterFunctorList
Example #18
0
        Node<Status, T> createLeaf(
                const typename NodeTypes<Status, T>::ValueList& originalValueList,
                int depthRemaining,
                const State& collectedState)
        {
            typedef typename NodeTypes<Status, T>::ValuePtr ValuePtr;
            typedef typename NodeTypes<Status, T>::ValueList ValueList;

            ValueList valueList;
            if (checker_) {
                boost::remove_copy_if(
                        originalValueList,
                        std::back_inserter(valueList),
                        [this, &collectedState](const ValuePtr& value)
                        {
                            State state(collectedState);
                            for (Point  p: value->first.state()) {
                                state.addStone(p);
                            }
                            return !checkState(*checker_, value->first.table(), state);
                        });
            } else {
                valueList = originalValueList;
            }
            advanceProgress(valueList.size(), depthRemaining);
            return LeafNode<Status, T>(std::move(valueList));
        }
Example #19
0
	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 PropertiesBinding::SetList(const ValueList& args, KValueRef result)
	{
		if (args.size() >= 2 && args.at(0)->IsString() && args.at(1)->IsList())
		{
			std::string property = args.at(0)->ToString();
			KListRef list = args.at(1)->ToList();

			std::string value = "";
			for (unsigned int i = 0; i < list->Size(); i++)
			{
				KValueRef arg = list->At(i);
				if (arg->IsString())
				{
					value += list->At(i)->ToString();
					if (i < list->Size() - 1)
					{
						value += ",";
					}
				}
				else
				{
					std::cerr << "skipping object: " << arg->GetType() << std::endl;
				}
			}
			config->setString(property, value);
			if (file_path.size() > 0)
			{
				config->save(file_path);
			}
		}
	}
Example #21
0
	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));
	}
Example #22
0
/*static*/
KValueRef Codec::ExtractZipAsync(const ValueList& args)
{
    std::string zipFile = args.GetString(0);
    std::string directory = args.GetString(1);
    AutoPtr<AsyncJob> job = args.GetObject(2).cast<AsyncJob>();
    KMethodRef callback = 0;
    if (args.size() > 3)
    {
        callback = args.GetMethod(3);
    }

    std::ifstream stream(UTF8ToSystem(zipFile).c_str(), std::ios::binary);
    Poco::Zip::Decompress decompressor(stream, directory);
    try
    {
        decompressor.decompressAllFiles();
    }
    catch (std::exception& e)
    {
        Logger::Get("Codec")->Error("exception decompressing: %s", e.what());
        throw ValueException::FromFormat("Exception during extraction: %s", e.what());
    }

    stream.close();

    if (!callback.isNull())
    {
        ValueList args;
        args.push_back(Value::NewString(directory));
        RunOnMainThread(callback, args, true);
    }

    return Value::Undefined;
}
	void HTTPServerBinding::Bind(const ValueList& args, SharedValue result)
	{
		Close();
		
		// port, callback
		// port, ipaddress, callback
		int port = args.at(0)->ToInt();
		std::string ipaddress = "127.0.0.1";
		
		if (args.at(1)->IsString())
		{
			ipaddress = args.at(1)->ToString();
		}
		else if (args.at(1)->IsMethod())
		{
			callback = args.at(1)->ToMethod();
		}
		if (args.size()==3)
		{
			callback = args.at(2)->ToMethod();
		}
		
		Poco::Net::SocketAddress addr(ipaddress,port);
		this->socket = new Poco::Net::ServerSocket(addr);		
		
		connection = new Poco::Net::HTTPServer(new HttpServerRequestFactory(host,callback), *socket, new Poco::Net::HTTPServerParams);
		connection->start();
	}
Example #24
0
	void Process::_SetEnvironment(const ValueList& args, KValueRef result)
	{
		if (args.size() >= 2 && args.at(0)->IsString() && args.at(1)->IsString())
		{
			SetEnvironment(args.at(0)->ToString(), args.at(1)->ToString());
		}
	}
Example #25
0
void Codec::ExtractZip(const ValueList& args, KValueRef result)
{
    args.VerifyException("extractZip", "s|o s|o ?m");

    std::string zipFile = GetPathFromValue(args.at(0));
    std::string directory = GetPathFromValue(args.at(1));

    if (zipFile.size() <= 0)
    {
        throw ValueException::FromString("Error: Zip file name in extractZip is empty");
    }
    if (zipFile.size() <= 0)
    {
        throw ValueException::FromString("Error: Destination directory name in extractZip is empty");
    }

    KMethodRef extractAsyncMethod = new KFunctionPtrMethod(&Codec::ExtractZipAsync);
    ValueList extractArgs;
    extractArgs.push_back(Value::NewString(zipFile));
    extractArgs.push_back(Value::NewString(directory));

    AutoPtr<AsyncJob> extractJob = new AsyncJob(extractAsyncMethod);
    extractArgs.push_back(Value::NewObject(extractJob));
    if (args.size() > 2)
    {
        extractArgs.push_back(args.at(2));
    }

    extractJob->SetArguments(extractArgs);
    extractJob->RunAsynchronously();
    result->SetObject(extractJob);
}
	void FilesystemBinding::ResolveFileName(const ValueList& args, std::string& filename)
	{
		if (args.at(0)->IsList())
		{
			// you can pass in an array of parts to join
			KListRef list = args.at(0)->ToList();
			for (size_t c = 0; c < list->Size(); c++)
			{
				std::string arg = list->At(c)->ToString();
				filename = kroll::FileUtils::Join(filename.c_str(), arg.c_str(), NULL);
			}
		}
		else
		{
			// you can pass in vararg of strings which acts like  a join
			for (size_t c = 0; c < args.size(); c++)
			{
				std::string arg = FileSystemUtils::GetFileName(args.at(c))->c_str();
				filename = kroll::FileUtils::Join(filename.c_str(), arg.c_str(), NULL);
			}
		}
		if (filename.empty())
		{
			throw ValueException::FromString("invalid file type");
		}
	}
Example #27
0
Value FindString(Environment &env, const char *str, const char *sub, int start,
				 bool ignoreCaseFlag, bool reverseFlag, bool listFlag)
{
	do {
		int len = static_cast<int>(::strlen(str));
		if (start < 0) {
			start += len;
			if (start < 0) start = 0;
		}
		if (start > len) return Value::Nil;
	} while (0);
	if (reverseFlag) {
		const char *p = FindString(str + start, sub, ignoreCaseFlag);
		if (listFlag) {
			ValueList valListOrg;
			for ( ; p != nullptr; p = FindString(p + 1, sub, ignoreCaseFlag)) {
				valListOrg.push_back(Value(static_cast<Number>(p - str)));
			}
			Value result;
			Object_list *pObjList = result.InitAsList(env);
			pObjList->Reserve(valListOrg.size());
			foreach_reverse (ValueList, pValue, valListOrg) {
				pObjList->AddFast(*pValue);
			}
			pObjList->SetValueType(VTYPE_number);
			return result;
		} else {
Example #28
0
void UserWindow::_OpenSaveAsDialog(const ValueList& args, SharedValue result)
{
	args.VerifyException("openFolderChooserDialog", "m,o?");
	SharedKMethod callback = args.at(0)->ToMethod();
	bool multiple = false;
	std::string path;
	std::string defaultName;
	std::string title = "Save File";
	std::vector<std::string> types;
	std::string typesDescription;

	SharedKObject props;
	if (args.size() > 1)
	{
		SharedKObject props = args.at(1)->ToObject();
		ReadChooserDialogObject(props,
			multiple,
			title,
			path,
			defaultName,
			types,
			typesDescription);
	}
	this->OpenSaveAsDialog(
		callback, title, path, defaultName, types, typesDescription);
}
Example #29
0
	void Bytes::_Concat(const ValueList& args, KValueRef result)
	{
		std::vector<BytesRef> bytes;
		bytes.push_back(BytesRef(this, true));

		for (size_t i = 0; i < args.size(); i++)
		{
			if (args.at(i)->IsObject())
			{
				BytesRef bytesObject(args.GetObject(i).cast<Bytes>());
				if (!bytesObject.isNull());
				{
					bytes.push_back(bytesObject);
				}
			}
			else if (args.at(i)->IsString())
			{
				std::string str(args.GetString(i));
				bytes.push_back(new Bytes(str));
			}
		}

		BytesRef newBytes = Bytes::Concat(bytes);
		result->SetObject(newBytes);
	}
	void TCPSocketBinding::Connect(const ValueList& args, SharedValue result)
	{
		int timeout = 10;
		if (args.size() > 0)
		{
			timeout = args.at(0)->ToInt();
		}
		std::string eprefix = "Connect exception: ";
		if (this->opened)
		{
			throw ValueException::FromString(eprefix + "Socket is already open");
		}
		try
		{
			SocketAddress a(this->host.c_str(),this->port);
			this->reactor.setTimeout(Poco::Timespan(timeout, 0));
			this->socket.connectNB(a);
			this->thread.start(this->reactor);
			this->opened = true;
			result->SetBool(true);
		}
		catch(Poco::IOException &e)
		{
			throw ValueException::FromString(eprefix + e.displayText());
		}
		catch(std::exception &e)
		{
			throw ValueException::FromString(eprefix + e.what());
		}
		catch(...)
		{
			throw ValueException::FromString(eprefix + "Unknown exception");
		}
	}