summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/wtf/typed_arrays/bigint64_array.h
blob: 07a52592e1d440a6d5771f47f42936b998ac835b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_BIGINT64_ARRAY_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_BIGINT64_ARRAY_H_

#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/typed_arrays/typed_array_base.h"

namespace WTF {

class BigInt64Array final : public TypedArrayBase<int64_t> {
 public:
  static inline scoped_refptr<BigInt64Array> Create(unsigned length);
  static inline scoped_refptr<BigInt64Array> Create(const int64_t* array,
                                                    unsigned length);
  static inline scoped_refptr<BigInt64Array> Create(scoped_refptr<ArrayBuffer>,
                                                    unsigned byte_offset,
                                                    unsigned length);

  // Should only be used when it is known the entire array will be filled. Do
  // not return these results directly to JavaScript without filling first.
  static inline scoped_refptr<BigInt64Array> CreateUninitialized(
      unsigned length);

  using TypedArrayBase<int64_t>::Set;

  void Set(unsigned index, int64_t value) {
    if (index >= TypedArrayBase<int64_t>::length_)
      return;
    TypedArrayBase<int64_t>::Data()[index] = value;
  }

  ViewType GetType() const override { return kTypeBigInt64; }

 private:
  inline BigInt64Array(scoped_refptr<ArrayBuffer>,
                       unsigned byte_offset,
                       unsigned length);
  // Make constructor visible to superclass.
  friend class TypedArrayBase<int64_t>;
};

scoped_refptr<BigInt64Array> BigInt64Array::Create(unsigned length) {
  return TypedArrayBase<int64_t>::Create<BigInt64Array>(length);
}

scoped_refptr<BigInt64Array> BigInt64Array::Create(const int64_t* array,
                                                   unsigned length) {
  return TypedArrayBase<int64_t>::Create<BigInt64Array>(array, length);
}

scoped_refptr<BigInt64Array> BigInt64Array::Create(
    scoped_refptr<ArrayBuffer> buffer,
    unsigned byte_offset,
    unsigned length) {
  return TypedArrayBase<int64_t>::Create<BigInt64Array>(std::move(buffer),
                                                        byte_offset, length);
}

BigInt64Array::BigInt64Array(scoped_refptr<ArrayBuffer> buffer,
                             unsigned byte_offset,
                             unsigned length)
    : TypedArrayBase<int64_t>(std::move(buffer), byte_offset, length) {}

}  // namespace WTF

using WTF::BigInt64Array;

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_BIGINT64_ARRAY_H_