Esempio n. 1
0
        public static SObject NameOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                return(processor.Undefined);
            }

            var parameterAsString = parameters[0] as SProtoObject;

            if (parameterAsString != null)
            {
                return(processor.CreateString(parameterAsString.IsProtoInstance ? parameterAsString.Prototype.Name : parameterAsString.TypeOf()));
            }
            return(processor.CreateString(parameters[0].TypeOf()));
        }
Esempio n. 2
0
 public static SObject ToPrimitive(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     if (parameters.Length == 0)
     {
         return(processor.Undefined);
     }
     if (parameters[0] is SString)
     {
         return(processor.CreateString(((SString)parameters[0]).Value));
     }
     if (parameters[0] is SNumber)
     {
         return(processor.CreateNumber(((SNumber)parameters[0]).Value));
     }
     if (parameters[0] is SBool)
     {
         return(processor.CreateBool(((SBool)parameters[0]).Value));
     }
     return(parameters[0]); // returns the input object, if no conversion was conducted.
 }
Esempio n. 3
0
 public static SObject TypeOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) =>
 parameters.Length == 0 ? processor.Undefined : processor.CreateString(parameters[0].TypeOf());
Esempio n. 4
0
        /// <summary>
        /// Throws an error with the given <see cref="ErrorType"/> and error message.
        /// </summary>
        public SObject ThrowError(ErrorType errorType, string message, params object[] messageArgs)
        {
            var formattedMessage = string.Format(message, messageArgs);

            var errorObject = _processor.Context.CreateInstance("Error", new SObject[] { _processor.CreateString(formattedMessage),
                                                                                         _processor.CreateString(errorType.ToString()),
                                                                                         _processor.CreateNumber(_processor.GetLineNumber()) });

            return(ThrowError(errorObject));
        }