summaryrefslogtreecommitdiff
path: root/js/src/vm/BigIntType.h
blob: 3c5768e818ef6da84e471e716189f60e5cba19cf (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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef vm_BigIntType_h
#define vm_BigIntType_h

#include "gc/Barrier.h"
#include "gc/Marking.h"
#include "gc/Heap.h"
#include "js/GCHashTable.h"
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
#include "vm/String.h"

namespace JS {

class BigInt final : public js::gc::TenuredCell
{
  private:
    // The minimum allocation size is currently 16 bytes (see
    // SortedArenaList in gc/ArenaList.h).
    uint8_t unused_[16 + (16 % js::gc::CellSize)];

  public:
    // Allocate and initialize a BigInt value
    static BigInt* create(js::ExclusiveContext* cx);

    static const JS::TraceKind TraceKind = JS::TraceKind::BigInt;

    void traceChildren(JSTracer* trc);

    void finalize(js::FreeOp* fop);

    js::HashNumber hash();

    size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;

    static JSLinearString* toString(js::ExclusiveContext* cx, BigInt* x);
    bool toBoolean();

    static BigInt* copy(js::ExclusiveContext* cx, Handle<BigInt*> x);
};

static_assert(sizeof(BigInt) >= js::gc::CellSize,
              "sizeof(BigInt) must be greater than the minimum allocation size");

} // namespace JS

namespace js {

extern JSAtom*
BigIntToAtom(ExclusiveContext* cx, JS::BigInt* bi);

} // namespace js

#endif