DisposableStackConstructor.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Jint.Native.Object;
  2. using Jint.Runtime;
  3. using Jint.Runtime.Descriptors;
  4. namespace Jint.Native.Disposable;
  5. internal sealed class DisposableStackConstructor : Constructor
  6. {
  7. private static readonly JsString _name = new("DisposableStack");
  8. public DisposableStackConstructor(Engine engine, Realm realm) : base(engine, realm, _name)
  9. {
  10. PrototypeObject = new DisposableStackPrototype(engine, realm, this, engine.Intrinsics.Object.PrototypeObject);
  11. _length = new PropertyDescriptor(0, PropertyFlag.Configurable);
  12. _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
  13. }
  14. internal DisposableStackPrototype PrototypeObject { get; }
  15. public override ObjectInstance Construct(JsCallArguments arguments, JsValue newTarget)
  16. {
  17. if (newTarget.IsUndefined())
  18. {
  19. ExceptionHelper.ThrowTypeError(_realm);
  20. }
  21. var stack = OrdinaryCreateFromConstructor(
  22. newTarget,
  23. static intrinsics => intrinsics.DisposableStack.PrototypeObject,
  24. static (Engine engine, Realm _, object? _) => new DisposableStack(engine, DisposeHint.Sync));
  25. return stack;
  26. }
  27. }