|
@@ -2,63 +2,62 @@ using Esprima.Ast;
|
|
|
using Jint.Native;
|
|
|
using Jint.Runtime.Interpreter.Expressions;
|
|
|
|
|
|
-namespace Jint.Runtime.Interpreter.Statements
|
|
|
+namespace Jint.Runtime.Interpreter.Statements;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.1
|
|
|
+/// </summary>
|
|
|
+internal sealed class JintDoWhileStatement : JintStatement<DoWhileStatement>
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.1
|
|
|
- /// </summary>
|
|
|
- internal sealed class JintDoWhileStatement : JintStatement<DoWhileStatement>
|
|
|
+ private ProbablyBlockStatement _body;
|
|
|
+ private string? _labelSetName;
|
|
|
+ private JintExpression _test = null!;
|
|
|
+
|
|
|
+ public JintDoWhileStatement(DoWhileStatement statement) : base(statement)
|
|
|
{
|
|
|
- private ProbablyBlockStatement _body;
|
|
|
- private string? _labelSetName;
|
|
|
- private JintExpression _test = null!;
|
|
|
+ }
|
|
|
|
|
|
- public JintDoWhileStatement(DoWhileStatement statement) : base(statement)
|
|
|
- {
|
|
|
- }
|
|
|
+ protected override void Initialize(EvaluationContext context)
|
|
|
+ {
|
|
|
+ _body = new ProbablyBlockStatement(_statement.Body);
|
|
|
+ _test = JintExpression.Build(_statement.Test);
|
|
|
+ _labelSetName = _statement.LabelSet?.Name;
|
|
|
+ }
|
|
|
|
|
|
- protected override void Initialize(EvaluationContext context)
|
|
|
- {
|
|
|
- _body = new ProbablyBlockStatement(_statement.Body);
|
|
|
- _test = JintExpression.Build(_statement.Test);
|
|
|
- _labelSetName = _statement.LabelSet?.Name;
|
|
|
- }
|
|
|
+ protected override Completion ExecuteInternal(EvaluationContext context)
|
|
|
+ {
|
|
|
+ JsValue v = JsValue.Undefined;
|
|
|
+ bool iterating;
|
|
|
|
|
|
- protected override Completion ExecuteInternal(EvaluationContext context)
|
|
|
+ do
|
|
|
{
|
|
|
- JsValue v = JsValue.Undefined;
|
|
|
- bool iterating;
|
|
|
+ var completion = _body.Execute(context);
|
|
|
+ if (!ReferenceEquals(completion.Value, null))
|
|
|
+ {
|
|
|
+ v = completion.Value;
|
|
|
+ }
|
|
|
|
|
|
- do
|
|
|
+ if (completion.Type != CompletionType.Continue || context.Target != _labelSetName)
|
|
|
{
|
|
|
- var completion = _body.Execute(context);
|
|
|
- if (!ReferenceEquals(completion.Value, null))
|
|
|
+ if (completion.Type == CompletionType.Break && (context.Target == null || context.Target == _labelSetName))
|
|
|
{
|
|
|
- v = completion.Value;
|
|
|
+ return new Completion(CompletionType.Normal, v, _statement);
|
|
|
}
|
|
|
|
|
|
- if (completion.Type != CompletionType.Continue || context.Target != _labelSetName)
|
|
|
+ if (completion.Type != CompletionType.Normal)
|
|
|
{
|
|
|
- if (completion.Type == CompletionType.Break && (context.Target == null || context.Target == _labelSetName))
|
|
|
- {
|
|
|
- return new Completion(CompletionType.Normal, v, _statement);
|
|
|
- }
|
|
|
-
|
|
|
- if (completion.Type != CompletionType.Normal)
|
|
|
- {
|
|
|
- return completion;
|
|
|
- }
|
|
|
+ return completion;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (context.DebugMode)
|
|
|
- {
|
|
|
- context.Engine.DebugHandler.OnStep(_test._expression);
|
|
|
- }
|
|
|
+ if (context.DebugMode)
|
|
|
+ {
|
|
|
+ context.Engine.DebugHandler.OnStep(_test._expression);
|
|
|
+ }
|
|
|
|
|
|
- iterating = TypeConverter.ToBoolean(_test.GetValue(context));
|
|
|
- } while (iterating);
|
|
|
+ iterating = TypeConverter.ToBoolean(_test.GetValue(context));
|
|
|
+ } while (iterating);
|
|
|
|
|
|
- return new Completion(CompletionType.Normal, v, ((JintStatement) this)._statement);
|
|
|
- }
|
|
|
+ return new Completion(CompletionType.Normal, v, ((JintStatement) this)._statement);
|
|
|
}
|
|
|
}
|