예제 #1
0
 /// <summary>
 /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.11
 /// </summary>
 /// <param name="switchStatement"></param>
 /// <returns></returns>
 public Completion ExecuteSwitchStatement(SwitchStatement switchStatement)
 {
     var exprRef = _engine.EvaluateExpression(switchStatement.Discriminant);
     var r = ExecuteSwitchBlock(switchStatement.Cases, _engine.GetValue(exprRef));
     if (r.Type == Completion.Break && r.Identifier == switchStatement.LabelSet)
     {
         return new Completion(Completion.Normal, r.Value, null);
     }
     return r;
 }
예제 #2
0
        private void EmitSwitchStatement(SwitchStatement s)
        {
            Write("switch(");
            Emit(s.Discriminant);
            Write(")");
            EnterBlock();
            foreach (var c in s.Cases)
            {
                Write(c.Test == null ? "default " : "case ");
                Emit(c.Test);
                WriteLine(": ");
                Indent();
                foreach (var stmt in c.Consequent)
                {
                    Emit(stmt);
                }
                UnIndent();
            }

            LeaveBlock();
        }