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.
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
;
79 /* Class and struct forward declarations in namespace js. */
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
140 class ExecuteArgsGuard
;
141 class InvokeFrameGuard
;
142 class InvokeArgsGuard
;
146 class CallStackSegment
;
153 class ContextAllocPolicy
;
154 class SystemAllocPolicy
;
157 size_t MinInlineCapacity
= 0,
158 class AllocPolicy
= ContextAllocPolicy
>
162 struct DefaultHasher
;
166 class HashPolicy
= DefaultHasher
<Key
>,
167 class AllocPolicy
= ContextAllocPolicy
>
171 class HashPolicy
= DefaultHasher
<T
>,
172 class AllocPolicy
= ContextAllocPolicy
>
175 class DeflatedStringCache
;
178 struct PropertyCacheEntry
;
183 /* Common instantiations. */
184 typedef js::Vector
<jschar
, 32> JSCharBuffer
;
187 #endif /* __cplusplus */
189 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
190 typedef enum JSTrapStatus
{
199 (* JSTrapHandler
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
203 (* JSInterruptHook
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
207 (* JSDebuggerHandler
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
211 (* JSThrowHook
)(JSContext
*cx
, JSScript
*script
, jsbytecode
*pc
, jsval
*rval
,
215 (* JSWatchPointHandler
)(JSContext
*cx
, JSObject
*obj
, jsid id
, jsval old
,
216 jsval
*newp
, void *closure
);
218 /* called just after script creation */
220 (* JSNewScriptHook
)(JSContext
*cx
,
221 const char *filename
, /* URL of script */
222 uintN lineno
, /* first line */
227 /* called just before script destruction */
229 (* JSDestroyScriptHook
)(JSContext
*cx
,
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
263 (* JSInterpreterHook
)(JSContext
*cx
, JSStackFrame
*fp
, JSBool before
,
264 JSBool
*ok
, void *closure
);
267 (* JSDebugErrorHook
)(JSContext
*cx
, const char *message
, JSErrorReport
*report
,
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
;
285 JSThrowHook throwHook
;
287 JSDebugErrorHook debugErrorHook
;
288 void *debugErrorHookData
;
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.
311 (* JSLookupPropOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, JSObject
**objp
,
315 * Define obj[id], a direct property of obj named id, having the given initial
316 * value, with the specified getter, setter, and attributes.
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).
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.
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
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
355 extern JSBool js_CStringsAreUTF8
;
360 #endif /* jsprvtd_h___ */