Ejemplo n.º 1
0
        internal override SObject GetMember(ScriptProcessor processor, SObject accessor, bool isIndexer)
        {
            if (isIndexer && accessor.TypeOf() == LiteralTypeNumber)
            {
                if (Prototype.GetIndexerGetFunction() != IndexerGetFunction)
                {
                    IndexerGetFunction = Prototype.GetIndexerGetFunction();
                }

                return(IndexerGetFunction != null?IndexerGetFunction.Call(processor, this, this, new[] { accessor }) : processor.Undefined);
            }

            var accessorAsString = accessor as SString;
            var memberName       = accessorAsString != null ? accessorAsString.Value : accessor.ToString(processor).Value;

            if (Members.ContainsKey(PropertyGetPrefix + memberName)) // getter property
            {
                return(((SFunction)Members[PropertyGetPrefix + memberName].Data).Call(processor, this, this, new SObject[] { }));
            }
            if (Members.ContainsKey(memberName))
            {
                return(Members[memberName]);
            }
            if (Prototype != null && Prototype.HasMember(processor, memberName))
            {
                return(Prototype.GetMember(processor, accessor, isIndexer));
            }
            if (SuperClass != null)
            {
                return(SuperClass.GetMember(processor, accessor, isIndexer));
            }

            return(processor.Undefined);
        }
Ejemplo n.º 2
0
        internal override SObject GetMember(ScriptProcessor processor, SObject accessor, bool isIndexer)
        {
            if (isIndexer && accessor.TypeOf() == LITERAL_TYPE_NUMBER)
            {
                if (Prototype.GetIndexerGetFunction() != IndexerGetFunction)
                {
                    IndexerGetFunction = Prototype.GetIndexerGetFunction();
                }

                if (IndexerGetFunction != null)
                {
                    return(IndexerGetFunction.Call(processor, this, this, new SObject[] { accessor }));
                }
                else
                {
                    return(processor.Undefined);
                }
            }

            string memberName;

            if (accessor is SString)
            {
                memberName = ((SString)accessor).Value;
            }
            else
            {
                memberName = accessor.ToString(processor).Value;
            }

            if (Members.ContainsKey(PROPERTY_GET_PREFIX + memberName)) // getter property
            {
                return(((SFunction)Members[PROPERTY_GET_PREFIX + memberName].Data).Call(processor, this, this, new SObject[] { }));
            }
            else if (Members.ContainsKey(memberName))
            {
                return(Members[memberName]);
            }
            else if (Prototype != null && Prototype.HasMember(processor, memberName))
            {
                return(Prototype.GetMember(processor, accessor, isIndexer));
            }
            else if (SuperClass != null)
            {
                return(SuperClass.GetMember(processor, accessor, isIndexer));
            }

            return(processor.Undefined);
        }