Handle<Value> TiUIBase::_add(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; TiUIBase* obj = (TiUIBase*) userContext; if ((args.Length() > 0) && (args[0]->IsObject())) { TiObject* addObj = getTiObjectFromJsObject(args[0]); if ((addObj == NULL) || (!addObj->isUIObject())) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } TiUIBase* uiObj = (TiUIBase*) addObj; NativeObject* childNO = uiObj->getNativeObject(); if (childNO == NULL) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } NativeObject* parentNO = obj->getNativeObject(); if (N_SUCCEEDED(parentNO->addChildNativeObject(childNO))) { ObjectEntry entry = addObj; obj->childControls_.push_back(entry); obj->jsChildren_->Set(obj->jsChildren_->Length(), addObj->getValue()); } childNO->release(); parentNO->release(); } else { // TODO: expand this exception } return Undefined(); }
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); } } }