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 "jsapi.h"
58 : #include "jsutil.h"
59 :
60 : #ifdef __cplusplus
61 : #include "js/HashTable.h"
62 : #include "js/Vector.h"
63 : #endif
64 :
65 : JS_BEGIN_EXTERN_C
66 :
67 : /*
68 : * Convenience constants.
69 : */
70 : #define JS_BITS_PER_UINT32_LOG2 5
71 : #define JS_BITS_PER_UINT32 32
72 :
73 : /* The alignment required of objects stored in GC arenas. */
74 : static const unsigned JS_GCTHING_ALIGN = 8;
75 : static const unsigned JS_GCTHING_ZEROBITS = 3;
76 :
77 : /* Scalar typedefs. */
78 : typedef uint8_t jsbytecode;
79 : typedef uint8_t jssrcnote;
80 : typedef uintptr_t jsatomid;
81 :
82 : /* Struct typedefs. */
83 : typedef struct JSArgumentFormatMap JSArgumentFormatMap;
84 : typedef struct JSGCThing JSGCThing;
85 : typedef struct JSGenerator JSGenerator;
86 : typedef struct JSNativeEnumerator JSNativeEnumerator;
87 : typedef struct JSProperty JSProperty;
88 : typedef struct JSSharpObjectMap JSSharpObjectMap;
89 : typedef struct JSTryNote JSTryNote;
90 :
91 : /* Friend "Advanced API" typedefs. */
92 : typedef struct JSAtomState JSAtomState;
93 : typedef struct JSCodeSpec JSCodeSpec;
94 : typedef struct JSPrinter JSPrinter;
95 : typedef struct JSStackHeader JSStackHeader;
96 : typedef struct JSSubString JSSubString;
97 : typedef struct JSSpecializedNative JSSpecializedNative;
98 : typedef struct JSXML JSXML;
99 :
100 : /*
101 : * Template declarations.
102 : *
103 : * jsprvtd.h can be included in both C and C++ translation units. For C++, it
104 : * may possibly be wrapped in an extern "C" block which does not agree with
105 : * templates.
106 : */
107 : #ifdef __cplusplus
108 :
109 : extern "C++" {
110 :
111 : class JSDependentString;
112 : class JSExtensibleString;
113 : class JSExternalString;
114 : class JSLinearString;
115 : class JSFixedString;
116 : class JSStaticAtom;
117 : class JSRope;
118 : class JSAtom;
119 : class JSWrapper;
120 :
121 : namespace js {
122 :
123 : struct ArgumentsData;
124 : struct Class;
125 :
126 : class RegExpGuard;
127 : class RegExpObject;
128 : class RegExpObjectBuilder;
129 : class RegExpShared;
130 : class RegExpStatics;
131 : class MatchPairs;
132 :
133 : namespace detail { class RegExpCode; }
134 :
135 : enum RegExpFlag
136 : {
137 : IgnoreCaseFlag = 0x01,
138 : GlobalFlag = 0x02,
139 : MultilineFlag = 0x04,
140 : StickyFlag = 0x08,
141 :
142 : NoFlags = 0x00,
143 : AllFlags = 0x0f
144 : };
145 :
146 : enum RegExpExecType
147 : {
148 : RegExpExec,
149 : RegExpTest
150 : };
151 :
152 : class ExecuteArgsGuard;
153 : class InvokeFrameGuard;
154 : class InvokeArgsGuard;
155 : class StringBuffer;
156 :
157 : class FrameRegs;
158 : class StackFrame;
159 : class StackSegment;
160 : class StackSpace;
161 : class ContextStack;
162 : class FrameRegsIter;
163 : class CallReceiver;
164 : class CallArgs;
165 :
166 : struct BytecodeEmitter;
167 : struct Definition;
168 : struct FunctionBox;
169 : struct ObjectBox;
170 : struct ParseNode;
171 : struct Parser;
172 : class TokenStream;
173 : struct Token;
174 : struct TokenPos;
175 : struct TokenPtr;
176 : struct TreeContext;
177 : class UpvarCookie;
178 :
179 : class Proxy;
180 : class ProxyHandler;
181 : class Wrapper;
182 : class CrossCompartmentWrapper;
183 :
184 : class TempAllocPolicy;
185 : class RuntimeAllocPolicy;
186 :
187 : class GlobalObject;
188 :
189 : template <typename K,
190 : typename V,
191 : size_t InlineElems>
192 226506 : class InlineMap;
193 :
194 : class LifoAlloc;
195 :
196 : class BaseShape;
197 : class UnownedBaseShape;
198 : struct Shape;
199 : struct EmptyShape;
200 : class ShapeKindArray;
201 : class Bindings;
202 :
203 : struct StackBaseShape;
204 : struct StackShape;
205 :
206 : class MultiDeclRange;
207 : class ParseMapPool;
208 : class DefnOrHeader;
209 : typedef InlineMap<JSAtom *, Definition *, 24> AtomDefnMap;
210 : typedef InlineMap<JSAtom *, jsatomid, 24> AtomIndexMap;
211 : typedef InlineMap<JSAtom *, DefnOrHeader, 24> AtomDOHMap;
212 : typedef Vector<UpvarCookie, 8> UpvarCookies;
213 :
214 : class Breakpoint;
215 : class BreakpointSite;
216 : class Debugger;
217 : class WatchpointMap;
218 :
219 : /*
220 : * Env is the type of what ES5 calls "lexical environments" (runtime
221 : * activations of lexical scopes). This is currently just JSObject, and is
222 : * implemented by Call, Block, With, and DeclEnv objects, among others--but
223 : * environments and objects are really two different concepts.
224 : */
225 : typedef JSObject Env;
226 :
227 : typedef JSNative Native;
228 : typedef JSPropertyOp PropertyOp;
229 : typedef JSStrictPropertyOp StrictPropertyOp;
230 : typedef JSPropertyDescriptor PropertyDescriptor;
231 :
232 : namespace analyze {
233 :
234 : struct LifetimeVariable;
235 : class LoopAnalysis;
236 : class ScriptAnalysis;
237 : class SlotValue;
238 : class SSAValue;
239 : class SSAUseChain;
240 :
241 : } /* namespace analyze */
242 :
243 : namespace types {
244 :
245 : class TypeSet;
246 : struct TypeCallsite;
247 : struct TypeObject;
248 : struct TypeCompartment;
249 :
250 : } /* namespace types */
251 :
252 : enum ThingRootKind
253 : {
254 : THING_ROOT_OBJECT,
255 : THING_ROOT_SHAPE,
256 : THING_ROOT_BASE_SHAPE,
257 : THING_ROOT_TYPE_OBJECT,
258 : THING_ROOT_STRING,
259 : THING_ROOT_SCRIPT,
260 : THING_ROOT_ID,
261 : THING_ROOT_VALUE,
262 : THING_ROOT_LIMIT
263 : };
264 :
265 : template <typename T> class Root;
266 : template <typename T> class RootedVar;
267 :
268 : template <typename T>
269 : struct RootMethods { };
270 :
271 : /*
272 : * Reference to a stack location rooted for GC. See "Moving GC Stack Rooting"
273 : * comment in jscntxt.h.
274 : */
275 : template <typename T>
276 : class Handle
277 : {
278 : public:
279 : /* Copy handles of different types, with implicit coercion. */
280 : template <typename S> Handle(Handle<S> handle) {
281 : testAssign<S>();
282 : ptr = reinterpret_cast<const T *>(handle.address());
283 : }
284 :
285 : /* Get a handle from a rooted stack location, with implicit coercion. */
286 : template <typename S> inline Handle(const Root<S> &root);
287 : template <typename S> inline Handle(const RootedVar<S> &root);
288 :
289 : const T *address() { return ptr; }
290 :
291 54505897 : operator T () { return value(); }
292 52023565 : T operator ->() { return value(); }
293 :
294 : private:
295 : const T *ptr;
296 106529462 : T value() { return *ptr; }
297 :
298 : template <typename S>
299 22017578 : void testAssign() {
300 : #ifdef DEBUG
301 22017578 : T a = RootMethods<T>::initial();
302 22017578 : S b = RootMethods<S>::initial();
303 22017578 : a = b;
304 : (void)a;
305 : #endif
306 22017578 : }
307 : };
308 :
309 : typedef Handle<JSObject*> HandleObject;
310 : typedef Handle<JSFunction*> HandleFunction;
311 : typedef Handle<Shape*> HandleShape;
312 : typedef Handle<BaseShape*> HandleBaseShape;
313 : typedef Handle<types::TypeObject*> HandleTypeObject;
314 : typedef Handle<JSString*> HandleString;
315 : typedef Handle<JSAtom*> HandleAtom;
316 : typedef Handle<jsid> HandleId;
317 : typedef Handle<Value> HandleValue;
318 :
319 : enum XDRMode {
320 : XDR_ENCODE,
321 : XDR_DECODE
322 : };
323 :
324 : template <XDRMode mode>
325 : class XDRState;
326 :
327 : class FreeOp;
328 :
329 : } /* namespace js */
330 :
331 : namespace JSC {
332 :
333 : class ExecutableAllocator;
334 :
335 : } /* namespace JSC */
336 :
337 : namespace WTF {
338 :
339 : class BumpPointerAllocator;
340 :
341 : } /* namespace WTF */
342 :
343 : } /* export "C++" */
344 :
345 : #else
346 :
347 : typedef struct JSAtom JSAtom;
348 :
349 : #endif /* __cplusplus */
350 :
351 : /* "Friend" types used by jscntxt.h and jsdbgapi.h. */
352 : typedef enum JSTrapStatus {
353 : JSTRAP_ERROR,
354 : JSTRAP_CONTINUE,
355 : JSTRAP_RETURN,
356 : JSTRAP_THROW,
357 : JSTRAP_LIMIT
358 : } JSTrapStatus;
359 :
360 : typedef JSTrapStatus
361 : (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
362 : jsval closure);
363 :
364 : typedef JSTrapStatus
365 : (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
366 : void *closure);
367 :
368 : typedef JSTrapStatus
369 : (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
370 : void *closure);
371 :
372 : typedef JSTrapStatus
373 : (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
374 : void *closure);
375 :
376 : typedef JSBool
377 : (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
378 : jsval *newp, void *closure);
379 :
380 : /* called just after script creation */
381 : typedef void
382 : (* JSNewScriptHook)(JSContext *cx,
383 : const char *filename, /* URL of script */
384 : unsigned lineno, /* first line */
385 : JSScript *script,
386 : JSFunction *fun,
387 : void *callerdata);
388 :
389 : /* called just before script destruction */
390 : typedef void
391 : (* JSDestroyScriptHook)(JSFreeOp *fop,
392 : JSScript *script,
393 : void *callerdata);
394 :
395 : typedef void
396 : (* JSSourceHandler)(const char *filename, unsigned lineno, const jschar *str,
397 : size_t length, void **listenerTSData, void *closure);
398 :
399 : /*
400 : * This hook captures high level script execution and function calls (JS or
401 : * native). It is used by JS_SetExecuteHook to hook top level scripts and by
402 : * JS_SetCallHook to hook function calls. It will get called twice per script
403 : * or function call: just before execution begins and just after it finishes.
404 : * In both cases the 'current' frame is that of the executing code.
405 : *
406 : * The 'before' param is JS_TRUE for the hook invocation before the execution
407 : * and JS_FALSE for the invocation after the code has run.
408 : *
409 : * The 'ok' param is significant only on the post execution invocation to
410 : * signify whether or not the code completed 'normally'.
411 : *
412 : * The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
413 : * for the 'before'invocation, but is whatever value is returned from that
414 : * invocation for the 'after' invocation. Thus, the hook implementor *could*
415 : * allocate a structure in the 'before' invocation and return a pointer to that
416 : * structure. The pointer would then be handed to the hook for the 'after'
417 : * invocation. Alternately, the 'before' could just return the same value as
418 : * in 'closure' to cause the 'after' invocation to be called with the same
419 : * 'closure' value as the 'before'.
420 : *
421 : * Returning NULL in the 'before' hook will cause the 'after' hook *not* to
422 : * be called.
423 : */
424 : typedef void *
425 : (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
426 : JSBool *ok, void *closure);
427 :
428 : typedef JSBool
429 : (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
430 : void *closure);
431 :
432 : typedef struct JSDebugHooks {
433 : JSInterruptHook interruptHook;
434 : void *interruptHookData;
435 : JSNewScriptHook newScriptHook;
436 : void *newScriptHookData;
437 : JSDestroyScriptHook destroyScriptHook;
438 : void *destroyScriptHookData;
439 : JSDebuggerHandler debuggerHandler;
440 : void *debuggerHandlerData;
441 : JSSourceHandler sourceHandler;
442 : void *sourceHandlerData;
443 : JSInterpreterHook executeHook;
444 : void *executeHookData;
445 : JSInterpreterHook callHook;
446 : void *callHookData;
447 : JSThrowHook throwHook;
448 : void *throwHookData;
449 : JSDebugErrorHook debugErrorHook;
450 : void *debugErrorHookData;
451 : } JSDebugHooks;
452 :
453 : /* js::ObjectOps function pointer typedefs. */
454 :
455 : /*
456 : * Look for id in obj and its prototype chain, returning false on error or
457 : * exception, true on success. On success, return null in *propp if id was
458 : * not found. If id was found, return the first object searching from obj
459 : * along its prototype chain in which id names a direct property in *objp, and
460 : * return a non-null, opaque property pointer in *propp.
461 : *
462 : * If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
463 : * may be passed as the prop parameter to a JSAttributesOp, as a short-cut
464 : * that bypasses id re-lookup.
465 : */
466 : typedef JSBool
467 : (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
468 : JSProperty **propp);
469 :
470 : /*
471 : * Get or set attributes of the property obj[id]. Return false on error or
472 : * exception, true with current attributes in *attrsp.
473 : */
474 : typedef JSBool
475 : (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, unsigned *attrsp);
476 :
477 : /*
478 : * A generic type for functions mapping an object to another object, or null
479 : * if an error or exception was thrown on cx.
480 : */
481 : typedef JSObject *
482 : (* JSObjectOp)(JSContext *cx, JSObject *obj);
483 :
484 : /*
485 : * Hook that creates an iterator object for a given object. Returns the
486 : * iterator object or null if an error or exception was thrown on cx.
487 : */
488 : typedef JSObject *
489 : (* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly);
490 :
491 : /*
492 : * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
493 : * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
494 : */
495 : #ifdef JS_C_STRINGS_ARE_UTF8
496 : # define js_CStringsAreUTF8 JS_TRUE
497 : #else
498 : extern JSBool js_CStringsAreUTF8;
499 : #endif
500 :
501 : JS_END_EXTERN_C
502 :
503 : #endif /* jsprvtd_h___ */
|