Exemplo n.º 1
0
Handle<Value> TiObject::setPropHelper(const char* propString, Local<Value> value, SET_VALUE_CALLBACK cb)
{
    TiObject* destObj = onLookupMember(propString);
    TiObject* srcObj = getTiObjectFromJsObject(value);
    if (srcObj == NULL)
    {
        srcObj = new TiObject(propString);
        srcObj->initializeTiObject(NULL);
        srcObj->setValue(value);
        setTiObjectToJsObject(value, srcObj);
    }
    if (destObj == NULL)
    {
        if ((!canAddMembers()) || (!userCanAddMember(propString)))
        {
            srcObj->release();
            return Undefined();
        }
        destObj = srcObj;
    }
    (destObj->*cb)(value);
    addMember(destObj, propString);
    onSetProperty(propString, value);
    srcObj->release();
    return value;
}
void TiProxy::setParametersFromObject(void* userContext, Local<Object> obj)
{
    HandleScope handleScope;
    Handle<Value> value;
    Handle<Value> controlValue = getValue();
    if (!controlValue->IsObject())
    {
        return;
    }
    Handle<Array> propNames = obj->GetPropertyNames();
    uint32_t props = propNames->Length();
    Local<Value> propValue;
    for (uint32_t i = 0; i < props; i++)
    {
        Handle<String> propString = Handle<String>::Cast(propNames->Get(Integer::New(i)));
        String::Utf8Value propNameUTF(propString);
        Local<Value> propValue = obj->Get(propString);
        TiObject* foundProp = onLookupMember(*propNameUTF);
        if (foundProp != NULL)
        {
            TiObject* addObj = getTiObjectFromJsObject(propValue);
            if (addObj)
            {
                TiProxy* obj = (TiProxy*) userContext;
                TiProxy* uiObj = (TiProxy*) addObj;
                NativeObject* childNO = uiObj->getNativeObject();
                NativeObject* parentNO = obj->getNativeObject();
                parentNO->addChildNativeObject(childNO);
                parentNO->release();
            }
            else
            {
                foundProp->setValue(propValue);
            }
        }
        else
        {
            // Set any custom properties onto the JS object.
            getValue()->ToObject()->ForceSet(propString, propValue);
        }
    }
}