Esempio n. 1
0
        public static void CheckReturnValue(MethodInfo method, JSExpression returnValue, TypeSystem typeSystem)
        {
            if (method == null)
            {
                return;
            }

            var resultType          = returnValue.GetActualType(typeSystem);
            var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);

            var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");

            if (returnValueAttribute != null)
            {
                if (!resultIsPackedArray)
                {
                    throw new ArgumentException(
                              "Return value of method '" + method.Name + "' must be a packed array."
                              );
                }
            }
            else
            {
                if (resultIsPackedArray)
                {
                    throw new ArgumentException(
                              "Return value of method '" + method.Name + "' is a packed array. " +
                              "For this to be valid you must attach a JSPackedArrayReturnValueAttribute to the method."
                              );
                }
            }
        }
Esempio n. 2
0
        public static JSExpression FilterInvocationResult(
            MethodReference methodReference, MethodInfo method,
            JSExpression result,
            ITypeInfoSource typeInfo, TypeSystem typeSystem
            )
        {
            if (method == null)
            {
                return(result);
            }

            var resultType           = result.GetActualType(typeSystem);
            var resultIsPackedArray  = PackedArrayUtil.IsPackedArrayType(resultType);
            var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");

            if (returnValueAttribute != null)
            {
                if (TypeUtil.IsOpenType(resultType))
                {
                    // FIXME: We need to restrict substitution to when the result type is a generic parameter owned by the invocation...
                    resultType = JSExpression.SubstituteTypeArgs(typeInfo, resultType, methodReference);
                }

                if (!resultIsPackedArray)
                {
                    return(JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem));
                }
            }

            return(result);
        }