Example #1
0
        public override void MergeInto (JSIL.Translator.Configuration result) {
            base.MergeInto(result);

            var cc = result as JSIL.Compiler.Configuration;
            if (cc == null)
                throw new ArgumentException("Result must be a Compiler.Configuration", "result");

            if (AutoLoadConfigFiles.HasValue)
                cc.AutoLoadConfigFiles = AutoLoadConfigFiles;
            if (UseLocalProxies.HasValue)
                cc.UseLocalProxies = UseLocalProxies;
            if (ReuseTypeInfoAcrossAssemblies.HasValue)
                cc.ReuseTypeInfoAcrossAssemblies = ReuseTypeInfoAcrossAssemblies;
            if (OutputDirectory != null)
                cc.OutputDirectory = OutputDirectory;
            if (FileOutputDirectory != null)
                cc.FileOutputDirectory = FileOutputDirectory;
            if (Profile != null)
                cc.Profile = Profile;
            if (Path != null)
                cc.Path = Path;

            foreach (var kvp in ProfileSettings)
                cc.ProfileSettings[kvp.Key] = kvp.Value;

            foreach (var kvp in AnalyzerSettings)
                cc.AnalyzerSettings[kvp.Key] = kvp.Value;

            foreach (var kvp in CustomVariables)
                cc.CustomVariables[kvp.Key] = kvp.Value;

            SolutionBuilder.MergeInto(cc.SolutionBuilder);

            cc.ContributingPaths = cc.ContributingPaths.Concat(ContributingPaths).ToArray();
        }
Example #2
0
        protected bool NeedsExplicitThis(
            TypeReference declaringType, TypeDefinition declaringTypeDef, TypeInfo declaringTypeInfo,
            bool isSelf, TypeReference thisReferenceType, JSIL.Internal.MethodInfo methodInfo
        )
        {
            /*
             *  Use our type information to determine whether an invocation must be
             *      performed using an explicit this reference, through an object's
             *      prototype.
             *  The isSelf parameter is used to identify whether the method performing
             *      this invocation is a member of one of the involved types.
             *
             *  (void (Base this)) (Base)
             *      Statically resolved call to self method.
             *      If the name is hidden in the type hierarchy, normal invoke is not ok.
             *
             *  (void (Base this)) (Derived)
             *      Statically resolved call to base method via derived reference.
             *      If isSelf, normal invoke is only ok if the method is never redefined.
             *      (If the method is redefined, we could infinitely call ourselves.)
             *      If the method is virtual, normal invoke is ok.
             *      If the method is never hidden in the type hierarchy, normal is ok.
             *
             *  (void (Interface this)) (Anything)
             *      Call to an interface method. Normal invoke is always OK!
             *
             */

            // System.Array's prototype isn't accessible to us in JS, and we don't
            //     want to call through it anyway.
            if (
                (thisReferenceType is ArrayType) ||
                ((thisReferenceType.Name == "Array") && (thisReferenceType.Namespace == "System"))
            )
                return false;

            var sameThisReference = TypeUtil.TypesAreEqual(declaringTypeDef, thisReferenceType, true);

            var isInterfaceMethod = (declaringTypeDef != null) && (declaringTypeDef.IsInterface);

            if (isInterfaceMethod)
                return false;

            if (methodInfo.IsSealed)
                return false;

            if (methodInfo.IsVirtual) {
                if (sameThisReference)
                    return false;
                else
                    return true;
            } else {
                if (sameThisReference && !isSelf)
                    return false;

                // If the method was defined in a generic class, overloaded dispatch won't be sufficient
                //  because of generic parameters.
                if (!declaringTypeDef.IsGenericInstance && !declaringTypeDef.HasGenericParameters) {
                    var definitionCount = declaringTypeInfo.MethodSignatures.GetDefinitionCountOf(methodInfo);

                    if (definitionCount < 2)
                        return false;
                }

                return true;
            }
        }