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); } } }
AutoPtr<StaticBoundObject> ScopeMethodDelegate::CreateDelegate(KObjectRef global, KObjectRef bo) { AutoPtr<StaticBoundObject> scope = new StaticBoundObject(); SharedStringList keys = bo->GetPropertyNames(); StringList::iterator iter = keys->begin(); while(iter!=keys->end()) { SharedString key_ptr = (*iter++); std::string key = *key_ptr; KValueRef value = bo->Get(key.c_str()); if (key == "set") { KMethodRef d = new ScopeMethodDelegate(SET, global, scope, value->ToMethod()); KValueRef v = Value::NewMethod(d); scope->Set(key.c_str(), v); } else if (key == "get") { KMethodRef d = new ScopeMethodDelegate(GET, global, scope, value->ToMethod()); KValueRef v = Value::NewMethod(d); scope->Set(key.c_str(), v); } else { scope->Set(key.c_str(), value); } } return scope; }