Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jsprvtd.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
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/
10  *
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.
15  *
16  * The Original Code is Mozilla Communicator client code, released
17  * March 31, 1998.
18  *
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.
23  *
24  * Contributor(s):
25  *
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.
37  *
38  * ***** END LICENSE BLOCK ***** */
39
40 #ifndef jsprvtd_h___
41 #define jsprvtd_h___
42 /*
43  * JS private typename definitions.
44  *
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.
51  *
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.
55  */
56
57 #include "jspubtd.h"
58 #include "jsstaticcheck.h"
59 #include "jsutil.h"
60
61 JS_BEGIN_EXTERN_C
62
63 /*
64  * Convenience constants.
65  */
66 #define JS_BITS_PER_UINT32_LOG2 5
67 #define JS_BITS_PER_UINT32      32
68
69 /* The alignment required of objects stored in GC arenas. */
70 static const uintN JS_GCTHING_ALIGN = 8;
71 static const uintN JS_GCTHING_ZEROBITS = 3;
72
73 /* Scalar typedefs. */
74 typedef uint8  jsbytecode;
75 typedef uint8  jssrcnote;
76 typedef uint32 jsatomid;
77
78 /* Struct typedefs. */
79 typedef struct JSArgumentFormatMap  JSArgumentFormatMap;
80 typedef struct JSCodeGenerator      JSCodeGenerator;
81 typedef struct JSGCThing            JSGCThing;
82 typedef struct JSGenerator          JSGenerator;
83 typedef struct JSNativeEnumerator   JSNativeEnumerator;
84 typedef struct JSFunctionBox        JSFunctionBox;
85 typedef struct JSObjectBox          JSObjectBox;
86 typedef struct JSParseNode          JSParseNode;
87 typedef struct JSProperty           JSProperty;
88 typedef struct JSScript             JSScript;
89 typedef struct JSSharpObjectMap     JSSharpObjectMap;
90 typedef struct JSThread             JSThread;
91 typedef struct JSThreadData         JSThreadData;
92 typedef struct JSTreeContext        JSTreeContext;
93 typedef struct JSTryNote            JSTryNote;
94
95 /* Friend "Advanced API" typedefs. */
96 typedef struct JSLinearString       JSLinearString;
97 typedef struct JSAtom               JSAtom;
98 typedef struct JSAtomList           JSAtomList;
99 typedef struct JSAtomListElement    JSAtomListElement;
100 typedef struct JSAtomMap            JSAtomMap;
101 typedef struct JSAtomState          JSAtomState;
102 typedef struct JSCodeSpec           JSCodeSpec;
103 typedef struct JSPrinter            JSPrinter;
104 typedef struct JSRegExpStatics      JSRegExpStatics;
105 typedef struct JSStackHeader        JSStackHeader;
106 typedef struct JSSubString          JSSubString;
107 typedef struct JSNativeTraceInfo    JSNativeTraceInfo;
108 typedef struct JSSpecializedNative  JSSpecializedNative;
109 typedef struct JSXML                JSXML;
110 typedef struct JSXMLArray           JSXMLArray;
111 typedef struct JSXMLArrayCursor     JSXMLArrayCursor;
112
113 /*
114  * Template declarations.
115  *
116  * jsprvtd.h can be included in both C and C++ translation units. For C++, it
117  * may possibly be wrapped in an extern "C" block which does not agree with
118  * templates.
119  */
120 #ifdef __cplusplus
121 extern "C++" {
122
123 namespace js {
124
125 struct ArgumentsData;
126
127 class RegExp;
128 class RegExpStatics;
129 class AutoStringRooter;
130 class ExecuteArgsGuard;
131 class InvokeFrameGuard;
132 class InvokeArgsGuard;
133 class InvokeSessionGuard;
134 class TraceRecorder;
135 struct TraceMonitor;
136 class StackSpace;
137 class StackSegment;
138 class FrameRegsIter;
139 class StringBuffer;
140
141 struct Compiler;
142 struct Parser;
143 class TokenStream;
144 struct Token;
145 struct TokenPos;
146 struct TokenPtr;
147
148 class ContextAllocPolicy;
149 class SystemAllocPolicy;
150
151 template <class T,
152           size_t MinInlineCapacity = 0,
153           class AllocPolicy = ContextAllocPolicy>
154 class Vector;
155
156 template <class>
157 struct DefaultHasher;
158
159 template <class Key,
160           class Value,
161           class HashPolicy = DefaultHasher<Key>,
162           class AllocPolicy = ContextAllocPolicy>
163 class HashMap;
164
165 template <class T,
166           class HashPolicy = DefaultHasher<T>,
167           class AllocPolicy = ContextAllocPolicy>
168 class HashSet;
169
170 class PropertyCache;
171 struct PropertyCacheEntry;
172
173 struct Shape;
174 struct EmptyShape;
175
176 } /* namespace js */
177
178 } /* export "C++" */
179 #endif  /* __cplusplus */
180
181 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
182 typedef enum JSTrapStatus {
183     JSTRAP_ERROR,
184     JSTRAP_CONTINUE,
185     JSTRAP_RETURN,
186     JSTRAP_THROW,
187     JSTRAP_LIMIT
188 } JSTrapStatus;
189
190 typedef JSTrapStatus
191 (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
192                   jsval closure);
193
194 typedef JSTrapStatus
195 (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
196                     void *closure);
197
198 typedef JSTrapStatus
199 (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
200                       void *closure);
201
202 typedef JSTrapStatus
203 (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
204                 void *closure);
205
206 typedef JSBool
207 (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
208                         jsval *newp, void *closure);
209
210 /* called just after script creation */
211 typedef void
212 (* JSNewScriptHook)(JSContext  *cx,
213                     const char *filename,  /* URL of script */
214                     uintN      lineno,     /* first line */
215                     JSScript   *script,
216                     JSFunction *fun,
217                     void       *callerdata);
218
219 /* called just before script destruction */
220 typedef void
221 (* JSDestroyScriptHook)(JSContext *cx,
222                         JSScript  *script,
223                         void      *callerdata);
224
225 typedef void
226 (* JSSourceHandler)(const char *filename, uintN lineno, jschar *str,
227                     size_t length, void **listenerTSData, void *closure);
228
229 /*
230  * This hook captures high level script execution and function calls (JS or
231  * native).  It is used by JS_SetExecuteHook to hook top level scripts and by
232  * JS_SetCallHook to hook function calls.  It will get called twice per script
233  * or function call: just before execution begins and just after it finishes.
234  * In both cases the 'current' frame is that of the executing code.
235  *
236  * The 'before' param is JS_TRUE for the hook invocation before the execution
237  * and JS_FALSE for the invocation after the code has run.
238  *
239  * The 'ok' param is significant only on the post execution invocation to
240  * signify whether or not the code completed 'normally'.
241  *
242  * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
243  * for the 'before'invocation, but is whatever value is returned from that
244  * invocation for the 'after' invocation. Thus, the hook implementor *could*
245  * allocate a structure in the 'before' invocation and return a pointer to that
246  * structure. The pointer would then be handed to the hook for the 'after'
247  * invocation. Alternately, the 'before' could just return the same value as
248  * in 'closure' to cause the 'after' invocation to be called with the same
249  * 'closure' value as the 'before'.
250  *
251  * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
252  * be called.
253  */
254 typedef void *
255 (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
256                       JSBool *ok, void *closure);
257
258 typedef JSBool
259 (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
260                      void *closure);
261
262 typedef struct JSDebugHooks {
263     JSInterruptHook     interruptHook;
264     void                *interruptHookData;
265     JSNewScriptHook     newScriptHook;
266     void                *newScriptHookData;
267     JSDestroyScriptHook destroyScriptHook;
268     void                *destroyScriptHookData;
269     JSDebuggerHandler   debuggerHandler;
270     void                *debuggerHandlerData;
271     JSSourceHandler     sourceHandler;
272     void                *sourceHandlerData;
273     JSInterpreterHook   executeHook;
274     void                *executeHookData;
275     JSInterpreterHook   callHook;
276     void                *callHookData;
277     JSThrowHook         throwHook;
278     void                *throwHookData;
279     JSDebugErrorHook    debugErrorHook;
280     void                *debugErrorHookData;
281 } JSDebugHooks;
282
283 /* js::ObjectOps function pointer typedefs. */
284
285 /*
286  * Look for id in obj and its prototype chain, returning false on error or
287  * exception, true on success.  On success, return null in *propp if id was
288  * not found.  If id was found, return the first object searching from obj
289  * along its prototype chain in which id names a direct property in *objp, and
290  * return a non-null, opaque property pointer in *propp.
291  *
292  * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
293  * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
294  * that bypasses id re-lookup.
295  *
296  * NB: successful return with non-null *propp means the implementation may
297  * have locked *objp and added a reference count associated with *propp, so
298  * callers should not risk deadlock by nesting or interleaving other lookups
299  * or any obj-bearing ops before dropping *propp.
300  */
301 typedef JSBool
302 (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
303                    JSProperty **propp);
304
305 /*
306  * Get or set attributes of the property obj[id]. Return false on error or
307  * exception, true with current attributes in *attrsp.
308  */
309 typedef JSBool
310 (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
311
312 /*
313  * A generic type for functions mapping an object to another object, or null
314  * if an error or exception was thrown on cx.
315  */
316 typedef JSObject *
317 (* JSObjectOp)(JSContext *cx, JSObject *obj);
318
319 /*
320  * Hook that creates an iterator object for a given object. Returns the
321  * iterator object or null if an error or exception was thrown on cx.
322  */
323 typedef JSObject *
324 (* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly);
325
326 /*
327  * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
328  * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
329  */
330 #ifdef JS_C_STRINGS_ARE_UTF8
331 # define js_CStringsAreUTF8 JS_TRUE
332 #else
333 extern JSBool js_CStringsAreUTF8;
334 #endif
335
336 /*
337  * Hack to expose obj->getOps()->outer to the C implementation of the debugger
338  * interface.
339  */
340 extern JS_FRIEND_API(JSObject *)
341 js_ObjectToOuterObject(JSContext *cx, JSObject *obj);
342
343 JS_END_EXTERN_C
344
345 #endif /* jsprvtd_h___ */