public void ExecuteStatement(RuntimeState state) { Statement statement = (Statement)state.arg; //_lastSyntaxNode = statement; /* if (_runBeforeStatementChecks) * { * BeforeExecuteStatement(statement); * } */ if (state.calleeReturned) { switch (statement.Type) { case Nodes.BlockStatement: case Nodes.VariableDeclaration: case Nodes.BreakStatement: case Nodes.ContinueStatement: case Nodes.DoWhileStatement: case Nodes.ForStatement: case Nodes.ForInStatement: case Nodes.IfStatement: case Nodes.LabeledStatement: case Nodes.SwitchStatement: case Nodes.ThrowStatement: case Nodes.TryStatement: case Nodes.WhileStatement: case Nodes.WithStatement: case Nodes.Program: _statements.Return(state.calleeReturnValue); return; case Nodes.ReturnStatement: var jsValue = ((ReturnStatement)statement).Argument == null ? Undefined.Instance : GetValue(state.calleeReturnValue, true); _statements.Return(new Completion(CompletionType.Return, jsValue, null)); return; case Nodes.ExpressionStatement: _statements.Return(new Completion( CompletionType.Normal, GetValue(state.calleeReturnValue, true), null)); return; default: ExceptionHelper.ThrowArgumentOutOfRangeException(); _statements.Return(new Completion(CompletionType.Normal, null, null)); return; } } switch (statement.Type) { case Nodes.BlockStatement: _statements.Call(_statements.ExecuteStatementList, ((BlockStatement)statement).Body); return; case Nodes.ReturnStatement: _statements.Call(EvaluateExpression, ((ReturnStatement)statement).Argument); return; case Nodes.VariableDeclaration: _statements.Call(_statements.ExecuteVariableDeclaration, (VariableDeclaration)statement); return; case Nodes.BreakStatement: _statements.Call(_statements.ExecuteBreakStatement, (BreakStatement)statement); return; case Nodes.ContinueStatement: _statements.Call(_statements.ExecuteContinueStatement, (ContinueStatement)statement); return; case Nodes.DoWhileStatement: _statements.Call(_statements.ExecuteDoWhileStatement, (DoWhileStatement)statement); return; case Nodes.EmptyStatement: _statements.Return(new Completion(CompletionType.Normal, null, null)); return; case Nodes.ExpressionStatement: _statements.Call(EvaluateExpression, ((ExpressionStatement)statement).Expression); return; case Nodes.ForStatement: _statements.Call(_statements.ExecuteForStatement, (ForStatement)statement); return; case Nodes.ForInStatement: _statements.Call(_statements.ExecuteForInStatement, (ForInStatement)statement); return; case Nodes.IfStatement: _statements.Call(_statements.ExecuteIfStatement, (IfStatement)statement); return; case Nodes.LabeledStatement: _statements.Call(_statements.ExecuteLabeledStatement, (LabeledStatement)statement); return; case Nodes.SwitchStatement: _statements.Call(_statements.ExecuteSwitchStatement, (SwitchStatement)statement); return; case Nodes.FunctionDeclaration: _statements.Return(new Completion(CompletionType.Normal, null, null)); return; case Nodes.ThrowStatement: _statements.Call(_statements.ExecuteThrowStatement, (ThrowStatement)statement); return; case Nodes.TryStatement: _statements.Call(_statements.ExecuteTryStatement, (TryStatement)statement); return; case Nodes.WhileStatement: _statements.Call(_statements.ExecuteWhileStatement, (WhileStatement)statement); return; case Nodes.WithStatement: _statements.Call(_statements.ExecuteWithStatement, (WithStatement)statement); return; case Nodes.Program: _statements.Call(_statements.ExecuteProgram, (Program)statement); return; default: ExceptionHelper.ThrowArgumentOutOfRangeException(); _statements.Return(new Completion(CompletionType.Normal, null, null)); return; } }