/[jscoverage]/trunk/js/jsprvtd.h
ViewVC logotype

Contents of /trunk/js/jsprvtd.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 460 - (show annotations)
Sat Sep 26 23:15:22 2009 UTC (10 years, 1 month ago) by siliconforks
File MIME type: text/plain
File size: 15091 byte(s)
Upgrade to SpiderMonkey from Firefox 3.5.3.

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 "jsutil.h"
59
60 /* Internal identifier (jsid) macros. */
61
62 #define JSID_IS_ATOM(id) JSVAL_IS_STRING((jsval)(id))
63 #define JSID_TO_ATOM(id) ((JSAtom *)(id))
64 #define ATOM_TO_JSID(atom) (JS_ASSERT(ATOM_IS_STRING(atom)), \
65 (jsid)(atom))
66
67 #define JSID_IS_INT(id) JSVAL_IS_INT((jsval)(id))
68 #define JSID_TO_INT(id) JSVAL_TO_INT((jsval)(id))
69 #define INT_TO_JSID(i) ((jsid)INT_TO_JSVAL(i))
70 #define INT_JSVAL_TO_JSID(v) ((jsid)(v))
71 #define INT_JSID_TO_JSVAL(id) ((jsval)(id))
72
73 #define JSID_IS_OBJECT(id) JSVAL_IS_OBJECT((jsval)(id))
74 #define JSID_TO_OBJECT(id) JSVAL_TO_OBJECT((jsval)(id))
75 #define OBJECT_TO_JSID(obj) ((jsid)OBJECT_TO_JSVAL(obj))
76 #define OBJECT_JSVAL_TO_JSID(v) ((jsid)v)
77
78 #define ID_TO_VALUE(id) ((jsval)(id))
79
80 /*
81 * Convenience constants.
82 */
83 #define JS_BITS_PER_UINT32_LOG2 5
84 #define JS_BITS_PER_UINT32 32
85
86 /* Scalar typedefs. */
87 typedef uint8 jsbytecode;
88 typedef uint8 jssrcnote;
89 typedef uint32 jsatomid;
90
91 /* Struct typedefs. */
92 typedef struct JSArgumentFormatMap JSArgumentFormatMap;
93 typedef struct JSCodeGenerator JSCodeGenerator;
94 typedef struct JSGCThing JSGCThing;
95 typedef struct JSGenerator JSGenerator;
96 typedef struct JSNativeEnumerator JSNativeEnumerator;
97 typedef struct JSCompiler JSCompiler;
98 typedef struct JSFunctionBox JSFunctionBox;
99 typedef struct JSObjectBox JSObjectBox;
100 typedef struct JSParseNode JSParseNode;
101 typedef struct JSPropCacheEntry JSPropCacheEntry;
102 typedef struct JSProperty JSProperty;
103 typedef struct JSSharpObjectMap JSSharpObjectMap;
104 typedef struct JSTempValueRooter JSTempValueRooter;
105 typedef struct JSThread JSThread;
106 typedef struct JSThreadData JSThreadData;
107 typedef struct JSToken JSToken;
108 typedef struct JSTokenPos JSTokenPos;
109 typedef struct JSTokenPtr JSTokenPtr;
110 typedef struct JSTokenStream JSTokenStream;
111 typedef struct JSTraceMonitor JSTraceMonitor;
112 typedef struct JSTreeContext JSTreeContext;
113 typedef struct JSTryNote JSTryNote;
114 typedef struct JSWeakRoots JSWeakRoots;
115
116 /* Friend "Advanced API" typedefs. */
117 typedef struct JSAtom JSAtom;
118 typedef struct JSAtomList JSAtomList;
119 typedef struct JSAtomListElement JSAtomListElement;
120 typedef struct JSAtomMap JSAtomMap;
121 typedef struct JSAtomState JSAtomState;
122 typedef struct JSCodeSpec JSCodeSpec;
123 typedef struct JSPrinter JSPrinter;
124 typedef struct JSRegExp JSRegExp;
125 typedef struct JSRegExpStatics JSRegExpStatics;
126 typedef struct JSScope JSScope;
127 typedef struct JSScopeOps JSScopeOps;
128 typedef struct JSScopeProperty JSScopeProperty;
129 typedef struct JSStackHeader JSStackHeader;
130 typedef struct JSStringBuffer JSStringBuffer;
131 typedef struct JSSubString JSSubString;
132 typedef struct JSTraceableNative JSTraceableNative;
133 typedef struct JSXML JSXML;
134 typedef struct JSXMLArray JSXMLArray;
135 typedef struct JSXMLArrayCursor JSXMLArrayCursor;
136
137 /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
138 typedef enum JSTrapStatus {
139 JSTRAP_ERROR,
140 JSTRAP_CONTINUE,
141 JSTRAP_RETURN,
142 JSTRAP_THROW,
143 JSTRAP_LIMIT
144 } JSTrapStatus;
145
146 typedef JSTrapStatus
147 (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
148 void *closure);
149
150 typedef JSBool
151 (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsval id, jsval old,
152 jsval *newp, void *closure);
153
154 /* called just after script creation */
155 typedef void
156 (* JSNewScriptHook)(JSContext *cx,
157 const char *filename, /* URL of script */
158 uintN lineno, /* first line */
159 JSScript *script,
160 JSFunction *fun,
161 void *callerdata);
162
163 /* called just before script destruction */
164 typedef void
165 (* JSDestroyScriptHook)(JSContext *cx,
166 JSScript *script,
167 void *callerdata);
168
169 typedef void
170 (* JSSourceHandler)(const char *filename, uintN lineno, jschar *str,
171 size_t length, void **listenerTSData, void *closure);
172
173 /*
174 * This hook captures high level script execution and function calls (JS or
175 * native). It is used by JS_SetExecuteHook to hook top level scripts and by
176 * JS_SetCallHook to hook function calls. It will get called twice per script
177 * or function call: just before execution begins and just after it finishes.
178 * In both cases the 'current' frame is that of the executing code.
179 *
180 * The 'before' param is JS_TRUE for the hook invocation before the execution
181 * and JS_FALSE for the invocation after the code has run.
182 *
183 * The 'ok' param is significant only on the post execution invocation to
184 * signify whether or not the code completed 'normally'.
185 *
186 * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
187 * for the 'before'invocation, but is whatever value is returned from that
188 * invocation for the 'after' invocation. Thus, the hook implementor *could*
189 * allocate a structure in the 'before' invocation and return a pointer to that
190 * structure. The pointer would then be handed to the hook for the 'after'
191 * invocation. Alternately, the 'before' could just return the same value as
192 * in 'closure' to cause the 'after' invocation to be called with the same
193 * 'closure' value as the 'before'.
194 *
195 * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
196 * be called.
197 */
198 typedef void *
199 (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
200 JSBool *ok, void *closure);
201
202 typedef void
203 (* JSObjectHook)(JSContext *cx, JSObject *obj, JSBool isNew, void *closure);
204
205 typedef JSBool
206 (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
207 void *closure);
208
209 typedef struct JSDebugHooks {
210 JSTrapHandler interruptHandler;
211 void *interruptHandlerData;
212 JSNewScriptHook newScriptHook;
213 void *newScriptHookData;
214 JSDestroyScriptHook destroyScriptHook;
215 void *destroyScriptHookData;
216 JSTrapHandler debuggerHandler;
217 void *debuggerHandlerData;
218 JSSourceHandler sourceHandler;
219 void *sourceHandlerData;
220 JSInterpreterHook executeHook;
221 void *executeHookData;
222 JSInterpreterHook callHook;
223 void *callHookData;
224 JSObjectHook objectHook;
225 void *objectHookData;
226 JSTrapHandler throwHook;
227 void *throwHookData;
228 JSDebugErrorHook debugErrorHook;
229 void *debugErrorHookData;
230 } JSDebugHooks;
231
232 /*
233 * Type definitions for temporary GC roots that register with GC local C
234 * variables. See jscntxt.h for details.
235 */
236 typedef void
237 (* JSTempValueTrace)(JSTracer *trc, JSTempValueRooter *tvr);
238
239 typedef union JSTempValueUnion {
240 jsval value;
241 JSObject *object;
242 JSString *string;
243 JSXML *xml;
244 JSTempValueTrace trace;
245 JSScopeProperty *sprop;
246 JSWeakRoots *weakRoots;
247 JSCompiler *compiler;
248 JSScript *script;
249 jsval *array;
250 } JSTempValueUnion;
251
252 struct JSTempValueRooter {
253 JSTempValueRooter *down;
254 ptrdiff_t count;
255 JSTempValueUnion u;
256 };
257
258 /* JSObjectOps function pointer typedefs. */
259
260 /*
261 * Look for id in obj and its prototype chain, returning false on error or
262 * exception, true on success. On success, return null in *propp if id was
263 * not found. If id was found, return the first object searching from obj
264 * along its prototype chain in which id names a direct property in *objp, and
265 * return a non-null, opaque property pointer in *propp.
266 *
267 * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
268 * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
269 * that bypasses id re-lookup. In any case, a non-null *propp result after a
270 * successful lookup must be dropped via JSObjectOps.dropProperty.
271 *
272 * NB: successful return with non-null *propp means the implementation may
273 * have locked *objp and added a reference count associated with *propp, so
274 * callers should not risk deadlock by nesting or interleaving other lookups
275 * or any obj-bearing ops before dropping *propp.
276 */
277 typedef JSBool
278 (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
279 JSProperty **propp);
280
281 /*
282 * Define obj[id], a direct property of obj named id, having the given initial
283 * value, with the specified getter, setter, and attributes. If the propp out
284 * param is non-null, *propp on successful return contains an opaque property
285 * pointer usable as a speedup hint with JSAttributesOp. But note that propp
286 * may be null, indicating that the caller is not interested in recovering an
287 * opaque pointer to the newly-defined property.
288 *
289 * If propp is non-null and JSDefinePropOp succeeds, its caller must be sure
290 * to drop *propp using JSObjectOps.dropProperty in short order, just as with
291 * JSLookupPropOp.
292 */
293 typedef JSBool
294 (* JSDefinePropOp)(JSContext *cx, JSObject *obj, jsid id, jsval value,
295 JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
296 JSProperty **propp);
297
298 /*
299 * Get, set, or delete obj[id], returning false on error or exception, true
300 * on success. If getting or setting, the new value is returned in *vp on
301 * success. If deleting without error, *vp will be JSVAL_FALSE if obj[id] is
302 * permanent, and JSVAL_TRUE if id named a direct property of obj that was in
303 * fact deleted, or if id names no direct property of obj (id could name a
304 * prototype property, or no property in obj or its prototype chain).
305 */
306 typedef JSBool
307 (* JSPropertyIdOp)(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
308
309 /*
310 * Get or set attributes of the property obj[id]. Return false on error or
311 * exception, true with current attributes in *attrsp. If prop is non-null,
312 * it must come from the *propp out parameter of a prior JSDefinePropOp or
313 * JSLookupPropOp call.
314 */
315 typedef JSBool
316 (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
317 uintN *attrsp);
318
319 /*
320 * JSObjectOps.checkAccess type: check whether obj[id] may be accessed per
321 * mode, returning false on error/exception, true on success with obj[id]'s
322 * last-got value in *vp, and its attributes in *attrsp.
323 */
324 typedef JSBool
325 (* JSCheckAccessIdOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
326 jsval *vp, uintN *attrsp);
327
328 /*
329 * A generic type for functions taking a context, object, and property, with
330 * no return value. Used by JSObjectOps.dropProperty currently (see above,
331 * JSDefinePropOp and JSLookupPropOp, for the object-locking protocol in which
332 * dropProperty participates).
333 */
334 typedef void
335 (* JSPropertyRefOp)(JSContext *cx, JSObject *obj, JSProperty *prop);
336
337 /*
338 * Get and set a required slot, one that should already have been allocated.
339 * These operations are infallible, so required slots must be pre-allocated,
340 * or implementations must suppress out-of-memory errors. The native ops
341 * (js_ObjectOps, see jsobj.c) access slots reserved by including a call to
342 * the JSCLASS_HAS_RESERVED_SLOTS(n) macro in the JSClass.flags initializer.
343 *
344 * NB: the slot parameter is a zero-based index into obj slots, unlike the
345 * index parameter to the JS_GetReservedSlot and JS_SetReservedSlot API entry
346 * points, which is a zero-based index into the JSCLASS_RESERVED_SLOTS(clasp)
347 * reserved slots that come after the initial well-known slots: proto, parent,
348 * class, and optionally, the private data slot.
349 */
350 typedef jsval
351 (* JSGetRequiredSlotOp)(JSContext *cx, JSObject *obj, uint32 slot);
352
353 typedef JSBool
354 (* JSSetRequiredSlotOp)(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
355
356 /*
357 * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
358 * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
359 */
360 #ifdef JS_C_STRINGS_ARE_UTF8
361 # define js_CStringsAreUTF8 JS_TRUE
362 #else
363 extern JSBool js_CStringsAreUTF8;
364 #endif
365
366 #endif /* jsprvtd_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24