AsyncGeneratorFunctionConstructor.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Jint.Native.AsyncFunction;
  2. using Jint.Native.Function;
  3. using Jint.Native.Iterator;
  4. using Jint.Native.Object;
  5. using Jint.Runtime;
  6. using Jint.Runtime.Descriptors;
  7. namespace Jint.Native.Generator;
  8. /// <summary>
  9. /// https://tc39.es/ecma262/#sec-asyncgeneratorfunction-constructor
  10. /// </summary>
  11. internal sealed class AsyncGeneratorFunctionConstructor : Constructor
  12. {
  13. private static readonly JsString _functionName = new("AsyncGeneratorFunction");
  14. internal AsyncGeneratorFunctionConstructor(
  15. Engine engine,
  16. Realm realm,
  17. AsyncFunctionPrototype prototype,
  18. IteratorPrototype iteratorPrototype)
  19. : base(engine, realm, _functionName)
  20. {
  21. PrototypeObject = new AsyncGeneratorFunctionPrototype(engine, this, prototype, iteratorPrototype);
  22. _prototype = PrototypeObject;
  23. _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
  24. _length = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable);
  25. }
  26. public AsyncGeneratorFunctionPrototype PrototypeObject { get; }
  27. protected internal override JsValue Call(JsValue thisObject, JsCallArguments arguments)
  28. {
  29. return Construct(arguments, thisObject);
  30. }
  31. public override ObjectInstance Construct(JsCallArguments arguments, JsValue newTarget)
  32. {
  33. var function = _realm.Intrinsics.Function.CreateDynamicFunction(
  34. this,
  35. newTarget,
  36. FunctionKind.AsyncGenerator,
  37. arguments);
  38. return function;
  39. }
  40. }