TypedArrayPrototype.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Jint.Collections;
  2. using Jint.Native.Array;
  3. using Jint.Native.Object;
  4. using Jint.Runtime;
  5. using Jint.Runtime.Descriptors;
  6. using Jint.Runtime.Interop;
  7. namespace Jint.Native.TypedArray;
  8. /// <summary>
  9. /// https://tc39.es/ecma262/#sec-properties-of-typedarray-prototype-objects
  10. /// </summary>
  11. internal sealed class TypedArrayPrototype : Prototype
  12. {
  13. private readonly TypedArrayConstructor _constructor;
  14. private readonly TypedArrayElementType _arrayElementType;
  15. internal TypedArrayPrototype(
  16. Engine engine,
  17. IntrinsicTypedArrayPrototype objectPrototype,
  18. TypedArrayConstructor constructor,
  19. TypedArrayElementType type) : base(engine, engine.Realm)
  20. {
  21. _prototype = objectPrototype;
  22. _constructor = constructor;
  23. _arrayElementType = type;
  24. }
  25. protected override void Initialize()
  26. {
  27. var properties = new PropertyDictionary(2, false)
  28. {
  29. ["BYTES_PER_ELEMENT"] = new(JsNumber.Create(_arrayElementType.GetElementSize()), PropertyFlag.AllForbidden),
  30. ["constructor"] = new(_constructor, PropertyFlag.NonEnumerable),
  31. };
  32. SetProperties(properties);
  33. }
  34. }