TypedArrayPrototype.cs 1.2 KB

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