TypeArrayHelper.cs 725 B

123456789101112131415161718192021222324
  1. using Jint.Native.ArrayBuffer;
  2. using Jint.Runtime;
  3. namespace Jint.Native.TypedArray;
  4. internal static class TypeArrayHelper
  5. {
  6. internal static IntrinsicTypedArrayPrototype.TypedArrayWithBufferWitnessRecord ValidateTypedArray(this JsValue o, Realm realm, ArrayBufferOrder order = ArrayBufferOrder.Unordered)
  7. {
  8. if (o is not JsTypedArray typedArray)
  9. {
  10. Throw.TypeError(realm);
  11. return default;
  12. }
  13. var taRecord = IntrinsicTypedArrayPrototype.MakeTypedArrayWithBufferWitnessRecord(typedArray, order);
  14. if (taRecord.IsTypedArrayOutOfBounds)
  15. {
  16. Throw.TypeError(realm, "TypedArray is out of bounds");
  17. }
  18. return taRecord;
  19. }
  20. }