AsyncFunctionConstructor.cs 1.3 KB

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