AsyncFunctionConstructor.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 : FunctionInstance, IConstructor
  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, JsValue[] arguments)
  21. {
  22. return Construct(arguments, thisObject);
  23. }
  24. ObjectInstance IConstructor.Construct(JsValue[] arguments, JsValue newTarget) => Construct(arguments, newTarget);
  25. private ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
  26. {
  27. var function = CreateDynamicFunction(
  28. this,
  29. newTarget,
  30. FunctionKind.Async,
  31. arguments);
  32. return function;
  33. }
  34. }