1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla Communicator client code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
44 * JS public API typedefs.
49 * Allow headers to reference JS::Value without #including the whole jsapi.h.
50 * Unfortunately, typedefs (hence jsval) cannot be declared.
53 namespace JS
{ class Value
; }
57 * In release builds, jsid is defined to be an integral type. This
58 * prevents many bugs from being caught at compile time. E.g.:
61 * if (id == JS_TRUE) // error
64 * size_t n = id; // error
66 * To catch more errors, jsid is given a struct type in C++ debug builds.
67 * Struct assignment and (in C++) operator== allow correct code to be mostly
68 * oblivious to the change. This feature can be explicitly disabled in debug
69 * builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES.
73 # if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES)
74 # define JS_USE_JSID_STRUCT_TYPES
77 # ifdef JS_USE_JSID_STRUCT_TYPES
81 bool operator==(jsid rhs
) const { return asBits
== rhs
.asBits
; }
82 bool operator!=(jsid rhs
) const { return asBits
!= rhs
.asBits
; }
84 # define JSID_BITS(id) (id.asBits)
85 # else /* defined(JS_USE_JSID_STRUCT_TYPES) */
86 typedef ptrdiff_t jsid
;
87 # define JSID_BITS(id) (id)
88 # endif /* defined(JS_USE_JSID_STRUCT_TYPES) */
89 #else /* defined(__cplusplus) */
90 typedef ptrdiff_t jsid
;
91 # define JSID_BITS(id) (id)
97 typedef wchar_t jschar
;
99 typedef uint16_t jschar
;
103 * Run-time version enumeration. See jsversion.h for compile-time counterparts
104 * to these values that may be selected by the JS_VERSION macro, and tested by
107 typedef enum JSVersion
{
113 JSVERSION_ECMA_3
= 148,
118 JSVERSION_ECMA_5
= 185,
119 JSVERSION_DEFAULT
= 0,
120 JSVERSION_UNKNOWN
= -1,
121 JSVERSION_LATEST
= JSVERSION_ECMA_5
124 #define JSVERSION_IS_ECMA(version) \
125 ((version) == JSVERSION_DEFAULT || (version) >= JSVERSION_1_3)
127 /* Result of typeof operator enumeration. */
128 typedef enum JSType
{
129 JSTYPE_VOID
, /* undefined */
130 JSTYPE_OBJECT
, /* object */
131 JSTYPE_FUNCTION
, /* function */
132 JSTYPE_STRING
, /* string */
133 JSTYPE_NUMBER
, /* number */
134 JSTYPE_BOOLEAN
, /* boolean */
135 JSTYPE_NULL
, /* null */
136 JSTYPE_XML
, /* xml object */
140 /* Dense index into cached prototypes and class atoms for standard objects. */
141 typedef enum JSProtoKey
{
142 #define JS_PROTO(name,code,init) JSProto_##name = code,
143 #include "jsproto.tbl"
148 /* js_CheckAccess mode enumeration. */
149 typedef enum JSAccessMode
{
150 JSACC_PROTO
= 0, /* XXXbe redundant w.r.t. id */
151 JSACC_PARENT
= 1, /* XXXbe redundant w.r.t. id */
154 * enum value #2 formerly called JSACC_IMPORT,
155 * gap preserved for ABI compatibility.
158 JSACC_WATCH
= 3, /* a watchpoint on object foo for id 'bar' */
159 JSACC_READ
= 4, /* a "get" of foo.bar */
160 JSACC_WRITE
= 8, /* a "set" of foo.bar = baz */
164 #define JSACC_TYPEMASK (JSACC_WRITE - 1)
167 * This enum type is used to control the behavior of a JSObject property
168 * iterator function that has type JSNewEnumerate.
170 typedef enum JSIterateOp
{
171 /* Create new iterator state over enumerable properties. */
174 /* Create new iterator state over all properties. */
175 JSENUMERATE_INIT_ALL
,
180 /* Destroy iterator state. */
184 /* See JSVAL_TRACE_KIND and JSTraceCallback in jsapi.h. */
191 * Trace kinds internal to the engine. The embedding can only them if it
192 * implements JSTraceCallback.
194 #if JS_HAS_XML_SUPPORT
200 JSTRACE_LAST
= JSTRACE_TYPE_OBJECT
203 /* Struct typedefs. */
204 typedef struct JSClass JSClass
;
205 typedef struct JSCompartment JSCompartment
;
206 typedef struct JSConstDoubleSpec JSConstDoubleSpec
;
207 typedef struct JSContext JSContext
;
208 typedef struct JSCrossCompartmentCall JSCrossCompartmentCall
;
209 typedef struct JSErrorReport JSErrorReport
;
210 typedef struct JSExceptionState JSExceptionState
;
211 typedef struct JSFunction JSFunction
;
212 typedef struct JSFunctionSpec JSFunctionSpec
;
213 typedef struct JSIdArray JSIdArray
;
214 typedef struct JSLocaleCallbacks JSLocaleCallbacks
;
215 typedef struct JSObject JSObject
;
216 typedef struct JSObjectMap JSObjectMap
;
217 typedef struct JSPrincipals JSPrincipals
;
218 typedef struct JSPropertyDescriptor JSPropertyDescriptor
;
219 typedef struct JSPropertyName JSPropertyName
;
220 typedef struct JSPropertySpec JSPropertySpec
;
221 typedef struct JSRuntime JSRuntime
;
222 typedef struct JSSecurityCallbacks JSSecurityCallbacks
;
223 typedef struct JSStackFrame JSStackFrame
;
224 typedef struct JSScript JSScript
;
225 typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks
;
226 typedef struct JSStructuredCloneReader JSStructuredCloneReader
;
227 typedef struct JSStructuredCloneWriter JSStructuredCloneWriter
;
228 typedef struct JSTracer JSTracer
;
234 typedef struct JSFlatString JSFlatString
;
235 typedef struct JSString JSString
;
236 #endif /* !__cplusplus */
239 typedef struct PRCallOnceType JSCallOnceType
;
241 typedef JSBool JSCallOnceType
;
243 typedef JSBool (*JSInitCallback
)(void);
251 template <typename T
>
260 THING_ROOT_BASE_SHAPE
,
261 THING_ROOT_TYPE_OBJECT
,
270 struct ContextFriendFields
{
271 JSRuntime
*const runtime
;
273 ContextFriendFields(JSRuntime
*rt
)
276 static const ContextFriendFields
*get(const JSContext
*cx
) {
277 return reinterpret_cast<const ContextFriendFields
*>(cx
);
280 static ContextFriendFields
*get(JSContext
*cx
) {
281 return reinterpret_cast<ContextFriendFields
*>(cx
);
284 #ifdef JSGC_ROOT_ANALYSIS
287 * Stack allocated GC roots for stack GC heap pointers, which may be
288 * overwritten if moved during a GC.
290 Root
<void*> *thingGCRooters
[THING_ROOT_LIMIT
];
294 * Stack allocated list of stack locations which hold non-relocatable
295 * GC heap pointers (where the target is rooted somewhere else) or integer
296 * values which may be confused for GC heap pointers. These are used to
297 * suppress false positives which occur when a rooting analysis treats the
298 * location as holding a relocatable pointer, but have no other effect on
301 SkipRoot
*skipGCRooters
;
304 #endif /* JSGC_ROOT_ANALYSIS */
309 #endif /* __cplusplus */
311 #endif /* jspubtd_h___ */