GeneratorFunctionConstructor.cs 1.5 KB

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