1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sts=2 et sw=2 tw=80:
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 // This file contains public type declarations that are used *frequently*.  If
8 // it doesn't occur at least 10 times in Gecko, it probably shouldn't be in
9 // here.
10 //
11 // It includes only:
12 // - forward declarations of structs and classes;
13 // - typedefs;
14 // - enums (maybe).
15 // It does *not* contain any struct or class definitions.
16 
17 #ifndef js_TypeDecls_h
18 #define js_TypeDecls_h
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #include "jstypes.h"
24 
25 typedef uint8_t jsbytecode;
26 
27 class JS_PUBLIC_API JSAtom;
28 struct JS_PUBLIC_API JSContext;
29 struct JSClass;
30 class JS_PUBLIC_API JSFunction;
31 class JS_PUBLIC_API JSFreeOp;
32 class JS_PUBLIC_API JSObject;
33 struct JS_PUBLIC_API JSRuntime;
34 class JS_PUBLIC_API JSScript;
35 class JS_PUBLIC_API JSString;
36 
37 struct JSPrincipals;
38 
39 namespace js {
40 class JS_PUBLIC_API TempAllocPolicy;
41 };  // namespace js
42 
43 namespace JS {
44 
45 class JS_PUBLIC_API PropertyKey;
46 
47 typedef unsigned char Latin1Char;
48 
49 class JS_PUBLIC_API Symbol;
50 class JS_PUBLIC_API BigInt;
51 #ifdef ENABLE_RECORD_TUPLE
52 class JS_PUBLIC_API RecordType;
53 class JS_PUBLIC_API TupleType;
54 #endif
55 class JS_PUBLIC_API Value;
56 
57 class JS_PUBLIC_API Compartment;
58 class JS_PUBLIC_API Realm;
59 struct JS_PUBLIC_API Runtime;
60 class JS_PUBLIC_API Zone;
61 
62 template <typename T>
63 class Handle;
64 template <typename T>
65 class MutableHandle;
66 template <typename T>
67 class Rooted;
68 template <typename T>
69 class PersistentRooted;
70 template <typename T>
71 class RootedVector;
72 template <typename T>
73 class PersistentRootedVector;
74 template <typename T, typename AllocPolicy = js::TempAllocPolicy>
75 class StackGCVector;
76 
77 typedef Handle<JSFunction*> HandleFunction;
78 typedef Handle<PropertyKey> HandleId;
79 typedef Handle<JSObject*> HandleObject;
80 typedef Handle<JSScript*> HandleScript;
81 typedef Handle<JSString*> HandleString;
82 typedef Handle<JS::Symbol*> HandleSymbol;
83 typedef Handle<JS::BigInt*> HandleBigInt;
84 typedef Handle<Value> HandleValue;
85 typedef Handle<StackGCVector<Value>> HandleValueVector;
86 typedef Handle<StackGCVector<JSObject*>> HandleObjectVector;
87 typedef Handle<StackGCVector<JS::PropertyKey>> HandleIdVector;
88 
89 typedef MutableHandle<JSFunction*> MutableHandleFunction;
90 typedef MutableHandle<PropertyKey> MutableHandleId;
91 typedef MutableHandle<JSObject*> MutableHandleObject;
92 typedef MutableHandle<JSScript*> MutableHandleScript;
93 typedef MutableHandle<JSString*> MutableHandleString;
94 typedef MutableHandle<JS::Symbol*> MutableHandleSymbol;
95 typedef MutableHandle<JS::BigInt*> MutableHandleBigInt;
96 typedef MutableHandle<Value> MutableHandleValue;
97 typedef MutableHandle<StackGCVector<Value>> MutableHandleValueVector;
98 typedef MutableHandle<StackGCVector<JSObject*>> MutableHandleObjectVector;
99 typedef MutableHandle<StackGCVector<JS::PropertyKey>> MutableHandleIdVector;
100 
101 typedef Rooted<JSObject*> RootedObject;
102 typedef Rooted<JSFunction*> RootedFunction;
103 typedef Rooted<JSScript*> RootedScript;
104 typedef Rooted<JSString*> RootedString;
105 typedef Rooted<JS::Symbol*> RootedSymbol;
106 typedef Rooted<JS::BigInt*> RootedBigInt;
107 typedef Rooted<PropertyKey> RootedId;
108 typedef Rooted<JS::Value> RootedValue;
109 
110 typedef RootedVector<JS::Value> RootedValueVector;
111 typedef RootedVector<JSObject*> RootedObjectVector;
112 typedef RootedVector<JS::PropertyKey> RootedIdVector;
113 
114 typedef PersistentRooted<JSFunction*> PersistentRootedFunction;
115 typedef PersistentRooted<PropertyKey> PersistentRootedId;
116 typedef PersistentRooted<JSObject*> PersistentRootedObject;
117 typedef PersistentRooted<JSScript*> PersistentRootedScript;
118 typedef PersistentRooted<JSString*> PersistentRootedString;
119 typedef PersistentRooted<JS::Symbol*> PersistentRootedSymbol;
120 typedef PersistentRooted<JS::BigInt*> PersistentRootedBigInt;
121 typedef PersistentRooted<Value> PersistentRootedValue;
122 
123 typedef PersistentRootedVector<PropertyKey> PersistentRootedIdVector;
124 typedef PersistentRootedVector<JSObject*> PersistentRootedObjectVector;
125 
126 template <typename T>
127 using HandleVector = Handle<StackGCVector<T>>;
128 template <typename T>
129 using MutableHandleVector = MutableHandle<StackGCVector<T>>;
130 }  // namespace JS
131 
132 using jsid = JS::PropertyKey;
133 
134 #ifdef ENABLE_RECORD_TUPLE
135 // This takes 1 or 2 parameters. ... is just used so that
136 // it's possible to omit the comma when passing a single
137 // param:
138 //     IF_RECORD_TUPLE(doThis)
139 //     IF_RECORD_TUPLE(doThis, elseThis)
140 #  define IF_RECORD_TUPLE(x, ...) x
141 #else
142 #  define IF_RECORD_TUPLE(x, ...) __VA_ARGS__
143 #endif
144 
145 // Follows the same pattern as IF_RECORD_TUPLE
146 #ifndef MOZ_DOM_STREAMS
147 #  define IF_JS_STREAMS(x, ...) x
148 #else
149 #  define IF_JS_STREAMS(x, ...) __VA_ARGS__
150 #endif
151 
152 #endif /* js_TypeDecls_h */
153