JintConstantExpression.cs 945 B

123456789101112131415161718192021222324252627282930313233
  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(Engine engine, Expression expression, JsValue value) : base(engine, expression)
  12. {
  13. _value = value;
  14. }
  15. /// <summary>
  16. /// Resolves the underlying value for this expression.
  17. /// By default uses the Engine for resolving.
  18. /// </summary>
  19. /// <seealso cref="JintLiteralExpression"/>
  20. public override JsValue GetValue()
  21. {
  22. // need to notify correct node when taking shortcut
  23. _engine._lastSyntaxNode = _expression;
  24. return _value;
  25. }
  26. protected override object EvaluateInternal() => _value;
  27. }
  28. }