示例#1
0
        private static object NewWithInitializer(JsType type, JsObject json)
        {
            var obj = JsCompiler.NewByFunc(type.ctor);

            if (@typeof(json) == "array")
            {
                throw new Exception("not implemented");
            }
            else
            {
                foreach (var p in json)
                {
                    var setter = obj.As <JsObject>()["set_" + p];
                    if (@typeof(setter) == "function")
                    {
                        setter.As <JsFunction>().call(obj, json[p]);
                    }
                    else
                    {
                        obj.As <JsObject>()[p] = json[p];
                    }
                }
            }
            return(obj);
        }
示例#2
0
 JsImplType(JsType jsType)
 {
     _JsType = jsType;
     _Name = _JsType.name;
     if (EmptyTypes == null)
         EmptyTypes = new JsImplType[0];
 }
示例#3
0
 public static JsImplType _TypeOf(JsType jsType)
 {
     if (jsType == null)
         throw new Exception("Cannot resovle type");
     if (jsType._ClrType == null)
         jsType._ClrType = new JsImplType(jsType);
     return jsType._ClrType;
 }
示例#4
0
        //checkes if the [objType] is of a certain [type]
        static bool TypeIs(JsType objType, JsType type)
        {
            if (objType == type)
            {
                return(true);
            }
            if (type.Kind == JsTypeKind.Interface)
            {
                var testedInterfaces = new JsObject();
                while (objType != null)
                {
                    if (objType == type)
                    {
                        return(true);
                    }
                    if (_TestTypeInterfacesIs(objType, type, testedInterfaces))
                    {
                        return(true);
                    }
                    objType = objType.baseType;
                }
                return(false);
            }
            if (type.Kind == JsTypeKind.Delegate && objType.fullname == "System.Delegate")
            {
                //for now, casting between any delegate type is permitted
                return(true);
            }
            if (objType.fullname == "System.Int32")
            {
                if (type.fullname == "System.Decimal")
                {
                    return(true);
                }
                if (type.fullname == "System.Double")
                {
                    return(true);
                }
                if (type.fullname == "System.Single")
                {
                    return(true);
                }
            }
            var t = objType.baseType;

            while (t != null)
            {
                if (t == type)
                {
                    return(true);
                }
                t = t.baseType;
            }
            return(false);
        }
示例#5
0
 public static string GetAssemblyQualifiedName(this JsType type)
 {
     if (type._AssemblyQualifiedName == null)
     {
         var name = type.fullname;
         if (type.assemblyName != null)
         {
             name += ", " + type.assemblyName;
         }
         type._AssemblyQualifiedName = name;
     }
     return(type._AssemblyQualifiedName);
 }
示例#6
0
        private static void ResolveBaseType(JsType type, JsType currentType)
        {
            var baseType = JsTypeHelper.GetType(type.baseTypeName);

            if (baseType == null)
            {
                baseType = JsTypeHelper.GetTypeIgnoreNamespace(type.baseTypeName, true);
            }
            if (!baseType.isCompiled)
            {
                CompileType(baseType);
            }
            currentType.baseType = baseType;
            baseType.derivedTypes.push(currentType);
        }
示例#7
0
 private static void CompileEnum(JsType currentType)
 {
     if (currentType.Kind == JsTypeKind.Enum)
     {
         currentType.tryParse = _EnumTryParse;
         foreach (var p in currentType.staticDefinition)
         {
             if (@typeof(currentType.staticDefinition[p]) == "string")
             {
                 var x = NewByFunc(currentType.ctor);
                 x.As <JsObject>()["_Name"]      = p;
                 currentType.staticDefinition[p] = x;
                 currentType.As <JsObject>()[p]  = x;
             }
         }
     }
 }
示例#8
0
        private static void Compile_Phase2_TmpType(JsType tmpType)
        {
            var p    = tmpType.fullname;
            var type = CompileType(tmpType);

            if (type != null)
            {
                CopyMemberIfNotDefined(type, type.fullname, window);
            }
            if (type.ns != null)
            {
                var ns = ResolveNamespace(type.ns);
                if (type != null)
                {
                    ns[type.name] = type;
                }
            }
        }
示例#9
0
        private static void Compile_Phase2_TmpType(JsType tmpType)
        {
            var    p    = tmpType.fullname;
            JsType type = null;

            //tmpType = tmpTypes[p].As<JsType>();
            type = CompileType(tmpType);
            if (type != null)                                        //.ctor  && type.ns!=null && type.ns!=""
            {
                CopyMemberIfNotDefined(type, type.fullname, window); //window[type.get_FullName()] = type;//.ctor;
            }
            if (type.ns != null)
            {
                var ns = ResolveNamespace(type.ns);
                if (type != null)         //.ctor
                {
                    ns[type.name] = type; //.ctor;
                }
            }
        }
示例#10
0
 static bool _TestTypeInterfacesIs(JsType testType, JsType iface, JsObject testedInterfaces)
 {
     if (testedInterfaces[iface.name].As <bool>())
     {
         return(false);
     }
     for (var i = 0; i < testType.interfaces.length; i++)
     {
         var testIface = testType.interfaces[i].As <JsType>();
         if (testIface == iface)
         {
             return(true);
         }
         testedInterfaces[testIface.name] = true;
         if (_TestTypeInterfacesIs(testIface, iface, testedInterfaces))
         {
             return(true);
         }
     }
     return(false);
 }
示例#11
0
 private static void ResolveInterfaces(JsType type, JsType currentType)
 {
     if (type.interfaceNames == null)
     {
         return;
     }
     for (var i = 0; i < type.interfaceNames.length; i++)
     {
         var iName = type.interfaceNames[i].As <string>();
         var iface = JsTypeHelper.GetType(iName);
         if (iface == null)
         {
             iface = JsTypeHelper.GetTypeIgnoreNamespace(iName, true);
         }
         if (!iface.isCompiled)
         {
             CompileType(iface);
         }
         currentType.interfaces.push(iface);
     }
 }
示例#12
0
 public static string GetName(this JsType type)
 {
     return(type.name);
 }
示例#13
0
 private static object NewAtServer(JsType type, params object[] args)
 {
     throw new NotImplementedException();
     //return RemotingServices.DefaultProxy.CreateInstance(type.assemblyName, type.get_FullName(), JsCompilerArguments.from(JsContext.arguments, 1).As<object[]>());
 }
示例#14
0
 internal static JsDelegateFunction CreateClrDelegate(JsType type, JsArray<JsType> genericArgs, object target, JsFunction func)
 {
     return JsTypeHelper.GetDelegate(target, func).As<JsDelegateFunction>(); //TODO: support delegate.getType()
 }
示例#15
0
 static JsFunction CreateBaseCtor(JsType type)
 {
     throw new NotImplementedException();
 }
示例#16
0
 private static void Compile_Phase2_TmpType(JsType tmpType)
 {
     var p = tmpType.fullname;
     JsType type = null;
     //tmpType = tmpTypes[p].As<JsType>();
     type = CompileType(tmpType);
     if (type != null)//.ctor  && type.ns!=null && type.ns!=""
         CopyMemberIfNotDefined(type, type.fullname, window); //window[type.get_FullName()] = type;//.ctor;
     if (type.ns != null)
     {
         var ns = ResolveNamespace(type.ns);
         if (type != null)//.ctor
             ns[type.name] = type; //.ctor;
     }
 }
示例#17
0
        private static JsType CompileType(JsType type)
        {
            var currentType = Types[type.fullname].As <JsType>() ?? type;

            if (currentType.ctors == null)
            {
                currentType.ctors = new JsObject();
            }
            if (!type.isCompiled)
            {
                var baseTypeResolved = false;
                if (currentType.baseType == null && currentType.baseTypeName != null)
                {
                    ResolveBaseType(type, currentType);
                    if (currentType.baseType != null)
                    {
                        baseTypeResolved = true;
                    }
                }
                ResolveInterfaces(type, currentType);
                foreach (var p in type.definition)
                {
                    if (p.As <JsString>().search("ctor") == 0) //isCtor
                    {
                        currentType.As <JsObject>()[p] = type.definition[p];
                        JsContext.delete(type.definition[p]);
                        if (JsContext.@typeof(currentType.commonPrototype) == "undefined")
                        {
                            currentType.commonPrototype = currentType.As <JsObject>()[p].As <JsFunction>().prototype.As <JsCompilerPrototype>();
                        }
                        else
                        {
                            currentType.As <JsObject>()[p].As <JsFunction>().prototype = currentType.commonPrototype;
                        }
                        currentType.ctors[p] = currentType.As <JsObject>()[p];
                    }
                    if (p == "cctor")
                    {
                        currentType.cctor = p.As <JsFunction>();
                    }
                }
                //		if(currentType.ctor==null)
                //		{
                //			currentType.ctor = window[type.get_FullName()];
                //		}
                if (currentType.ctor == null)
                {
                    if (currentType.ns == null || currentType.ns == "")
                    {
                        var jsCtor = window.As <JsObject>()[currentType.name].As <JsFunction>();
                        currentType.ctor = jsCtor;
                    }
                    //			currentType.ctor = type.definition[type.name];
                    //			if(type.definition[type.name]!=null)
                    //				delete type.definition[type.name];
                    //			else
                    if (currentType.ctor == null && currentType.ctors != null)
                    {
                        var createCtor = true;
                        foreach (var p in currentType.ctors)
                        {
                            createCtor = false;
                            break;
                        }
                        if (createCtor)
                        {
                            if (currentType.baseType != null)
                            {
                                currentType.ctor = CreateBaseCtor();
                            }
                            else
                            {
                                currentType.ctor = CreateEmptyCtor();
                            }
                        }
                    }
                    if (currentType.ctor != null)
                    {
                        currentType.ctors["ctor"] = currentType.ctor;
                        if (JsContext.@typeof(currentType.commonPrototype) == "undefined")
                        {
                            currentType.commonPrototype = currentType.ctor.prototype.As <JsCompilerPrototype>();
                        }
                        else
                        {
                            currentType.ctor.prototype = currentType.commonPrototype;
                        }
                    }
                }
                foreach (var p in currentType.ctors)
                {
                    var ctor = currentType.ctors[p].As <JsCompilerFunction>();
                    if (ctor._type == null)
                    {
                        ctor._type = currentType;
                    }
                }
                //		if(currentType.ctor._type==null)
                //			currentType.ctor._type = currentType;
                if (baseTypeResolved)
                {
                    _CopyObject(currentType.baseType.commonPrototype, currentType.commonPrototype);
                }
                foreach (var p in type.definition)
                {
                    var member = type.definition[p];
                    currentType.commonPrototype[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As <JsCompilerFunction>()._name = p;
                        member.As <JsCompilerFunction>()._type = currentType;
                    }
                }
                if (type.definition.As <JsCompilerPrototype>().toString != JsCompilerObject.prototype.toString)
                {
                    currentType.commonPrototype.toString       = type.definition.As <JsCompilerPrototype>().toString;
                    currentType.commonPrototype.toString.name  = "toString";
                    currentType.commonPrototype.toString._type = currentType;
                }
                foreach (var p in type.staticDefinition)
                {
                    var member = type.staticDefinition[p];
                    //TODO: if (JsContext.@typeof(currentType.As<JsObject>()[p]) != "undefined")
                    //TODO:    throw new JsError("Reserved static member name " + p).As<Exception>();
                    currentType.As <JsObject>()[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As <JsCompilerFunction>()._name = p;
                        member.As <JsCompilerFunction>()._type = currentType;
                    }
                }
                type.isCompiled = true;
            }
            CompileEnum(currentType);
            if (currentType != type && type.customAttributes != null)
            {
                if (currentType.customAttributes != null)
                {
                    for (var i = 0; i < type.customAttributes.length; i++)
                    {
                        currentType.customAttributes.push(type.customAttributes[i]);
                    }
                }
                else
                {
                    currentType.customAttributes = type.customAttributes;
                }
            }

            return(currentType);
        }
示例#18
0
 private static void CompileEnum(JsType currentType)
 {
     if (currentType.Kind == JsTypeKind.Enum)
     {
         currentType.tryParse = _EnumTryParse;
         foreach (var p in currentType.staticDefinition)
         {
             if (@typeof(currentType.staticDefinition[p]) == "string")
             {
                 var x = NewByFunc(currentType.ctor);
                 x.As<JsObject>()["_Name"] = p;
                 currentType.staticDefinition[p] = x;
                 currentType.As<JsObject>()[p] = x;
             }
         }
     }
 }
示例#19
0
        private static JsType CompileType(JsType type)
        {
            var currentType = Types[type.fullname].As<JsType>() ?? type;
            if (currentType.ctors == null)
                currentType.ctors = new JsObject();
            if (!type.isCompiled)
            {
                var baseTypeResolved = false;
                if (currentType.baseType == null && currentType.baseTypeName != null)
                {
                    ResolveBaseType(type, currentType);
                    if (currentType.baseType != null)
                        baseTypeResolved = true;
                }
                ResolveInterfaces(type, currentType);
                foreach (var p in type.definition)
                {
                    if (p.As<JsString>().search("ctor") == 0) //isCtor
                    {
                        currentType.As<JsObject>()[p] = type.definition[p];
                        delete(type.definition[p]);
                        if (@typeof(currentType.commonPrototype) == "undefined")
                            currentType.commonPrototype = currentType.As<JsObject>()[p].As<JsFunction>().prototype.As<JsCompilerPrototype>();
                        else
                            currentType.As<JsObject>()[p].As<JsFunction>().prototype = currentType.commonPrototype;
                        currentType.ctors[p] = currentType.As<JsObject>()[p];
                    }
                    if (p == "cctor")
                        currentType.cctor = p.As<JsFunction>();
                }
                if (currentType.ctor == null)
                {
                    if (currentType.ns == null || currentType.ns == "")
                    {
                        var jsCtor = window.As<JsObject>()[currentType.name].As<JsFunction>();
                        if (JsTypeOf(jsCtor) == JavaScript.JsTypes.function)
                            currentType.ctor = jsCtor;
                    }
                    if (currentType.ctor == null && currentType.ctors != null)
                    {
                        //create default ctor anyway for generic argument passing, etc...
                        //var createCtor = true;
                        //foreach (var p in currentType.ctors)
                        //{
                        //    createCtor = false;
                        //    break;
                        //}
                        //if (createCtor)
                        //{
                        if (currentType.baseType != null)
                            currentType.ctor = CreateBaseCtor(currentType);
                        else
                            currentType.ctor = CreateEmptyCtor();
                        //}
                    }
                    if (currentType.ctor != null)
                    {
                        currentType.ctors["ctor"] = currentType.ctor;
                        if (@typeof(currentType.commonPrototype) == "undefined")
                            currentType.commonPrototype = currentType.ctor.prototype.As<JsCompilerPrototype>();
                        else
                            currentType.ctor.prototype = currentType.commonPrototype;
                    }
                }
                foreach (var p in currentType.ctors)
                {
                    var ctor = currentType.ctors[p].As<JsCompilerFunction>();
                    if (ctor._type == null)
                        ctor._type = currentType;
                }
                if (baseTypeResolved)
                {
                    _CopyObject(currentType.baseType.commonPrototype, currentType.commonPrototype);
                }
                foreach (var p in type.definition)
                {
                    var member = type.definition[p];
                    currentType.commonPrototype[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As<JsCompilerFunction>()._name = p;
                        member.As<JsCompilerFunction>()._type = currentType;
                    }
                }
                if (type.definition.As<JsCompilerPrototype>().toString != JsCompilerObject.prototype.toString)
                {
                    currentType.commonPrototype.toString = type.definition.As<JsCompilerPrototype>().toString;
                    //currentType.commonPrototype.toString.name = "toString"; //It's always readonly! (and forbidden in strict mode)
                    currentType.commonPrototype.toString._type = currentType;
                }
                foreach (var p in type.staticDefinition)
                {
                    var member = type.staticDefinition[p];
                    //TODO: if (@typeof(currentType.As<JsObject>()[p]) != "undefined")
                    //TODO:    throw new JsError("Reserved static member name " + p).As<Exception>();
                    currentType.As<JsObject>()[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As<JsCompilerFunction>()._name = p;
                        member.As<JsCompilerFunction>()._type = currentType;
                    }
                }
                type.isCompiled = true;
            }
            CompileEnum(currentType);
            if (currentType != type && type.customAttributes != null)
            {
                if (currentType.customAttributes != null)
                {
                    for (var i = 0; i < type.customAttributes.length; i++)
                    {
                        currentType.customAttributes.push(type.customAttributes[i]);
                    }
                }
                else
                {
                    currentType.customAttributes = type.customAttributes;
                }
            }

            return currentType;
        }
示例#20
0
 private static void ResolveInterfaces(JsType type, JsType currentType)
 {
     if (type.interfaceNames == null)
         return;
     for (var i = 0; i < type.interfaceNames.length; i++)
     {
         var iName = type.interfaceNames[i].As<string>();
         var iface = JsTypeHelper.GetType(iName);
         if (iface == null)
             iface = JsTypeHelper.GetTypeIgnoreNamespace(iName, true);
         if (!iface.isCompiled)
             CompileType(iface);
         currentType.interfaces.push(iface);
     }
 }
示例#21
0
 private static void ResolveBaseType(JsType type, JsType currentType)
 {
     var baseType = JsTypeHelper.GetType(type.baseTypeName);
     if (baseType == null)
         baseType = JsTypeHelper.GetTypeIgnoreNamespace(type.baseTypeName, true);
     if (!baseType.isCompiled)
         CompileType(baseType);
     currentType.baseType = baseType;
     baseType.derivedTypes.push(currentType);
 }
示例#22
0
 static JsFunction CreateBaseCtor(JsType type)
 {
     throw new NotImplementedException();
 }
示例#23
0
 static bool _TestTypeInterfacesIs(JsType testType, JsType iface, JsObject testedInterfaces)
 {
     if (testedInterfaces[iface.name].As<bool>())
         return false;
     for (var i = 0; i < testType.interfaces.length; i++)
     {
         var testIface = testType.interfaces[i].As<JsType>();
         if (testIface == iface)
             return true;
         testedInterfaces[testIface.name] = true;
         if (_TestTypeInterfacesIs(testIface, iface, testedInterfaces))
             return true;
     }
     return false;
 }
示例#24
0
 internal static JsDelegateFunction CreateClrDelegate(JsType type, JsArray <JsType> genericArgs, object target, JsFunction func)
 {
     return(JsTypeHelper.GetDelegate(target, func).As <JsDelegateFunction>()); //TODO: support delegate.getType()
 }
示例#25
0
 //checkes if the [objType] is of a certain [type]
 static bool TypeIs(JsType objType, JsType type)
 {
     if (objType == type)
         return true;
     if (type.Kind == JsTypeKind.Interface)
     {
         var testedInterfaces = new JsObject();
         while (objType != null)
         {
             if (objType == type)
                 return true;
             if (_TestTypeInterfacesIs(objType, type, testedInterfaces))
                 return true;
             objType = objType.baseType;
         }
         return false;
     }
     if (type.Kind == JsTypeKind.Delegate && objType.fullname == "System.Delegate")
     {
         //for now, casting between any delegate type is permitted
         return true;
     }
     if (objType.fullname == "System.Int32")
     {
         if (type.fullname == "System.Decimal")
             return true;
         if (type.fullname == "System.Double")
             return true;
         if (type.fullname == "System.Single")
             return true;
     }
     var t = objType.baseType;
     while (t != null)
     {
         if (t == type)
             return true;
         t = t.baseType;
     }
     return false;
 }
示例#26
0
        private static JsType CompileType(JsType type)
        {
            var currentType = Types[type.fullname].As <JsType>() ?? type;

            if (currentType.ctors == null)
            {
                currentType.ctors = new JsObject();
            }
            if (!type.isCompiled)
            {
                var baseTypeResolved = false;
                if (currentType.baseType == null && currentType.baseTypeName != null)
                {
                    ResolveBaseType(type, currentType);
                    if (currentType.baseType != null)
                    {
                        baseTypeResolved = true;
                    }
                }
                ResolveInterfaces(type, currentType);
                foreach (var p in type.definition)
                {
                    if (p.As <JsString>().search("ctor") == 0) //isCtor
                    {
                        currentType.As <JsObject>()[p] = type.definition[p];
                        delete(type.definition[p]);
                        if (@typeof(currentType.commonPrototype) == "undefined")
                        {
                            currentType.commonPrototype = currentType.As <JsObject>()[p].As <JsFunction>().prototype.As <JsCompilerPrototype>();
                        }
                        else
                        {
                            currentType.As <JsObject>()[p].As <JsFunction>().prototype = currentType.commonPrototype;
                        }
                        currentType.ctors[p] = currentType.As <JsObject>()[p];
                    }
                    if (p == "cctor")
                    {
                        currentType.cctor = p.As <JsFunction>();
                    }
                }
                if (currentType.ctor == null)
                {
                    if (currentType.ns == null || currentType.ns == "")
                    {
                        var jsCtor = window.As <JsObject>()[currentType.name].As <JsFunction>();
                        if (JsTypeOf(jsCtor) == JavaScript.JsTypes.function || JsTypeOf(jsCtor) == JavaScript.JsTypes.@object)
                        {
                            currentType.ctor = jsCtor;
                        }
                    }
                    if (currentType.ctor == null && currentType.ctors != null)
                    {
                        //create default ctor anyway for generic argument passing, etc...
                        //var createCtor = true;
                        //foreach (var p in currentType.ctors)
                        //{
                        //    createCtor = false;
                        //    break;
                        //}
                        //if (createCtor)
                        //{
                        if (currentType.baseType != null)
                        {
                            currentType.ctor = CreateBaseCtor(currentType);
                        }
                        else
                        {
                            currentType.ctor = CreateEmptyCtor();
                        }
                        //}
                    }
                    if (currentType.ctor != null)
                    {
                        currentType.ctors["ctor"] = currentType.ctor;
                        if (@typeof(currentType.commonPrototype) == "undefined")
                        {
                            currentType.commonPrototype = currentType.ctor.prototype.As <JsCompilerPrototype>();
                        }
                        else
                        {
                            currentType.ctor.prototype = currentType.commonPrototype;
                        }
                    }
                }
                foreach (var p in currentType.ctors)
                {
                    var ctor = currentType.ctors[p].As <JsCompilerFunction>();
                    if (ctor._type == null)
                    {
                        ctor._type = currentType;
                    }
                }
                if (baseTypeResolved)
                {
                    _CopyObject(currentType.baseType.commonPrototype, currentType.commonPrototype);
                }
                foreach (var p in type.definition)
                {
                    var member = type.definition[p];
                    currentType.commonPrototype[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As <JsCompilerFunction>()._name = p;
                        member.As <JsCompilerFunction>()._type = currentType;
                    }
                }
                if (type.definition.As <JsCompilerPrototype>().toString != JsCompilerObject.prototype.toString)
                {
                    currentType.commonPrototype.toString = type.definition.As <JsCompilerPrototype>().toString;
                    //currentType.commonPrototype.toString.name = "toString"; //It's always readonly! (and forbidden in strict mode)
                    currentType.commonPrototype.toString._type = currentType;
                }
                foreach (var p in type.staticDefinition)
                {
                    var member = type.staticDefinition[p];
                    //TODO: if (@typeof(currentType.As<JsObject>()[p]) != "undefined")
                    //TODO:    throw new JsError("Reserved static member name " + p).As<Exception>();
                    currentType.As <JsObject>()[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As <JsCompilerFunction>()._name = p;
                        member.As <JsCompilerFunction>()._type = currentType;
                    }
                }
                type.isCompiled = true;
            }
            CompileEnum(currentType);
            if (currentType != type && type.customAttributes != null)
            {
                if (currentType.customAttributes != null)
                {
                    for (var i = 0; i < type.customAttributes.length; i++)
                    {
                        currentType.customAttributes.push(type.customAttributes[i]);
                    }
                }
                else
                {
                    currentType.customAttributes = type.customAttributes;
                }
            }

            return(currentType);
        }
示例#27
0
 private static object TryImplicitConvert(object obj, JsType type)
 {
     throw new NotImplementedException();
 }
示例#28
0
 private static void Compile_Phase2_TmpType(JsType tmpType)
 {
     var p = tmpType.fullname;
     var type = CompileType(tmpType);
     if (type != null)
         CopyMemberIfNotDefined(type, type.fullname, window);
     if (type.ns != null)
     {
         var ns = ResolveNamespace(type.ns);
         if (type != null)
             ns[type.name] = type;
     }
 }
示例#29
0
 private static object TryImplicitConvert(object obj, JsType type)
 {
     throw new NotImplementedException();
 }
示例#30
0
 private static object NewWithInitializer(JsType type, JsObject json)
 {
     var obj = JsCompiler.NewByFunc(type.ctor);
     if (@typeof(json) == "array")
     {
         throw new Exception("not implemented");
     }
     else
     {
         foreach (var p in json)
         {
             var setter = obj.As<JsObject>()["set_" + p];
             if (@typeof(setter) == "function")
                 setter.As<JsFunction>().call(obj, json[p]);
             else
                 obj.As<JsObject>()[p] = json[p];
         }
     }
     return obj;
 }
示例#31
0
        private static JsType CompileType(JsType type)
        {
            var currentType = Types[type.fullname].As<JsType>() ?? type;
            if (currentType.ctors == null)
                currentType.ctors = new JsObject();
            if (!type.isCompiled)
            {
                var baseTypeResolved = false;
                if (currentType.baseType == null && currentType.baseTypeName != null)
                {
                    ResolveBaseType(type, currentType);
                    if (currentType.baseType != null)
                        baseTypeResolved = true;
                }
                ResolveInterfaces(type, currentType);
                foreach (var p in type.definition)
                {
                    if (p.As<JsString>().search("ctor") == 0) //isCtor
                    {
                        currentType.As<JsObject>()[p] = type.definition[p];
                        JsContext.delete(type.definition[p]);
                        if (JsContext.@typeof(currentType.commonPrototype) == "undefined")
                            currentType.commonPrototype = currentType.As<JsObject>()[p].As<JsFunction>().prototype.As<JsCompilerPrototype>();
                        else
                            currentType.As<JsObject>()[p].As<JsFunction>().prototype = currentType.commonPrototype;
                        currentType.ctors[p] = currentType.As<JsObject>()[p];
                    }
                    if (p == "cctor")
                        currentType.cctor = p.As<JsFunction>();
                }
                //		if(currentType.ctor==null)
                //		{
                //			currentType.ctor = window[type.get_FullName()];
                //		}
                if (currentType.ctor == null)
                {
                    if (currentType.ns == null || currentType.ns == "")
                    {
                        var jsCtor = window.As<JsObject>()[currentType.name].As<JsFunction>();
                        currentType.ctor = jsCtor;
                    }
                    //			currentType.ctor = type.definition[type.name];
                    //			if(type.definition[type.name]!=null)
                    //				delete type.definition[type.name];
                    //			else
                    if (currentType.ctor == null && currentType.ctors != null)
                    {
                        var createCtor = true;
                        foreach (var p in currentType.ctors)
                        {
                            createCtor = false;
                            break;
                        }
                        if (createCtor)
                        {
                            if (currentType.baseType != null)
                                currentType.ctor = CreateBaseCtor();
                            else
                                currentType.ctor = CreateEmptyCtor();
                        }
                    }
                    if (currentType.ctor != null)
                    {
                        currentType.ctors["ctor"] = currentType.ctor;
                        if (JsContext.@typeof(currentType.commonPrototype) == "undefined")
                            currentType.commonPrototype = currentType.ctor.prototype.As<JsCompilerPrototype>();
                        else
                            currentType.ctor.prototype = currentType.commonPrototype;
                    }
                }
                foreach (var p in currentType.ctors)
                {
                    var ctor = currentType.ctors[p].As<JsCompilerFunction>();
                    if (ctor._type == null)
                        ctor._type = currentType;
                }
                //		if(currentType.ctor._type==null)
                //			currentType.ctor._type = currentType;
                if (baseTypeResolved)
                {
                    _CopyObject(currentType.baseType.commonPrototype, currentType.commonPrototype);
                }
                foreach (var p in type.definition)
                {
                    var member = type.definition[p];
                    currentType.commonPrototype[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As<JsCompilerFunction>()._name = p;
                        member.As<JsCompilerFunction>()._type = currentType;
                    }
                }
                if (type.definition.As<JsCompilerPrototype>().toString != JsCompilerObject.prototype.toString)
                {
                    currentType.commonPrototype.toString = type.definition.As<JsCompilerPrototype>().toString;
                    currentType.commonPrototype.toString.name = "toString";
                    currentType.commonPrototype.toString._type = currentType;
                }
                foreach (var p in type.staticDefinition)
                {
                    var member = type.staticDefinition[p];
                    //TODO: if (JsContext.@typeof(currentType.As<JsObject>()[p]) != "undefined")
                    //TODO:    throw new JsError("Reserved static member name " + p).As<Exception>();
                    currentType.As<JsObject>()[p] = member;
                    if (JsContext.@typeof(member) == "function")
                    {
                        member.As<JsCompilerFunction>()._name = p;
                        member.As<JsCompilerFunction>()._type = currentType;
                    }
                }
                type.isCompiled = true;
            }
            CompileEnum(currentType);
            if (currentType != type && type.customAttributes != null)
            {
                if (currentType.customAttributes != null)
                {
                    for (var i = 0; i < type.customAttributes.length; i++)
                    {
                        currentType.customAttributes.push(type.customAttributes[i]);
                    }
                }
                else
                {
                    currentType.customAttributes = type.customAttributes;
                }
            }

            return currentType;
        }