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 ***** */
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.
58 #include "jsstaticcheck.h"
64 * Convenience constants.
66 #define JS_BITS_PER_UINT32_LOG2 5
67 #define JS_BITS_PER_UINT32 32
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;
73 /* Scalar typedefs. */
74 typedef uint8 jsbytecode;
75 typedef uint8 jssrcnote;
76 typedef uint32 jsatomid;
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;
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;
114 * Template declarations.
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
125 struct ArgumentsData;
129 class AutoStringRooter;
130 class ExecuteArgsGuard;
131 class InvokeFrameGuard;
132 class InvokeArgsGuard;
133 class InvokeSessionGuard;
148 class ContextAllocPolicy;
149 class SystemAllocPolicy;
152 size_t MinInlineCapacity = 0,
153 class AllocPolicy = ContextAllocPolicy>
157 struct DefaultHasher;
161 class HashPolicy = DefaultHasher<Key>,
162 class AllocPolicy = ContextAllocPolicy>
166 class HashPolicy = DefaultHasher<T>,
167 class AllocPolicy = ContextAllocPolicy>
171 struct PropertyCacheEntry;
179 #endif /* __cplusplus */
181 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
182 typedef enum JSTrapStatus {
191 (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
195 (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
199 (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
203 (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
207 (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
208 jsval *newp, void *closure);
210 /* called just after script creation */
212 (* JSNewScriptHook)(JSContext *cx,
213 const char *filename, /* URL of script */
214 uintN lineno, /* first line */
219 /* called just before script destruction */
221 (* JSDestroyScriptHook)(JSContext *cx,
226 (* JSSourceHandler)(const char *filename, uintN lineno, jschar *str,
227 size_t length, void **listenerTSData, void *closure);
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.
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.
239 * The 'ok' param is significant only on the post execution invocation to
240 * signify whether or not the code completed 'normally'.
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'.
251 * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
255 (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
256 JSBool *ok, void *closure);
259 (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
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;
277 JSThrowHook throwHook;
279 JSDebugErrorHook debugErrorHook;
280 void *debugErrorHookData;
283 /* js::ObjectOps function pointer typedefs. */
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.
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.
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.
302 (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
306 * Get or set attributes of the property obj[id]. Return false on error or
307 * exception, true with current attributes in *attrsp.
310 (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
313 * A generic type for functions mapping an object to another object, or null
314 * if an error or exception was thrown on cx.
317 (* JSObjectOp)(JSContext *cx, JSObject *obj);
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.
324 (* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly);
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.
330 #ifdef JS_C_STRINGS_ARE_UTF8
331 # define js_CStringsAreUTF8 JS_TRUE
333 extern JSBool js_CStringsAreUTF8;
337 * Hack to expose obj->getOps()->outer to the C implementation of the debugger
340 extern JS_FRIEND_API(JSObject *)
341 js_ObjectToOuterObject(JSContext *cx, JSObject *obj);
345 #endif /* jsprvtd_h___ */