Exemplo n.º 1
0
        public JSSpecialIdentifiers (MethodTypeFactory methodTypes, TypeSystem typeSystem) {
            TypeSystem = typeSystem;
            MethodTypes = methodTypes;

            prototype = Object("prototype");
            eval = new JSFakeMethod("eval", TypeSystem.Object, new[] { TypeSystem.String }, methodTypes);
            toString = new JSFakeMethod("toString", TypeSystem.String, null, methodTypes);
            floor = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int32, null, methodTypes));
            fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, new[] { TypeSystem.Int32 }, methodTypes));
            charCodeAt = new JSFakeMethod("charCodeAt", TypeSystem.Int32, new[] { TypeSystem.Char }, methodTypes);
        }
Exemplo n.º 2
0
        public JSSpecialIdentifiers(MethodTypeFactory methodTypes, TypeSystem typeSystem)
        {
            TypeSystem  = typeSystem;
            MethodTypes = methodTypes;

            prototype    = Object("prototype");
            eval         = new JSFakeMethod("eval", TypeSystem.Object, new[] { TypeSystem.String }, methodTypes);
            toString     = new JSFakeMethod("toString", TypeSystem.String, null, methodTypes);
            floor        = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int32, null, methodTypes));
            fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, new[] { TypeSystem.Int32 }, methodTypes));
            charCodeAt   = new JSFakeMethod("charCodeAt", TypeSystem.Int32, new[] { TypeSystem.Char }, methodTypes);
        }
Exemplo n.º 3
0
 protected JSDotExpressionBase Dot(JSIdentifier rhs)
 {
     return(new JSDotExpression(this, rhs));
 }
Exemplo n.º 4
0
        public CLRSpecialIdentifiers(TypeSystem typeSystem)
        {
            TypeSystem = typeSystem;

            MemberwiseClone = new JSStringIdentifier("MemberwiseClone", TypeSystem.Object);
        }
Exemplo n.º 5
0
        public CLRSpecialIdentifiers(TypeSystem typeSystem)
        {
            TypeSystem = typeSystem;

            MemberwiseClone = new JSStringIdentifier("MemberwiseClone", TypeSystem.Object);
        }
Exemplo n.º 6
0
 protected JSDotExpressionBase Dot(JSIdentifier rhs)
 {
     return new JSDotExpression(this, rhs);
 }
Exemplo n.º 7
0
        public JSSpecialIdentifiers(TypeSystem typeSystem)
        {
            TypeSystem = typeSystem;

            prototype = Object("prototype");
            eval = new JSFakeMethod("eval", TypeSystem.Object, TypeSystem.String);
            toString = new JSFakeMethod("toString", TypeSystem.String);
            floor = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int64));
            fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, TypeSystem.Int32));
            charCodeAt = new JSFakeMethod("charCodeAt", TypeSystem.Int32, TypeSystem.Char);
        }
Exemplo n.º 8
0
 public JSAstBuilder Dot(JSIdentifier identifier)
 {
     return new JSAstBuilder(new JSDotExpression(_expression, identifier));
 }
Exemplo n.º 9
0
 public void VisitNode(JSIdentifier identifier)
 {
     Output.Identifier(identifier.Identifier);
 }
Exemplo n.º 10
0
        private IEnumerable <JSStatement> CreateJsCatchBlock(IEnumerable <CatchBlock> catchBlocks, FaultBlock faultBlock, int p)
        {
            if (catchBlocks.Count() == 1 && catchBlocks.First().CatchType == null)
            {
                yield return(new JSCatchBlock {
                    Error = new JSIdentifier {
                        Name = "_"
                    }
                });

                yield break;
            }

            var handledFlag = new JSIdentifier {
                Name = "__error_handled_" + p + "__"
            };

            var statements = new List <JSStatement>
            {
                JSFactory.Statement(
                    new JSVariableDelcaration
                {
                    Name  = handledFlag.Name,
                    Value = new JSBoolLiteral {
                        Value = false
                    }
                })
            };

            var exceptionObject = new JSIdentifier {
                Name = "__error__"
            };

            foreach (var catchBlock in catchBlocks)
            {
                var block = CreateJsBlock(catchBlock, p);

                int index;
                for (index = 0; index < block.Statements.Count; index++)
                {
                    var es = block.Statements[index] as JSSwitchCase;
                    if (es == null)
                    {
                        break;
                    }
                }

                block.Statements.Insert(index,
                                        JSFactory
                                        .Assignment(handledFlag, new JSBoolLiteral {
                    Value = true
                })
                                        .ToStatement());

                // assign the exception object to expressions reading from top of the stack

                // ok this is too delicate.. we happen to know it is the second expression..

                var expression = catchBlock.Ast.Skip(1).FirstOrDefault() as OpExpression;
                if (expression != null)
                {
                    var locations = expression
                                    .StackBefore
                                    .First()
                                    .Definitions
                                    .Cast <ExceptionNode>()
                                    .SelectMany(e => e.StoreLocations)
                    ;

                    foreach (var location in locations)
                    {
                        block.Statements.Insert(index, JSFactory.Assignment(location.Name, exceptionObject).ToStatement());
                    }
                }

                statements.Add(new JSIfStatement
                {
                    Condition = new JSBinaryExpression
                    {
                        Left = new JSUnaryExpression {
                            Operand = handledFlag, Operator = "!"
                        },
                        Operator = "&&",
                        Right    = new JSBinaryExpression
                        {
                            Left     = exceptionObject,
                            Operator = "instanceof",
                            Right    = GetTypeIdentifier(catchBlock.CatchType, method.ReflectionMethod, type.ReflectionType, this_)
                        }
                    },
                    Statements = block.Build().ToList()
                });
            }

            statements.Add(new JSIfStatement
            {
                Condition = new JSUnaryExpression {
                    Operand = handledFlag, Operator = "!"
                },
                Statements =
                {
                    new JSThrowExpression {
                        Expression = exceptionObject
                    }.ToStatement()
                }
            });

            if (faultBlock != null)
            {
                statements.AddRange(CreateJsFaultBlock(faultBlock, p));
            }

            yield return(new JSCatchBlock
            {
                Error = exceptionObject,
                Statements = statements
            });
        }