Exemplo n.º 1
0
        internal static string AddOperator(ScriptProcessor processor, SObject left, SObject right)
        {
            if (left is SString || right is SString)
            {
                var leftAsString = left as SString;
                var strLeft      = leftAsString != null ? leftAsString.Value : left.ToString(processor).Value;

                var rightAsString = right as SString;
                var strRight      = rightAsString != null ? rightAsString.Value : right.ToString(processor).Value;

                return("\"" + strLeft + strRight + "\"");
            }

            var numbers = GetNumericOperatorParameters(processor, left, right);

            return(SNumber.ConvertToScriptString(numbers.Item1 + numbers.Item2));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        internal override void SetMember(ScriptProcessor processor, SObject accessor, bool isIndexer, SObject value)
        {
            if (isIndexer)
            {
                if (Prototype.GetIndexerSetFunction() != IndexerSetFunction)
                {
                    IndexerSetFunction = Prototype.GetIndexerSetFunction();
                }
            }

            if (isIndexer && accessor.TypeOf() == LiteralTypeNumber && IndexerSetFunction != null)
            {
                IndexerSetFunction.Call(processor, this, this, new[] { accessor, value });
            }
            else
            {
                var accessorAsString = accessor as SString;
                var memberName       = accessorAsString != null ? accessorAsString.Value : accessor.ToString(processor).Value;

                if (Members.ContainsKey(PropertySetPrefix + memberName)) // setter property
                {
                    ((SFunction)Members[PropertySetPrefix + memberName].Data).Call(processor, this, this, new[] { value });
                }
                if (Members.ContainsKey(memberName))
                {
                    Members[memberName].Data = value;
                }
                else if (Prototype != null && Prototype.HasMember(processor, memberName) && !Prototype.IsStaticMember(memberName))
                {
                    // This is the case when new members got added to the prototype, and we haven't copied them over to the instance yet.
                    // So we do that now, and then set the value of that member:
                    AddMember(memberName, value);
                }
                else
                {
                    SuperClass?.SetMember(processor, accessor, isIndexer, value);
                }
            }
        }