1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jspubtd_h
8 #define jspubtd_h
9
10 /*
11 * JS public API typedefs.
12 */
13
14 #include "mozilla/Assertions.h"
15 #include "mozilla/EnumeratedArray.h"
16 #include "mozilla/LinkedList.h"
17 #include "mozilla/PodOperations.h"
18
19 #include "jstypes.h"
20
21 #include "js/ProtoKey.h"
22 #include "js/Result.h"
23 #include "js/TraceKind.h"
24 #include "js/TypeDecls.h"
25
26 #if defined(JS_GC_ZEAL) || defined(DEBUG)
27 #define JSGC_HASH_TABLE_CHECKS
28 #endif
29
30 namespace JS {
31
32 template <typename T>
33 class AutoVector;
34 using AutoIdVector = AutoVector<jsid>;
35 using AutoValueVector = AutoVector<Value>;
36 using AutoObjectVector = AutoVector<JSObject*>;
37
38 class CallArgs;
39
40 class JS_FRIEND_API CompileOptions;
41 class JS_FRIEND_API ReadOnlyCompileOptions;
42 class JS_FRIEND_API OwningCompileOptions;
43 class JS_FRIEND_API TransitiveCompileOptions;
44 class JS_PUBLIC_API CompartmentOptions;
45
46 } // namespace JS
47
48 /* Result of typeof operator enumeration. */
49 enum JSType {
50 JSTYPE_UNDEFINED, /* undefined */
51 JSTYPE_OBJECT, /* object */
52 JSTYPE_FUNCTION, /* function */
53 JSTYPE_STRING, /* string */
54 JSTYPE_NUMBER, /* number */
55 JSTYPE_BOOLEAN, /* boolean */
56 JSTYPE_NULL, /* null */
57 JSTYPE_SYMBOL, /* symbol */
58 JSTYPE_LIMIT
59 };
60
61 /* Dense index into cached prototypes and class atoms for standard objects. */
62 enum JSProtoKey {
63 #define PROTOKEY_AND_INITIALIZER(name, init, clasp) JSProto_##name,
64 JS_FOR_EACH_PROTOTYPE(PROTOKEY_AND_INITIALIZER)
65 #undef PROTOKEY_AND_INITIALIZER
66 JSProto_LIMIT
67 };
68
69 /* Struct forward declarations. */
70 struct JSClass;
71 class JSErrorReport;
72 struct JSExceptionState;
73 struct JSFunctionSpec;
74 struct JSLocaleCallbacks;
75 struct JSPrincipals;
76 struct JSPropertySpec;
77 struct JSSecurityCallbacks;
78 struct JSStructuredCloneCallbacks;
79 struct JSStructuredCloneReader;
80 struct JSStructuredCloneWriter;
81 class JS_PUBLIC_API JSTracer;
82
83 class JSFlatString;
84
85 typedef bool (*JSInitCallback)(void);
86
87 template <typename T>
88 struct JSConstScalarSpec;
89 typedef JSConstScalarSpec<double> JSConstDoubleSpec;
90 typedef JSConstScalarSpec<int32_t> JSConstIntegerSpec;
91
92 namespace js {
93 namespace gc {
94 class AutoTraceSession;
95 class StoreBuffer;
96 } // namespace gc
97
98 class CooperatingContext;
99
100 inline JSCompartment* GetContextCompartment(const JSContext* cx);
101 inline JS::Zone* GetContextZone(const JSContext* cx);
102
103 // Whether the current thread is permitted access to any part of the specified
104 // runtime or zone.
105 JS_FRIEND_API bool CurrentThreadCanAccessRuntime(const JSRuntime* rt);
106
107 #ifdef DEBUG
108 JS_FRIEND_API bool CurrentThreadIsPerformingGC();
109 #endif
110
111 } // namespace js
112
113 namespace JS {
114
115 class JS_PUBLIC_API AutoEnterCycleCollection;
116 class JS_PUBLIC_API AutoAssertOnBarrier;
117 struct JS_PUBLIC_API PropertyDescriptor;
118
119 typedef void (*OffThreadCompileCallback)(void* token, void* callbackData);
120
121 enum class HeapState {
122 Idle, // doing nothing with the GC heap
123 Tracing, // tracing the GC heap without collecting, e.g.
124 // IterateCompartments()
125 MajorCollecting, // doing a GC of the major heap
126 MinorCollecting, // doing a GC of the minor heap (nursery)
127 CycleCollecting // in the "Unlink" phase of cycle collection
128 };
129
130 JS_PUBLIC_API HeapState CurrentThreadHeapState();
131
CurrentThreadIsHeapBusy()132 static inline bool CurrentThreadIsHeapBusy() {
133 return CurrentThreadHeapState() != HeapState::Idle;
134 }
135
CurrentThreadIsHeapTracing()136 static inline bool CurrentThreadIsHeapTracing() {
137 return CurrentThreadHeapState() == HeapState::Tracing;
138 }
139
CurrentThreadIsHeapMajorCollecting()140 static inline bool CurrentThreadIsHeapMajorCollecting() {
141 return CurrentThreadHeapState() == HeapState::MajorCollecting;
142 }
143
CurrentThreadIsHeapMinorCollecting()144 static inline bool CurrentThreadIsHeapMinorCollecting() {
145 return CurrentThreadHeapState() == HeapState::MinorCollecting;
146 }
147
CurrentThreadIsHeapCollecting()148 static inline bool CurrentThreadIsHeapCollecting() {
149 HeapState state = CurrentThreadHeapState();
150 return state == HeapState::MajorCollecting ||
151 state == HeapState::MinorCollecting;
152 }
153
CurrentThreadIsHeapCycleCollecting()154 static inline bool CurrentThreadIsHeapCycleCollecting() {
155 return CurrentThreadHeapState() == HeapState::CycleCollecting;
156 }
157
158 // Decorates the Unlinking phase of CycleCollection so that accidental use
159 // of barriered accessors results in assertions instead of leaks.
160 class MOZ_STACK_CLASS JS_PUBLIC_API AutoEnterCycleCollection {
161 #ifdef DEBUG
162 public:
163 explicit AutoEnterCycleCollection(JSRuntime* rt);
164 ~AutoEnterCycleCollection();
165 #else
166 public:
167 explicit AutoEnterCycleCollection(JSRuntime* rt) {}
168 ~AutoEnterCycleCollection() {}
169 #endif
170 };
171
172 } /* namespace JS */
173
174 MOZ_BEGIN_EXTERN_C
175
176 // Defined in NSPR prio.h.
177 typedef struct PRFileDesc PRFileDesc;
178
179 MOZ_END_EXTERN_C
180
181 #endif /* jspubtd_h */
182