JintClassDeclarationStatement.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #nullable enable
  2. using Esprima.Ast;
  3. using Jint.Native.Function;
  4. namespace Jint.Runtime.Interpreter.Statements
  5. {
  6. internal sealed class JintClassDeclarationStatement : JintStatement<ClassDeclaration>
  7. {
  8. private readonly ClassDefinition _classDefinition;
  9. public JintClassDeclarationStatement(Engine engine, ClassDeclaration classDeclaration) : base(engine, classDeclaration)
  10. {
  11. _classDefinition = new ClassDefinition(className: classDeclaration.Id, classDeclaration.SuperClass, classDeclaration.Body);
  12. }
  13. protected override Completion ExecuteInternal()
  14. {
  15. var env = _engine.ExecutionContext.LexicalEnvironment;
  16. var F = _classDefinition.BuildConstructor(_engine, env);
  17. var classBinding = _classDefinition._className;
  18. if (classBinding != null)
  19. {
  20. env.CreateMutableBinding(classBinding);
  21. env.InitializeBinding(classBinding, F);
  22. }
  23. return new Completion(CompletionType.Normal, null, null, Location);
  24. }
  25. }
  26. }