TypedArrayPrototype.cs 1.0 KB

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