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 JSSharpObjectMap JSSharpObjectMap
;
89 typedef struct JSThread JSThread
;
90 typedef struct JSThreadData JSThreadData
;
91 typedef struct JSTreeContext JSTreeContext
;
92 typedef struct JSTryNote JSTryNote
;
94 /* Friend "Advanced API" typedefs. */
95 typedef struct JSLinearString JSLinearString
;
96 typedef struct JSAtom JSAtom
;
97 typedef struct JSAtomList JSAtomList
;
98 typedef struct JSAtomListElement JSAtomListElement
;
99 typedef struct JSAtomMap JSAtomMap
;
100 typedef struct JSAtomState JSAtomState
;
101 typedef struct JSCodeSpec JSCodeSpec
;
102 typedef struct JSPrinter JSPrinter
;
103 typedef struct JSRegExpStatics JSRegExpStatics
;
104 typedef struct JSStackHeader JSStackHeader
;
105 typedef struct JSSubString JSSubString
;
106 typedef struct JSNativeTraceInfo JSNativeTraceInfo
;
107 typedef struct JSSpecializedNative JSSpecializedNative
;
108 typedef struct JSXML JSXML
;
109 typedef struct JSXMLArray JSXMLArray
;
110 typedef struct JSXMLArrayCursor JSXMLArrayCursor
;
113 * Template declarations.
115 * jsprvtd.h can be included in both C and C++ translation units. For C++, it
116 * may possibly be wrapped in an extern "C" block which does not agree with
124 struct ArgumentsData
;
128 class AutoStringRooter
;
129 class ExecuteArgsGuard
;
130 class InvokeFrameGuard
;
131 class InvokeArgsGuard
;
132 class InvokeSessionGuard
;
147 class ContextAllocPolicy
;
148 class SystemAllocPolicy
;
151 size_t MinInlineCapacity
= 0,
152 class AllocPolicy
= ContextAllocPolicy
>
156 struct DefaultHasher
;
160 class HashPolicy
= DefaultHasher
<Key
>,
161 class AllocPolicy
= ContextAllocPolicy
>
165 class HashPolicy
= DefaultHasher
<T
>,
166 class AllocPolicy
= ContextAllocPolicy
>
170 struct PropertyCacheEntry
;
178 #endif /* __cplusplus */
180 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
181 typedef enum JSTrapStatus
{
190 (* JSTrapHandler
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
194 (* JSInterruptHook
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
198 (* JSDebuggerHandler
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
202 (* JSThrowHook
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
206 (* JSWatchPointHandler
)(JSContext
*cx
, JSObject
*obj
, jsid id
, jsval old
,
207 jsval
*newp
, void *closure
);
209 /* called just after script creation */
211 (* JSNewScriptHook
)(JSContext
*cx
,
212 const char *filename
, /* URL of script */
213 uintN lineno
, /* first line */
218 /* called just before script destruction */
220 (* JSDestroyScriptHook
)(JSContext
*cx
,
225 (* JSSourceHandler
)(const char *filename
, uintN lineno
, jschar
*str
,
226 size_t length
, void **listenerTSData
, void *closure
);
229 * This hook captures high level script execution and function calls (JS or
230 * native). It is used by JS_SetExecuteHook to hook top level scripts and by
231 * JS_SetCallHook to hook function calls. It will get called twice per script
232 * or function call: just before execution begins and just after it finishes.
233 * In both cases the 'current' frame is that of the executing code.
235 * The 'before' param is JS_TRUE for the hook invocation before the execution
236 * and JS_FALSE for the invocation after the code has run.
238 * The 'ok' param is significant only on the post execution invocation to
239 * signify whether or not the code completed 'normally'.
241 * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
242 * for the 'before'invocation, but is whatever value is returned from that
243 * invocation for the 'after' invocation. Thus, the hook implementor *could*
244 * allocate a structure in the 'before' invocation and return a pointer to that
245 * structure. The pointer would then be handed to the hook for the 'after'
246 * invocation. Alternately, the 'before' could just return the same value as
247 * in 'closure' to cause the 'after' invocation to be called with the same
248 * 'closure' value as the 'before'.
250 * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
254 (* JSInterpreterHook
)(JSContext
*cx
, JSStackFrame
*fp
, JSBool before
,
255 JSBool
*ok
, void *closure
);
258 (* JSDebugErrorHook
)(JSContext
*cx
, const char *message
, JSErrorReport
*report
,
261 typedef struct JSDebugHooks
{
262 JSInterruptHook interruptHook
;
263 void *interruptHookData
;
264 JSNewScriptHook newScriptHook
;
265 void *newScriptHookData
;
266 JSDestroyScriptHook destroyScriptHook
;
267 void *destroyScriptHookData
;
268 JSDebuggerHandler debuggerHandler
;
269 void *debuggerHandlerData
;
270 JSSourceHandler sourceHandler
;
271 void *sourceHandlerData
;
272 JSInterpreterHook executeHook
;
273 void *executeHookData
;
274 JSInterpreterHook callHook
;
276 JSThrowHook throwHook
;
278 JSDebugErrorHook debugErrorHook
;
279 void *debugErrorHookData
;
282 /* js::ObjectOps function pointer typedefs. */
285 * Look for id in obj and its prototype chain, returning false on error or
286 * exception, true on success. On success, return null in *propp if id was
287 * not found. If id was found, return the first object searching from obj
288 * along its prototype chain in which id names a direct property in *objp, and
289 * return a non-null, opaque property pointer in *propp.
291 * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
292 * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
293 * that bypasses id re-lookup.
295 * NB: successful return with non-null *propp means the implementation may
296 * have locked *objp and added a reference count associated with *propp, so
297 * callers should not risk deadlock by nesting or interleaving other lookups
298 * or any obj-bearing ops before dropping *propp.
301 (* JSLookupPropOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, JSObject
**objp
,
305 * Get or set attributes of the property obj[id]. Return false on error or
306 * exception, true with current attributes in *attrsp.
309 (* JSAttributesOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, uintN
*attrsp
);
312 * A generic type for functions mapping an object to another object, or null
313 * if an error or exception was thrown on cx.
316 (* JSObjectOp
)(JSContext
*cx
, JSObject
*obj
);
319 * Hook that creates an iterator object for a given object. Returns the
320 * iterator object or null if an error or exception was thrown on cx.
323 (* JSIteratorOp
)(JSContext
*cx
, JSObject
*obj
, JSBool keysonly
);
326 * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
327 * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
329 #ifdef JS_C_STRINGS_ARE_UTF8
330 # define js_CStringsAreUTF8 JS_TRUE
332 extern JSBool js_CStringsAreUTF8
;
336 * Hack to expose obj->getOps()->outer to the C implementation of the debugger
339 extern JS_FRIEND_API(JSObject
*)
340 js_ObjectToOuterObject(JSContext
*cx
, JSObject
*obj
);
344 #endif /* jsprvtd_h___ */