Backed out changeset 7b2b90efe57d -- the patch was landed against a tree with a lot...
[mozilla-central.git] / js / src / jsprvtd.h
blob220c35836133854d3bc8148e68feafd55e5d2a39
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
14 * License.
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
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.
24 * Contributor(s):
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 ***** */
40 #ifndef jsprvtd_h___
41 #define jsprvtd_h___
43 * JS private typename definitions.
45 * This header is included only in other .h files, for convenience and for
46 * simplicity of type naming. The alternative for structures is to use tags,
47 * which are named the same as their typedef names (legal in C/C++, and less
48 * noisy than suffixing the typedef name with "Struct" or "Str"). Instead,
49 * all .h files that include this file may use the same typedef name, whether
50 * declaring a pointer to struct type, or defining a member of struct type.
52 * A few fundamental scalar types are defined here too. Neither the scalar
53 * nor the struct typedefs should change much, therefore the nearly-global
54 * make dependency induced by this file should not prove painful.
57 #include "jspubtd.h"
58 #include "jsutil.h"
60 JS_BEGIN_EXTERN_C
63 * Convenience constants.
65 #define JS_BITS_PER_UINT32_LOG2 5
66 #define JS_BITS_PER_UINT32 32
68 /* The alignment required of objects stored in GC arenas. */
69 static const uintN JS_GCTHING_ALIGN = 8;
70 static const uintN JS_GCTHING_ZEROBITS = 3;
72 /* Scalar typedefs. */
73 typedef uint8 jsbytecode;
74 typedef uint8 jssrcnote;
75 typedef uint32 jsatomid;
77 #ifdef __cplusplus
79 /* Class and struct forward declarations in namespace js. */
80 extern "C++" {
81 namespace js {
82 struct Parser;
83 struct Compiler;
87 #endif
89 /* Struct typedefs. */
90 typedef struct JSArgumentFormatMap JSArgumentFormatMap;
91 typedef struct JSCodeGenerator JSCodeGenerator;
92 typedef struct JSGCThing JSGCThing;
93 typedef struct JSGenerator JSGenerator;
94 typedef struct JSNativeEnumerator JSNativeEnumerator;
95 typedef struct JSFunctionBox JSFunctionBox;
96 typedef struct JSObjectBox JSObjectBox;
97 typedef struct JSParseNode JSParseNode;
98 typedef struct JSProperty JSProperty;
99 typedef struct JSSharpObjectMap JSSharpObjectMap;
100 typedef struct JSEmptyScope JSEmptyScope;
101 typedef struct JSThread JSThread;
102 typedef struct JSThreadData JSThreadData;
103 typedef struct JSTreeContext JSTreeContext;
104 typedef struct JSTryNote JSTryNote;
105 typedef struct JSWeakRoots JSWeakRoots;
107 /* Friend "Advanced API" typedefs. */
108 typedef struct JSAtom JSAtom;
109 typedef struct JSAtomList JSAtomList;
110 typedef struct JSAtomListElement JSAtomListElement;
111 typedef struct JSAtomMap JSAtomMap;
112 typedef struct JSAtomState JSAtomState;
113 typedef struct JSCodeSpec JSCodeSpec;
114 typedef struct JSPrinter JSPrinter;
115 typedef struct JSRegExp JSRegExp;
116 typedef struct JSRegExpStatics JSRegExpStatics;
117 typedef struct JSScope JSScope;
118 typedef struct JSScopeOps JSScopeOps;
119 typedef struct JSScopeProperty JSScopeProperty;
120 typedef struct JSStackHeader JSStackHeader;
121 typedef struct JSSubString JSSubString;
122 typedef struct JSNativeTraceInfo JSNativeTraceInfo;
123 typedef struct JSSpecializedNative JSSpecializedNative;
124 typedef struct JSXML JSXML;
125 typedef struct JSXMLArray JSXMLArray;
126 typedef struct JSXMLArrayCursor JSXMLArrayCursor;
129 * Template declarations.
131 * jsprvtd.h can be included in both C and C++ translation units. For C++, it
132 * may possibly be wrapped in an extern "C" block which does not agree with
133 * templates.
135 #ifdef __cplusplus
136 extern "C++" {
138 namespace js {
140 class ExecuteArgsGuard;
141 class InvokeFrameGuard;
142 class InvokeArgsGuard;
143 class TraceRecorder;
144 struct TraceMonitor;
145 class StackSpace;
146 class CallStackSegment;
148 class TokenStream;
149 struct Token;
150 struct TokenPos;
151 struct TokenPtr;
153 class ContextAllocPolicy;
154 class SystemAllocPolicy;
156 template <class T,
157 size_t MinInlineCapacity = 0,
158 class AllocPolicy = ContextAllocPolicy>
159 class Vector;
161 template <class>
162 struct DefaultHasher;
164 template <class Key,
165 class Value,
166 class HashPolicy = DefaultHasher<Key>,
167 class AllocPolicy = ContextAllocPolicy>
168 class HashMap;
170 template <class T,
171 class HashPolicy = DefaultHasher<T>,
172 class AllocPolicy = ContextAllocPolicy>
173 class HashSet;
175 class DeflatedStringCache;
177 class PropertyCache;
178 struct PropertyCacheEntry;
181 } /* namespace js */
183 /* Common instantiations. */
184 typedef js::Vector<jschar, 32> JSCharBuffer;
186 } /* export "C++" */
187 #endif /* __cplusplus */
189 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
190 typedef enum JSTrapStatus {
191 JSTRAP_ERROR,
192 JSTRAP_CONTINUE,
193 JSTRAP_RETURN,
194 JSTRAP_THROW,
195 JSTRAP_LIMIT
196 } JSTrapStatus;
198 typedef JSTrapStatus
199 (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
200 jsval closure);
202 typedef JSTrapStatus
203 (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
204 void *closure);
206 typedef JSTrapStatus
207 (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
208 void *closure);
210 typedef JSTrapStatus
211 (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
212 void *closure);
214 typedef JSBool
215 (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
216 jsval *newp, void *closure);
218 /* called just after script creation */
219 typedef void
220 (* JSNewScriptHook)(JSContext *cx,
221 const char *filename, /* URL of script */
222 uintN lineno, /* first line */
223 JSScript *script,
224 JSFunction *fun,
225 void *callerdata);
227 /* called just before script destruction */
228 typedef void
229 (* JSDestroyScriptHook)(JSContext *cx,
230 JSScript *script,
231 void *callerdata);
233 typedef void
234 (* JSSourceHandler)(const char *filename, uintN lineno, jschar *str,
235 size_t length, void **listenerTSData, void *closure);
238 * This hook captures high level script execution and function calls (JS or
239 * native). It is used by JS_SetExecuteHook to hook top level scripts and by
240 * JS_SetCallHook to hook function calls. It will get called twice per script
241 * or function call: just before execution begins and just after it finishes.
242 * In both cases the 'current' frame is that of the executing code.
244 * The 'before' param is JS_TRUE for the hook invocation before the execution
245 * and JS_FALSE for the invocation after the code has run.
247 * The 'ok' param is significant only on the post execution invocation to
248 * signify whether or not the code completed 'normally'.
250 * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
251 * for the 'before'invocation, but is whatever value is returned from that
252 * invocation for the 'after' invocation. Thus, the hook implementor *could*
253 * allocate a structure in the 'before' invocation and return a pointer to that
254 * structure. The pointer would then be handed to the hook for the 'after'
255 * invocation. Alternately, the 'before' could just return the same value as
256 * in 'closure' to cause the 'after' invocation to be called with the same
257 * 'closure' value as the 'before'.
259 * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
260 * be called.
262 typedef void *
263 (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
264 JSBool *ok, void *closure);
266 typedef JSBool
267 (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
268 void *closure);
270 typedef struct JSDebugHooks {
271 JSInterruptHook interruptHook;
272 void *interruptHookData;
273 JSNewScriptHook newScriptHook;
274 void *newScriptHookData;
275 JSDestroyScriptHook destroyScriptHook;
276 void *destroyScriptHookData;
277 JSDebuggerHandler debuggerHandler;
278 void *debuggerHandlerData;
279 JSSourceHandler sourceHandler;
280 void *sourceHandlerData;
281 JSInterpreterHook executeHook;
282 void *executeHookData;
283 JSInterpreterHook callHook;
284 void *callHookData;
285 JSThrowHook throwHook;
286 void *throwHookData;
287 JSDebugErrorHook debugErrorHook;
288 void *debugErrorHookData;
289 } JSDebugHooks;
291 /* JSObjectOps function pointer typedefs. */
294 * Look for id in obj and its prototype chain, returning false on error or
295 * exception, true on success. On success, return null in *propp if id was
296 * not found. If id was found, return the first object searching from obj
297 * along its prototype chain in which id names a direct property in *objp, and
298 * return a non-null, opaque property pointer in *propp.
300 * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
301 * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
302 * that bypasses id re-lookup. In any case, a non-null *propp result after a
303 * successful lookup must be dropped via JSObject::dropProperty.
305 * NB: successful return with non-null *propp means the implementation may
306 * have locked *objp and added a reference count associated with *propp, so
307 * callers should not risk deadlock by nesting or interleaving other lookups
308 * or any obj-bearing ops before dropping *propp.
310 typedef JSBool
311 (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
312 JSProperty **propp);
315 * Define obj[id], a direct property of obj named id, having the given initial
316 * value, with the specified getter, setter, and attributes.
318 typedef JSBool
319 (* JSDefinePropOp)(JSContext *cx, JSObject *obj, jsid id, const jsval *value,
320 JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
323 * Get, set, or delete obj[id], returning false on error or exception, true
324 * on success. If getting or setting, the new value is returned in *vp on
325 * success. If deleting without error, *vp will be JSVAL_FALSE if obj[id] is
326 * permanent, and JSVAL_TRUE if id named a direct property of obj that was in
327 * fact deleted, or if id names no direct property of obj (id could name a
328 * prototype property, or no property in obj or its prototype chain).
330 typedef JSBool
331 (* JSPropertyIdOp)(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
334 * Get or set attributes of the property obj[id]. Return false on error or
335 * exception, true with current attributes in *attrsp.
337 typedef JSBool
338 (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
341 * The type of ops->call. Same argument types as JSFastNative, but a different
342 * contract. A JSCallOp expects a dummy stack frame with the caller's
343 * scopeChain.
345 typedef JSBool
346 (* JSCallOp)(JSContext *cx, uintN argc, jsval *vp);
349 * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
350 * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
352 #ifdef JS_C_STRINGS_ARE_UTF8
353 # define js_CStringsAreUTF8 JS_TRUE
354 #else
355 extern JSBool js_CStringsAreUTF8;
356 #endif
358 JS_END_EXTERN_C
360 #endif /* jsprvtd_h___ */