TypedArrayPrototype.cs 1.1 KB

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