bool ASObject::hasPropertyByMultiname(const multiname& name, bool considerDynamic) { //We look in all the object's levels uint32_t validTraits=DECLARED_TRAIT; if(considerDynamic) validTraits|=DYNAMIC_TRAIT; if(Variables.findObjVar(name, NO_CREATE_TRAIT, validTraits)!=NULL) return true; if(classdef && classdef->Variables.findObjVar(name, NO_CREATE_TRAIT, BORROWED_TRAIT)!=NULL) return true; //Check prototype inheritance chain if(getClass()) { ASObject* proto = getClass()->prototype.getPtr(); while(proto) { if(proto->findGettable(name, false) != NULL) return true; proto = proto->getprop_prototype(); } } //Must not ask for non borrowed traits as static class member are not valid return false; }
_NR<ASObject> ASObject::getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt, Class_base* cls) { check(); assert(!cls || classdef->isSubClass(cls)); //Get from the current object without considering borrowed properties variable* obj=findGettable(name, false); if(!obj && cls) { //Look for borrowed traits before obj=cls->findGettable(name,true); } if(!obj && cls) { //Check prototype chain ASObject* proto = cls->prototype.getPtr(); while(proto) { obj = proto->findGettable(name, false); if(obj) { obj->var->incRef(); return _MNR(obj->var); } proto = proto->getprop_prototype(); } } if(!obj) return NullRef; if(obj->getter) { //Call the getter ASObject* target=this; if(target->classdef) { LOG(LOG_CALLS,_("Calling the getter on type ") << target->classdef->class_name); } else { LOG(LOG_CALLS,_("Calling the getter")); } IFunction* getter=obj->getter; target->incRef(); ASObject* ret=getter->call(target,NULL,0); LOG(LOG_CALLS,_("End of getter")); // No incRef because ret is a new instance return _MNR(ret); } else { assert_and_throw(!obj->setter); assert_and_throw(obj->var); if(obj->var->getObjectType()==T_FUNCTION && obj->var->as<IFunction>()->isMethod()) { LOG(LOG_CALLS,"Attaching this " << this << " to function " << name); //the obj reference is acquired by the smart reference this->incRef(); IFunction* f=obj->var->as<IFunction>()->bind(_MR(this),-1); //No incref is needed, as the function is a new instance return _MNR(f); } obj->var->incRef(); return _MNR(obj->var); } }