|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|
using Esprima.Ast;
|
|
using Esprima.Ast;
|
|
using Jint.Native;
|
|
using Jint.Native;
|
|
using Jint.Native.Function;
|
|
using Jint.Native.Function;
|
|
-using Jint.Runtime.Interpreter.Statements;
|
|
|
|
|
|
+using Jint.Runtime.Interpreter.Expressions;
|
|
|
|
|
|
namespace Jint.Runtime.Interpreter
|
|
namespace Jint.Runtime.Interpreter
|
|
{
|
|
{
|
|
@@ -14,8 +14,9 @@ namespace Jint.Runtime.Interpreter
|
|
{
|
|
{
|
|
private readonly Engine _engine;
|
|
private readonly Engine _engine;
|
|
|
|
|
|
- private JintStatement _body;
|
|
|
|
-
|
|
|
|
|
|
+ private JintExpression _bodyExpression;
|
|
|
|
+ private JintStatementList _bodyStatementList;
|
|
|
|
+
|
|
public readonly string Name;
|
|
public readonly string Name;
|
|
public readonly bool Strict;
|
|
public readonly bool Strict;
|
|
public readonly IFunction Function;
|
|
public readonly IFunction Function;
|
|
@@ -47,21 +48,18 @@ namespace Jint.Runtime.Interpreter
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public JintStatement Body
|
|
|
|
|
|
+ internal Completion Execute()
|
|
{
|
|
{
|
|
- get
|
|
|
|
|
|
+ if (Function.Expression)
|
|
{
|
|
{
|
|
- if (_body != null)
|
|
|
|
- {
|
|
|
|
- return _body;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _body = Function.Expression
|
|
|
|
- ? (JintStatement) new JintReturnStatement(_engine, new ReturnStatement((Expression) Function.Body))
|
|
|
|
- : new JintBlockStatement(_engine, (BlockStatement) Function.Body);
|
|
|
|
-
|
|
|
|
- return _body;
|
|
|
|
|
|
+ _bodyExpression ??= JintExpression.Build(_engine, (Expression) Function.Body);
|
|
|
|
+ var jsValue = _bodyExpression?.GetValue() ?? Undefined.Instance;
|
|
|
|
+ return new Completion(CompletionType.Return, jsValue, null, Function.Body.Location);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ var blockStatement = (BlockStatement) Function.Body;
|
|
|
|
+ _bodyStatementList ??= new JintStatementList(_engine, blockStatement, blockStatement.Body);
|
|
|
|
+ return _bodyStatementList.Execute();
|
|
}
|
|
}
|
|
|
|
|
|
internal State Initialize(Engine engine, FunctionInstance functionInstance)
|
|
internal State Initialize(Engine engine, FunctionInstance functionInstance)
|