/// <summary> /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.2 /// </summary> /// <param name="whileStatement"></param> /// <returns></returns> public Completion ExecuteWhileStatement(WhileStatement whileStatement) { JsValue v = Undefined.Instance; while (true) { var exprRef = _engine.EvaluateExpression(whileStatement.Test); if (!TypeConverter.ToBoolean(_engine.GetValue(exprRef))) { return new Completion(Completion.Normal, v, null); } var stmt = ExecuteStatement(whileStatement.Body); if (stmt.Value != null) { v = stmt.Value; } if (stmt.Type != Completion.Continue || stmt.Identifier != whileStatement.LabelSet) { if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == whileStatement.LabelSet)) { return new Completion(Completion.Normal, v, null); } if (stmt.Type != Completion.Normal) { return stmt; } } } }
private void EmitWhileStatement(WhileStatement s) { _noeolstmt = true; Write("while("); Emit(s.Test); Write(") "); _noeolstmt = false; Emit(s.Body); }