summaryrefslogtreecommitdiffstats
path: root/js/src/jspubtd.h
blob: 64f2329c69f3d4e02b2e210e5f30a401d68c3288 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * 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 jspubtd_h
#define jspubtd_h

/*
 * JS public API typedefs.
 */

#include "mozilla/Assertions.h"  // MOZ_ASSERT_UNREACHABLE

#include "jstypes.h"

#include "js/ProtoKey.h"
#include "js/Result.h"
#include "js/TraceKind.h"
#include "js/TypeDecls.h"

#if defined(JS_GC_ZEAL) || defined(DEBUG)
#  define JSGC_HASH_TABLE_CHECKS
#endif

namespace JS {

class CallArgs;

class JS_PUBLIC_API RealmOptions;

}  // namespace JS

/* Result of typeof operator enumeration. */
enum JSType {
  JSTYPE_UNDEFINED, /* undefined */
  JSTYPE_OBJECT,    /* object */
  JSTYPE_FUNCTION,  /* function */
  JSTYPE_STRING,    /* string */
  JSTYPE_NUMBER,    /* number */
  JSTYPE_BOOLEAN,   /* boolean */
  JSTYPE_SYMBOL,    /* symbol */
  JSTYPE_BIGINT,    /* bigint */
#ifdef ENABLE_RECORD_TUPLE
  JSTYPE_RECORD, /* record */
  JSTYPE_TUPLE,  /* tuple */
#endif
  JSTYPE_LIMIT
};

inline const char* JSTypeToString(JSType type) {
  switch (type) {
    case JSTYPE_UNDEFINED:
      return "undefined";
    case JSTYPE_OBJECT:
      return "object";
    case JSTYPE_FUNCTION:
      return "function";
    case JSTYPE_STRING:
      return "string";
    case JSTYPE_NUMBER:
      return "number";
    case JSTYPE_BOOLEAN:
      return "boolean";
    case JSTYPE_SYMBOL:
      return "symbol";
    case JSTYPE_BIGINT:
      return "bigint";
#ifdef ENABLE_RECORD_TUPLE
    case JSTYPE_RECORD:
      return "record";
    case JSTYPE_TUPLE:
      return "tuple";
#endif
    default:
      MOZ_ASSERT_UNREACHABLE("Unknown JSType");
  }
  return "";
}

/* Dense index into cached prototypes and class atoms for standard objects. */
enum JSProtoKey {
#define PROTOKEY_AND_INITIALIZER(name, clasp) JSProto_##name,
  JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER)
#undef PROTOKEY_AND_INITIALIZER
      JSProto_LIMIT
};

/* Struct forward declarations. */
struct JSClass;
class JSErrorReport;
struct JSFunctionSpec;
struct JSPrincipals;
struct JSPropertySpec;
struct JSSecurityCallbacks;
struct JSStructuredCloneCallbacks;
struct JSStructuredCloneReader;
struct JSStructuredCloneWriter;
class JS_PUBLIC_API JSTracer;

class JSLinearString;

template <typename T>
struct JSConstScalarSpec;
using JSConstDoubleSpec = JSConstScalarSpec<double>;
using JSConstIntegerSpec = JSConstScalarSpec<int32_t>;

namespace js {

inline JS::Realm* GetContextRealm(const JSContext* cx);
inline JS::Compartment* GetContextCompartment(const JSContext* cx);
inline JS::Zone* GetContextZone(const JSContext* cx);

// Whether the current thread is permitted access to any part of the specified
// runtime or zone.
JS_PUBLIC_API bool CurrentThreadCanAccessRuntime(const JSRuntime* rt);

#ifdef DEBUG
JS_PUBLIC_API bool CurrentThreadIsMainThread();
JS_PUBLIC_API bool CurrentThreadIsPerformingGC();
#endif

}  // namespace js

namespace JS {

class JS_PUBLIC_API PropertyDescriptor;

// Decorates the Unlinking phase of CycleCollection so that accidental use
// of barriered accessors results in assertions instead of leaks.
class MOZ_STACK_CLASS JS_PUBLIC_API AutoEnterCycleCollection {
#ifdef DEBUG
  JSRuntime* runtime_;

 public:
  explicit AutoEnterCycleCollection(JSRuntime* rt);
  ~AutoEnterCycleCollection();
#else
 public:
  explicit AutoEnterCycleCollection(JSRuntime* rt) {}
  ~AutoEnterCycleCollection() {}
#endif
};

} /* namespace JS */

extern "C" {

// Defined in NSPR prio.h.
using PRFileDesc = struct PRFileDesc;
}

#endif /* jspubtd_h */