Пример #1
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     if (Value)
         return processor.CreateNumber(1);
     else
         return processor.CreateNumber(0);
 }
Пример #2
0
        internal override SNumber ToNumber(ScriptProcessor processor)
        {
            if (Value.Trim() == "")
            {
                return(processor.CreateNumber(0));
            }
            double dblResult;

            return(processor.CreateNumber(double.TryParse(Value, out dblResult) ? dblResult : double.NaN));
        }
Пример #3
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     if (Value)
     {
         return(processor.CreateNumber(1));
     }
     else
     {
         return(processor.CreateNumber(0));
     }
 }
Пример #4
0
        /// <summary>
        /// Multiplies an object with -1.
        /// </summary>
        internal static SObject NegateNumber(ScriptProcessor processor, SObject obj)
        {
            var sNumber = obj as SNumber;
            var number  = sNumber?.Value ?? obj.ToNumber(processor).Value;

            return(processor.CreateNumber(number * -1));
        }
Пример #5
0
        public static SObject LastIndexOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                var str    = (SString)instance;
                var search = (SString)parameters[0];

                if (!str.Value.Contains(search.Value) || search.Value == "")
                {
                    return(processor.CreateNumber(-1));
                }

                return(processor.CreateNumber(str.Value.LastIndexOf(search.Value, StringComparison.Ordinal)));
            }

            return(processor.Undefined);
        }
Пример #6
0
        public static SObject IndexOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                var str    = instance as SString;
                var search = parameters[0] as SString;

                if (!str.Value.Contains(search.Value) || search.Value == "")
                {
                    return(processor.CreateNumber(-1));
                }

                return(processor.CreateNumber(str.Value.IndexOf(search.Value)));
            }

            return(processor.Undefined);
        }
Пример #7
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     if (Value.Trim() == "")
     {
         return(processor.CreateNumber(0));
     }
     else
     {
         var dblResult = 0D;
         if (double.TryParse(Value, out dblResult))
         {
             return(processor.CreateNumber(dblResult));
         }
         else
         {
             return(processor.CreateNumber(double.NaN));
         }
     }
 }
Пример #8
0
        public static SObject Count(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                var arr = (SArray)instance;
                return(processor.CreateNumber(arr.ArrayMembers.Length));
            }

            if (parameters.Length >= 1)
            {
                var arr      = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var result = arr.ArrayMembers.Count(m => ((SBool)comparer.Call(processor, This, This, new[] { m })).Value);
                return(processor.CreateNumber(result));
            }

            return(processor.Undefined);
        }
Пример #9
0
        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SError)instance;

            if (parameters.Length > 0)
            {
                SString message;

                if (parameters[0] is SString)
                    message = (SString)parameters[0];
                else
                    message = parameters[0].ToString(processor);

                obj.Members[MEMBER_NAME_MESSAGE].Data = message;
            }

            if (parameters.Length > 1)
            {
                SString errorType;

                if (parameters[1] is SString)
                    errorType = (SString)parameters[1];
                else
                    errorType = parameters[1].ToString(processor);

                obj.Members[MEMBER_NAME_TYPE].Data = errorType;
            }
            else
            {
                obj.Members[MEMBER_NAME_TYPE].Data = processor.CreateString("UserError");
            }

            if (parameters.Length > 2)
            {
                SNumber errorLine;

                if (parameters[2] is SNumber)
                    errorLine = (SNumber)parameters[2];
                else
                    errorLine = parameters[2].ToNumber(processor);

                obj.Members[MEMBER_NAME_LINE].Data = errorLine;
            }
            else
            {
                obj.Members[MEMBER_NAME_LINE].Data = processor.CreateNumber(-1);
            }

            return obj;
        }
Пример #10
0
        /// <summary>
        /// Multiplies an object with -1.
        /// </summary>
        internal static SObject NegateNumber(ScriptProcessor processor, SObject obj)
        {
            double number;

            if (obj is SNumber)
            {
                number = ((SNumber)obj).Value;
            }
            else
            {
                number = obj.ToNumber(processor).Value;
            }

            return(processor.CreateNumber(number * -1));
        }
Пример #11
0
        internal static string IncrementOperator(ScriptProcessor processor, SObject obj)
        {
            // Only variables can be incremented:

            var variable = obj as SVariable;

            if (variable != null)
            {
                var svar = variable;
                svar.Data = processor.CreateNumber(svar.Data.ToNumber(processor).Value + 1D);
                return(svar.Identifier);
            }
            processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxInvalidIncrement);
            return("");
        }
Пример #12
0
        internal static string DecrementOperator(ScriptProcessor processor, SObject obj)
        {
            // Only variables can be decremented:

            if (obj is SVariable)
            {
                var svar = (SVariable)obj;
                svar.Data = processor.CreateNumber(svar.Data.ToNumber(processor).Value - 1D);
                return(svar.Identifier);
            }
            else
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_INVALID_DECREMENT);
                return("");
            }
        }
Пример #13
0
        private static SObject ConstructorImpl(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SError)instance;

            if (parameters.Length > 0)
            {
                var stringParameter = parameters[0] as SString;
                var message         = stringParameter ?? parameters[0].ToString(processor);

                obj.Members[MemberNameMessage].Data = message;
            }

            if (parameters.Length > 1)
            {
                var stringParameter = parameters[1] as SString;
                var errorType       = stringParameter ?? parameters[1].ToString(processor);

                obj.Members[MemberNameType].Data = errorType;
            }
            else
            {
                obj.Members[MemberNameType].Data = processor.CreateString("UserError");
            }

            if (parameters.Length > 2)
            {
                var line      = parameters[2] as SNumber;
                var errorLine = line ?? parameters[2].ToNumber(processor);

                obj.Members[MemberNameLine].Data = errorLine;
            }
            else
            {
                obj.Members[MemberNameLine].Data = processor.CreateNumber(-1);
            }

            return(obj);
        }
Пример #14
0
        public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var str = instance as SString;

            return processor.CreateNumber(str.Value.Length);
        }
Пример #15
0
        public static SObject Where(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length >= 1)
            {
                var arr      = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var results = arr.ArrayMembers.Where((m, i) => ((SBool)comparer.Call(processor, This, This, new[] { m, processor.CreateNumber(i) })).Value);
                return(processor.CreateArray(results.ToArray()));
            }

            return(processor.Undefined);
        }
Пример #16
0
        /// <summary>
        /// Multiplies an object with -1.
        /// </summary>
        internal static SObject NegateNumber(ScriptProcessor processor, SObject obj)
        {
            double number;
            if (obj is SNumber)
                number = ((SNumber)obj).Value;
            else
                number = obj.ToNumber(processor).Value;

            return processor.CreateNumber(number * -1);
        }
Пример #17
0
        internal static string DecrementOperator(ScriptProcessor processor, SObject obj)
        {
            // Only variables can be decremented:

            if (obj is SVariable)
            {
                var svar = (SVariable)obj;
                svar.Data = processor.CreateNumber(svar.Data.ToNumber(processor).Value - 1D);
                return svar.Identifier;
            }
            else
            {
                processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_INVALID_DECREMENT);
                return "";
            }
        }
Пример #18
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     if (Value.Trim() == "")
     {
         return processor.CreateNumber(0);
     }
     else
     {
         var dblResult = 0D;
         if (double.TryParse(Value, out dblResult))
         {
             return processor.CreateNumber(dblResult);
         }
         else
         {
             return processor.CreateNumber(double.NaN);
         }
     }
 }
Пример #19
0
        public static SObject Where(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length >= 1)
            {
                var arr = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var results = arr.ArrayMembers.Where((m, i) => ((SBool)comparer.Call(processor, This, This, new[] {m, processor.CreateNumber(i)})).Value);
                return processor.CreateArray(results.ToArray());
            }

            return processor.Undefined;
        }
Пример #20
0
 /// <summary>
 /// Returns the number representation of this object.
 /// </summary>
 internal virtual SNumber ToNumber(ScriptProcessor processor)
 {
     return(processor.CreateNumber(double.NaN));
 }
Пример #21
0
        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SError)instance;

            if (parameters.Length > 0)
            {
                SString message;

                if (parameters[0] is SString)
                {
                    message = (SString)parameters[0];
                }
                else
                {
                    message = parameters[0].ToString(processor);
                }

                obj.Members[MEMBER_NAME_MESSAGE].Data = message;
            }

            if (parameters.Length > 1)
            {
                SString errorType;

                if (parameters[1] is SString)
                {
                    errorType = (SString)parameters[1];
                }
                else
                {
                    errorType = parameters[1].ToString(processor);
                }

                obj.Members[MEMBER_NAME_TYPE].Data = errorType;
            }
            else
            {
                obj.Members[MEMBER_NAME_TYPE].Data = processor.CreateString("UserError");
            }

            if (parameters.Length > 2)
            {
                SNumber errorLine;

                if (parameters[2] is SNumber)
                {
                    errorLine = (SNumber)parameters[2];
                }
                else
                {
                    errorLine = parameters[2].ToNumber(processor);
                }

                obj.Members[MEMBER_NAME_LINE].Data = errorLine;
            }
            else
            {
                obj.Members[MEMBER_NAME_LINE].Data = processor.CreateNumber(-1);
            }

            return(obj);
        }
Пример #22
0
        public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var str = instance as SString;

            return(processor.CreateNumber(str.Value.Length));
        }
Пример #23
0
        public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var arr = (SArray)instance;

            return(processor.CreateNumber(arr.ArrayMembers.Length));
        }
Пример #24
0
        public static SObject LastIndexOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                var str = instance as SString;
                var search = parameters[0] as SString;

                if (!str.Value.Contains(search.Value) || search.Value == "")
                    return processor.CreateNumber(-1);

                return processor.CreateNumber(str.Value.LastIndexOf(search.Value));
            }

            return processor.Undefined;
        }
Пример #25
0
 /// <summary>
 /// Updates the "length" property of this object.
 /// </summary>
 public void UpdateLength(ScriptProcessor processor)
 {
     //TODO: Add length to prototype
     Members["length"] = new SVariable("length", processor.CreateNumber(ArrayMembers.Length)) { IsReadOnly = true };
 }
Пример #26
0
 private static SObject TranslateNumber(ScriptProcessor processor, double dblIn)
 {
     return processor.CreateNumber(dblIn);
 }
Пример #27
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     return processor.CreateNumber(Value);
 }
Пример #28
0
 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     return(processor.CreateNumber(Value));
 }
Пример #29
0
        public static SObject Count(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                var arr = (SArray)instance;
                return processor.CreateNumber(arr.ArrayMembers.Length);
            }

            if (parameters.Length >= 1)
            {
                var arr = (SArray)instance;
                var comparer = (SFunction)Unbox(parameters[0]);

                var result = arr.ArrayMembers.Count(m => ((SBool)comparer.Call(processor, This, This, new[] { m })).Value);
                return processor.CreateNumber(result);
            }

            return processor.Undefined;
        }
Пример #30
0
 public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     return(processor.CreateNumber(((SString)instance).Value.Length));
 }
Пример #31
0
        /// <summary>
        /// Sets the value and updates the length property.
        /// </summary>
        internal void SetValue(ScriptProcessor processor, string value)
        {
            Value = value;

            var length = processor.CreateNumber(value.Length);

            //TODO: add length to prototype.
            Members[STRING_LENGTH_PROPERTY_NAME].ForceSetData(length);
        }
Пример #32
0
 public static SObject Length(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     var arr = (SArray)instance;
     return processor.CreateNumber(arr.ArrayMembers.Length);
 }
Пример #33
0
 private static SObject TranslateNumber(ScriptProcessor processor, double dblIn)
 {
     return(processor.CreateNumber(dblIn));
 }
Пример #34
0
 /// <summary>
 /// Returns the number representation of this object.
 /// </summary>
 internal virtual SNumber ToNumber(ScriptProcessor processor)
 {
     return processor.CreateNumber(double.NaN);
 }