Esempio n. 1
0
        public Completion ExecuteStatement(Statement statement)
        {
            var maxStatements = Options._MaxStatements;

            if (maxStatements > 0 && _statementsCount++ > maxStatements)
            {
                throw new StatementsCountOverflowException();
            }

            if (_timeoutTicks > 0 && _timeoutTicks < DateTime.UtcNow.Ticks)
            {
                throw new TimeoutException();
            }

            _lastSyntaxNode = statement;

            if (Options._IsDebugMode)
            {
                DebugHandler.OnStep(statement);
            }

            switch (statement.Type)
            {
            case SyntaxNodes.BlockStatement:
                return(_statements.ExecuteBlockStatement(statement.As <BlockStatement>()));

            case SyntaxNodes.BreakStatement:
                return(_statements.ExecuteBreakStatement(statement.As <BreakStatement>()));

            case SyntaxNodes.ContinueStatement:
                return(_statements.ExecuteContinueStatement(statement.As <ContinueStatement>()));

            case SyntaxNodes.DoWhileStatement:
                return(_statements.ExecuteDoWhileStatement(statement.As <DoWhileStatement>()));

            case SyntaxNodes.DebuggerStatement:
                return(_statements.ExecuteDebuggerStatement(statement.As <DebuggerStatement>()));

            case SyntaxNodes.EmptyStatement:
                return(_statements.ExecuteEmptyStatement(statement.As <EmptyStatement>()));

            case SyntaxNodes.ExpressionStatement:
                return(_statements.ExecuteExpressionStatement(statement.As <ExpressionStatement>()));

            case SyntaxNodes.ForStatement:
                return(_statements.ExecuteForStatement(statement.As <ForStatement>()));

            case SyntaxNodes.ForInStatement:
                return(_statements.ExecuteForInStatement(statement.As <ForInStatement>()));

            case SyntaxNodes.FunctionDeclaration:
                return(new Completion(Completion.Normal, null, null));

            case SyntaxNodes.IfStatement:
                return(_statements.ExecuteIfStatement(statement.As <IfStatement>()));

            case SyntaxNodes.LabeledStatement:
                return(_statements.ExecuteLabelledStatement(statement.As <LabelledStatement>()));

            case SyntaxNodes.ReturnStatement:
                return(_statements.ExecuteReturnStatement(statement.As <ReturnStatement>()));

            case SyntaxNodes.SwitchStatement:
                return(_statements.ExecuteSwitchStatement(statement.As <SwitchStatement>()));

            case SyntaxNodes.ThrowStatement:
                return(_statements.ExecuteThrowStatement(statement.As <ThrowStatement>()));

            case SyntaxNodes.TryStatement:
                return(_statements.ExecuteTryStatement(statement.As <TryStatement>()));

            case SyntaxNodes.VariableDeclaration:
                return(_statements.ExecuteVariableDeclaration(statement.As <VariableDeclaration>()));

            case SyntaxNodes.WhileStatement:
                return(_statements.ExecuteWhileStatement(statement.As <WhileStatement>()));

            case SyntaxNodes.WithStatement:
                return(_statements.ExecuteWithStatement(statement.As <WithStatement>()));

            case SyntaxNodes.Program:
                return(_statements.ExecuteProgram(statement.As <Program>()));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }