Esempio n. 1
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                JsArray array = Global.ArrayClass.New();

                for (int i = 0; i < parameters.Length; i++)
                {
                    array[i.ToString()] = parameters[i];
                }

                visitor.Return(array);
            }
            else
            {
                // When called as part of a new expression, it is a constructor: it initialises the newly created object.
                for (int i = 0; i < parameters.Length; i++)
                {
                    that[i.ToString()] = parameters[i];
                }

                visitor.Return(that);
            }

            return that;
        }
Esempio n. 2
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                // 15.5.1 - When String is called as a function rather than as a constructor, it performs a type conversion.
                if (parameters.Length > 0)
                {
                    return visitor.Return(Global.StringClass.New(parameters[0].ToString()));
                }
                else
                {
                    return visitor.Return(Global.StringClass.New(String.Empty));
                }
            }
            else
            {
                // 15.5.2 - When String is called as part of a new expression, it is a constructor: it initialises the newly created object.
                if (parameters.Length > 0)
                {
                    that.Value = parameters[0].ToString();
                }
                else
                {
                    that.Value = String.Empty;
                }

                return visitor.Return(that);
            }
        }
Esempio n. 3
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (that == null)
            {
                // 15.7.1 - When Number is called as a function rather than as a constructor, it performs a type conversion.
                if (parameters.Length > 0)
                {
                    return visitor.Return(new JsNumber(parameters[0].ToNumber()));
                }
                else
                {
                    return visitor.Return(new JsNumber(0));
                }
            }
            else
            {
                // 15.7.2 - When Number is called as part of a new expression, it is a constructor: it initialises the newly created object.
                if (parameters.Length > 0)
                {
                    that.Value = parameters[0].ToNumber();
                }
                else
                {
                    that.Value = 0;
                }

                visitor.Return(that);
            }

            return that;
        }
Esempio n. 4
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (parameters.Length == 0) {
                return visitor.Return(New());
                //throw new ArgumentNullException("pattern");
            }

            return visitor.Return(New(parameters[0].ToString(), false, false, false));
        }
Esempio n. 5
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) {
            if (that == null || (that as IGlobal) == visitor.Global ) {
                return visitor.Return(Construct(parameters,null,visitor));
            }
            else {
                // When called as part of a new expression, it is a constructor: it initialises the newly created object.
                for (int i = 0; i < parameters.Length; i++) {
                    that[i.ToString()] = parameters[i];
                }

                return visitor.Return(that);
            }
        }
Esempio n. 6
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            int clrParameterCount = Delegate.Method.GetParameters().Length;
            object[] clrParameters = new object[clrParameterCount];

            for (int i = 0; i < parameters.Length; i++) {
                // First see if either the JsInstance or it's value can be directly accepted without converstion
                if (typeof(JsInstance).IsAssignableFrom(Parameters[i].ParameterType) && Parameters[i].ParameterType.IsInstanceOfType(parameters[i])) {
                    clrParameters[i] = parameters[i];
                }
                else if (Parameters[i].ParameterType.IsInstanceOfType(parameters[i].Value)) {
                    clrParameters[i] = parameters[i].Value;
                }
                else {
                    clrParameters[i] = visitor.Global.Marshaller.MarshalJsValue<object>(parameters[i]);
                }
            }

            object result;

            try {
                result = Delegate.DynamicInvoke(clrParameters);
            }
            catch (TargetInvocationException e) {
                throw e.InnerException;
            }
            catch (Exception e) {
                if (e.InnerException is JsException) {
                    throw e.InnerException;
                }

                throw;
            }

            if (result != null) {
                // Don't wrap if the result should be a JsInstance
                if (typeof(JsInstance).IsInstanceOfType(result)) {
                    visitor.Return((JsInstance)result);
                }
                else {
                    visitor.Return(visitor.Global.WrapClr(result));
                }
            }
            else {
                visitor.Return(JsUndefined.Instance);
            }

            return null;
        }
Esempio n. 7
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) {
            if (that == null || (that as IGlobal) == visitor.Global)
            {
                visitor.Return(parameters.Length > 0 ? New(parameters[0].ToString()) : New());
            }
            else {
                if (parameters.Length > 0) {
                    that.Value = parameters[0].ToString();
                }
                else {
                    that.Value = String.Empty;
                }

                visitor.Return(that);
            }

            return that;
        }
Esempio n. 8
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (parameters.Length == 0) {
                return visitor.Return(New());
                //throw new ArgumentNullException("pattern");
            }

            bool g = false, m = false, ic = false;

            if (parameters.Length == 2) {
                string strParam = parameters[1].ToString();
                if (strParam != null) {
                    m = strParam.Contains("m");
                    ic = strParam.Contains("i");
                    g = strParam.Contains("g");
                }
            }

            return visitor.Return(New(parameters[0].ToString(), g, ic, m));
        }
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) {
            // e.g., var foo = Boolean(true);
            if (that == null || (that as IGlobal) == visitor.Global)
            {
                visitor.Return(parameters.Length > 0 ? new JsBoolean(parameters[0].ToBoolean(), PrototypeProperty) : new JsBoolean(PrototypeProperty));
            }
            else // e.g., var foo = new Boolean(true);
            {
                if (parameters.Length > 0) {
                    that.Value = parameters[0].ToBoolean();
                }
                else {
                    that.Value = false;
                }

                visitor.Return(that);
            }

            return that;
        }
Esempio n. 10
0
 public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters, Type[] genericArguments)
 {
     if (m_generics.Count == 0 && (genericArguments != null && genericArguments.Length > 0))
         return base.Execute(visitor, that, parameters, genericArguments);
     else
     {
         JsMethodImpl impl = m_overloads.ResolveOverload(parameters, genericArguments);
         if (impl == null)
             throw new JintException(String.Format("No matching overload found {0}<{1}>", Name, genericArguments));
         visitor.Return(impl(visitor.Global, that, parameters));
         return that;
     }
 }
Esempio n. 11
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) {
            try {
                //visitor.CurrentScope["this"] = visitor.Global;
                JsInstance result = Delegate( parameters );
                visitor.Return(result == null ? JsUndefined.Instance : result);

                return that;
            }
            catch (Exception e) {
                if (e.InnerException is JsException) {
                    throw e.InnerException;
                }

                throw;
            }
        }
Esempio n. 12
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            try {
                //visitor.CurrentScope["this"] = visitor.Global;
                JsInstance result = Delegate(parameters);
                visitor.Return(result == null ? JsUndefined.Instance : result);

                return(that);
            }
            catch (Exception e) {
                if (e.InnerException is JsException)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }
Esempio n. 13
0
        public override JsInstance Execute(
            IJintVisitor visitor,
            JsDictionaryObject that,
            JsInstance[] parameters,
            Type[] genericArguments)
        {
            if (this.m_generics.Count == 0 && (genericArguments != null && (uint)genericArguments.Length > 0U))
            {
                return(base.Execute(visitor, that, parameters, genericArguments));
            }
            JsMethodImpl jsMethodImpl = this.m_overloads.ResolveOverload(parameters, genericArguments);

            if (jsMethodImpl == null)
            {
                throw new JintException(string.Format("No matching overload found {0}<{1}>", (object)this.Name, (object)genericArguments));
            }
            visitor.Return(jsMethodImpl(visitor.Global, (JsInstance)that, parameters));
            return((JsInstance)that);
        }
Esempio n. 14
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            try
            {
                JsInstance result;

                switch (argLen)
                {
                case 0:
                    result = impl.DynamicInvoke() as JsInstance;
                    break;

                case 1:
                    result = impl.DynamicInvoke(parameters[0].Value) as JsInstance;
                    break;

                case 2:
                    result = impl.DynamicInvoke(parameters[0].Value, parameters[1].Value) as JsInstance;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("argLen");
                }

                visitor.Return(result);
                return(result);
            }
            catch (ArgumentException)
            {
                var constructor = that["constructor"] as JsFunction;
                throw new JsException(visitor.Global.TypeErrorClass.New("incompatible type: " + constructor == null ? "<unknown>" : constructor.Name));
            }
            catch (Exception e)
            {
                if (e.InnerException is JsException)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }
Esempio n. 15
0
 public override JsInstance Execute(
     IJintVisitor visitor,
     JsDictionaryObject that,
     JsInstance[] parameters)
 {
     try
     {
         JsInstance jsInstance = this.Delegate(parameters);
         visitor.Return(jsInstance == null ? (JsInstance)JsUndefined.Instance : jsInstance);
         return((JsInstance)that);
     }
     catch (Exception ex)
     {
         if (ex.InnerException is JsException)
         {
             throw ex.InnerException;
         }
         throw;
     }
 }
Esempio n. 16
0
		public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
		{
			try
			{
				JsInstance result;

				switch (argLen)
				{
					case 0:
						result = impl.DynamicInvoke() as JsInstance;
						break;
					case 1:
						result = impl.DynamicInvoke(parameters[0].Value) as JsInstance;
						break;
					case 2:
						result = impl.DynamicInvoke(parameters[0].Value, parameters[1].Value) as JsInstance;
						break;
					default:
						throw new ArgumentOutOfRangeException("argLen");
				}
				
				visitor.Return(result);
				return result;
			}
			catch (ArgumentException)
			{
				var constructor = that["constructor"] as JsFunction;
				throw new JsException(visitor.Global.TypeErrorClass.New("incompatible type: " + constructor == null ? "<unknown>" : constructor.Name));
			}
			catch (Exception e)
			{
				if (e.InnerException is JsException)
				{
					throw e.InnerException;
				}

				throw;
			}
		}
Esempio n. 17
0
 public override JsInstance Execute(
     IJintVisitor visitor,
     JsDictionaryObject that,
     JsInstance[] parameters)
 {
     try
     {
         JsInstance result;
         if (this.hasParameters)
         {
             result = this.impl.DynamicInvoke((object)that, (object)parameters) as JsInstance;
         }
         else
         {
             result = this.impl.DynamicInvoke((object)that) as JsInstance;
         }
         visitor.Return(result);
         return(result);
     }
     catch (TargetInvocationException ex)
     {
         throw ex.InnerException;
     }
     catch (ArgumentException ex)
     {
         JsFunction jsFunction = that["constructor"] as JsFunction;
         throw new JsException((JsInstance)visitor.Global.TypeErrorClass.New("incompatible type: " + (object)jsFunction == null ? "<unknown>" : jsFunction.Name));
     }
     catch (Exception ex)
     {
         if (ex.InnerException is JsException)
         {
             throw ex.InnerException;
         }
         throw;
     }
 }
Esempio n. 18
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            try
            {
                JsInstance result;
                if (hasParameters)
                {
                    result = impl.DynamicInvoke(new object[] { that, parameters }) as JsInstance;
                }
                else
                {
                    result = impl.DynamicInvoke(new object[] { that }) as JsInstance;
                }

                visitor.Return(result);
                return(result);
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
            catch (ArgumentException e)
            {
                var constructor = that.Prototype["constructor"] as JsFunction;
                throw new JsException(visitor.Global.TypeErrorClass.New("incompatible type: " + constructor == null ? "" : constructor.Name));
            }
            catch (Exception e)
            {
                if (e.InnerException is JsException)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }
Esempio n. 19
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            int clrParameterCount = Delegate.Method.GetParameters().Length;
            object[] clrParameters = new object[clrParameterCount];

            for (int i = 0; i < parameters.Length; i++) {
                // First see if either the JsInstance or it's value can be directly accepted without converstion
                if (typeof(JsInstance).IsAssignableFrom(Parameters[i].ParameterType) && Parameters[i].ParameterType.IsInstanceOfType(parameters[i])) {
                    clrParameters[i] = parameters[i];
                }
                else if (Parameters[i].ParameterType.IsInstanceOfType(parameters[i].Value)) {
                    clrParameters[i] = parameters[i].Value;
                }
                else {
                    clrParameters[i] = visitor.Global.Marshaller.MarshalJsValue<object>(parameters[i]);
                }
            }

            object result;

            try {
                result = Delegate.DynamicInvoke(clrParameters);
            }
            catch (TargetInvocationException e) {
                throw e.InnerException;
            }
            catch (Exception e) {
                if (e.InnerException is JsException) {
                    throw e.InnerException;
                }

                throw;
            }

            if (result != null) {
                // Don't wrap if the result should be a JsInstance
                if (typeof(JsInstance).IsInstanceOfType(result)) {
                    visitor.Return((JsInstance)result);
                }
                else {
                    TypeCode t = System.Type.GetTypeCode(result.GetType());
                    switch (t) {
                    case TypeCode.Boolean:
                        visitor.Return(
                            visitor.Global.BooleanClass.New((bool)result));
                        break;

                    case TypeCode.Char:
                    case TypeCode.String:
                    case TypeCode.Object:
                        visitor.Return(
                            visitor.Global.StringClass.New(result.ToString()));
                        break;

                    case TypeCode.DateTime:
                        visitor.Return(
                            visitor.Global.DateClass.New((DateTime)result));
                        break;

                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.SByte:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                    case TypeCode.Decimal:
                    case TypeCode.Double:
                    case TypeCode.Single:
                        visitor.Return(visitor.Global.NumberClass.New(
                            Convert.ToDouble(result)));
                        break;

                    case TypeCode.DBNull:
                    case TypeCode.Empty:
                        visitor.Return(JsNull.Instance);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
            else {
                visitor.Return(JsUndefined.Instance);
            }

            return null;
        }
Esempio n. 20
0
 public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
 {
     return(visitor.Return(Construct(parameters, null, visitor)));
 }
Esempio n. 21
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            JsDate result = Construct(parameters);

            if (that == null)
            {
                return visitor.Return(ToStringImpl(result, JsInstance.EMPTY));
            }

            return result;
        }
Esempio n. 22
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            int clrParameterCount = Delegate.Method.GetParameters().Length;

            object[] clrParameters = new object[clrParameterCount];

            for (int i = 0; i < parameters.Length; i++)
            {
                // First see if either the JsInstance or it's value can be directly accepted without converstion
                if (typeof(JsInstance).IsAssignableFrom(Parameters[i].ParameterType) && Parameters[i].ParameterType.IsInstanceOfType(parameters[i]))
                {
                    clrParameters[i] = parameters[i];
                }
                else if (Parameters[i].ParameterType.IsInstanceOfType(parameters[i].Value))
                {
                    clrParameters[i] = parameters[i].Value;
                }
                else
                {
                    clrParameters[i] = JsClr.ConvertParameter(parameters[i]);
                }
            }

            object result;

            try
            {
                result = Delegate.DynamicInvoke(clrParameters);
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
            catch (Exception e)
            {
                if (e.InnerException is JsException)
                {
                    throw e.InnerException;
                }

                throw;
            }

            if (result != null)
            {
                // Don't wrap if the result should be a JsInstance
                if (typeof(JsInstance).IsInstanceOfType(result))
                {
                    visitor.Return((JsInstance)result);
                }
                else
                {
                    visitor.Return(visitor.Global.WrapClr(result));
                }
            }
            else
            {
                visitor.Return(JsUndefined.Instance);
            }

            return(null);
        }
Esempio n. 23
0
        public override JsInstance Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters)
        {
            int clrParameterCount = Delegate.Method.GetParameters().Length;

            object[] clrParameters = new object[clrParameterCount];

            for (int i = 0; i < parameters.Length; i++)
            {
                // First see if either the JsInstance or it's value can be directly accepted without converstion
                if (typeof(JsInstance).IsAssignableFrom(Parameters[i].ParameterType) && Parameters[i].ParameterType.IsInstanceOfType(parameters[i]))
                {
                    clrParameters[i] = parameters[i];
                }
                else if (Parameters[i].ParameterType.IsInstanceOfType(parameters[i].Value))
                {
                    clrParameters[i] = parameters[i].Value;
                }
                else
                {
                    clrParameters[i] = visitor.Global.Marshaller.MarshalJsValue <object>(parameters[i]);
                }
            }

            object result;

            try {
                result = Delegate.DynamicInvoke(clrParameters);
            }
            catch (TargetInvocationException e) {
                throw e.InnerException;
            }
            catch (Exception e) {
                if (e.InnerException is JsException)
                {
                    throw e.InnerException;
                }

                throw;
            }

            if (result != null)
            {
                // Don't wrap if the result should be a JsInstance
                if (typeof(JsInstance).IsInstanceOfType(result))
                {
                    visitor.Return((JsInstance)result);
                }
                else
                {
                    TypeCode t = System.Type.GetTypeCode(result.GetType());
                    switch (t)
                    {
                    case TypeCode.Boolean:
                        visitor.Return(
                            visitor.Global.BooleanClass.New((bool)result));
                        break;

                    case TypeCode.Char:
                    case TypeCode.String:
                    case TypeCode.Object:
                        visitor.Return(
                            visitor.Global.StringClass.New(result.ToString()));
                        break;

                    case TypeCode.DateTime:
                        visitor.Return(
                            visitor.Global.DateClass.New((DateTime)result));
                        break;

                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.SByte:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                    case TypeCode.Decimal:
                    case TypeCode.Double:
                    case TypeCode.Single:
                        visitor.Return(visitor.Global.NumberClass.New(
                                           Convert.ToDouble(result)));
                        break;

                    case TypeCode.DBNull:
                    case TypeCode.Empty:
                        visitor.Return(JsNull.Instance);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
            else
            {
                visitor.Return(JsUndefined.Instance);
            }

            return(null);
        }