Beispiel #1
0
	void AppBinding::CreateProperties(const ValueList& args, KValueRef result)
	{
		AutoPtr<PropertiesBinding> properties = new PropertiesBinding();
		result->SetObject(properties);
		
		if (args.size() > 0 && args.at(0)->IsObject())
		{
			KObjectRef p = args.at(0)->ToObject();
			SharedStringList names = p->GetPropertyNames();
			for (size_t i = 0; i < names->size(); i++)
			{
				KValueRef 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);
			}
		}
	}
Beispiel #2
0
bool EventListener::Dispatch(KObjectRef thisObject, const ValueList& args, bool synchronous)
{
    KValueRef result = RunOnMainThread(this->callback, thisObject, args, synchronous);
    if (result->IsBool())
        return result->ToBool();
    return true;
}
Beispiel #3
0
bool KObject::GetBool(const char* name, bool defaultValue)
{
    KValueRef prop = this->Get(name);
    if (prop->IsBool())
    {
        return prop->ToBool();
    }
    else
    {
        return defaultValue;
    }
}
    void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray)
    {
        if (value->IsNull() || value->IsUndefined())
        {
            add_next_index_null(phpArray);
        }
        else if (value->IsBool())
        {
            if (value->ToBool())
                add_next_index_bool(phpArray, 1);
            else
                add_next_index_bool(phpArray, 0);
        }
        else if (value->IsNumber())
        {
            /* No way to check whether the number is an
               integer or a double here. All Kroll numbers
               are doubles, so return a double. This could
               cause some PHP to function incorrectly if it's
               doing strict type checking. */
            add_next_index_double(phpArray, value->ToNumber());
        }
        else if (value->IsString())
        {
            add_next_index_stringl(phpArray, (char *) value->ToString(), strlen(value->ToString()), 1);
        }
        else if (value->IsObject())
        {
            /*TODO: Implement*/
        }
        else if (value->IsMethod())
        {
            /*TODO: Implement*/
        }
        else if (value->IsList())
        {
            zval *phpValue;
            AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
            if (!pl.isNull())
                phpValue = pl->ToPHP();
            else
                phpValue = PHPUtils::ToPHPValue(value);

            add_next_index_zval(phpArray, phpValue);
        }
    }
Beispiel #5
0
	KObjectRef Script::FindEvaluatorWithMethod(const char *method, const char *arg)
	{
		ValueList args;
		args.push_back(Value::NewString(arg));
		
		for (size_t i = 0; i < evaluators->Size(); i++)
		{
			KMethodRef finder = evaluators->At(i)->ToObject()->GetMethod(method);
			if (!finder.isNull())
			{
				KValueRef result = finder->Call(args);
				if (result->IsBool() && result->ToBool())
				{
					return evaluators->At(i)->ToObject();
				}
			}
		}
		return 0;
	}
Beispiel #6
0
 void convert (Statement &select, KValueRef arg)
 {
     if (arg->IsString())
     {
         std::string *s = new std::string(arg->ToString()); 
         select , use(*s);
         strings.push_back(s);
     }
     else if (arg->IsInt())
     {
         int *i = new int(arg->ToInt());
         select , use(*i);
         ints.push_back(i);
     }
     else if (arg->IsDouble())
     {
         double *d = new double(arg->ToDouble());
         select , use(*d);
         doubles.push_back(d);
     }
     else if (arg->IsBool())
     {
         bool *b = new bool(arg->ToBool());
         select , use(*b);
         bools.push_back(b);
     }
     else if (arg->IsNull() || arg->IsUndefined())
     {
         // in this case, we bind a null string (dequoted)
         std::string *s = new std::string("null");
         select , use(s);
         strings.push_back(s);
     }
     else
     {
         throw ValueException::FromFormat("Unsupport type for argument: %s",
             arg->GetType().c_str());
     }
 }