JintConstantExpression.cs 833 B

12345678910111213141516171819202122232425262728
  1. using Esprima.Ast;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Interpreter.Expressions
  4. {
  5. /// <summary>
  6. /// Constant JsValue returning expression.
  7. /// </summary>
  8. internal sealed class JintConstantExpression : JintExpression
  9. {
  10. private readonly JsValue _value;
  11. public JintConstantExpression(Expression expression, JsValue value) : base(expression)
  12. {
  13. _value = value;
  14. }
  15. public override Completion GetValue(EvaluationContext context)
  16. {
  17. // need to notify correct node when taking shortcut
  18. context.LastSyntaxElement = _expression;
  19. return new(CompletionType.Normal, _value, _expression);
  20. }
  21. protected override ExpressionResult EvaluateInternal(EvaluationContext context) => NormalCompletion(_value);
  22. }
  23. }