public override void Set(JsDictionaryObject that, JsInstance value)
        {
            object nativeValue = JsClr.ConvertParameter(value);

            getter.GetValue(that.Value, Name, ref nativeValue).SetValue(that.Value, nativeValue);
        }
Exemple #2
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);
        }