JintLogicalAndExpression.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Esprima.Ast;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Interpreter.Expressions
  4. {
  5. internal sealed class JintLogicalAndExpression : JintExpression
  6. {
  7. private JintExpression _left;
  8. private JintExpression _right;
  9. public JintLogicalAndExpression(BinaryExpression expression) : base(expression)
  10. {
  11. _initialized = false;
  12. }
  13. protected override void Initialize(EvaluationContext context)
  14. {
  15. var expression = (BinaryExpression) _expression;
  16. _left = Build(context.Engine, expression.Left);
  17. _right = Build(context.Engine, expression.Right);
  18. }
  19. protected override ExpressionResult EvaluateInternal(EvaluationContext context)
  20. {
  21. var left = _left.GetValue(context).Value;
  22. if (left is JsBoolean b && !b._value)
  23. {
  24. return NormalCompletion(b);
  25. }
  26. if (!TypeConverter.ToBoolean(left))
  27. {
  28. return NormalCompletion(left);
  29. }
  30. return _right.GetValue(context);
  31. }
  32. }
  33. }