home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jscntxt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.0 KB  |  198 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jscntxt_h___
  20. #define jscntxt_h___
  21. /*
  22.  * JS execution context.
  23.  */
  24. #ifndef NSPR20
  25. #include "prarena.h"
  26. #else
  27. #include "plarena.h"
  28. #endif
  29. #include "prclist.h"
  30. #include "prlong.h"
  31. #include "jsatom.h"
  32. #include "jsgc.h"
  33. #include "jsinterp.h"
  34. #include "jsobj.h"
  35. #include "jsprvtd.h"
  36. #include "jspubtd.h"
  37. #include "jsregexp.h"
  38.  
  39. PR_BEGIN_EXTERN_C
  40.  
  41. struct JSRuntime {
  42.     /* Garbage collector state, used by jsgc.c. */
  43.     PRArenaPool         gcArenaPool;
  44.     PRArenaPool         gcFlagsPool;
  45.     PRHashTable         *gcRootsHash;
  46.     JSGCThing           *gcFreeList;
  47.     uint32              gcBytes;
  48.     uint32              gcLastBytes;
  49.     uint32              gcMaxBytes;
  50.     uint32              gcLevel;
  51.     uint32              gcNumber;
  52.     JSBool              gcPoke;
  53. #ifdef JS_GCMETER
  54.     JSGCStats           gcStats;
  55. #endif
  56.  
  57.     /* Literal table maintained by jsatom.c functions. */
  58.     JSAtomState         atomState;
  59.  
  60.     /* Random number generator state, used by jsmath.c. */
  61.     JSBool              rngInitialized;
  62.     int64               rngMultiplier;
  63.     int64               rngAddend;
  64.     int64               rngMask;
  65.     int64               rngSeed;
  66.     jsdouble            rngDscale;
  67.  
  68.     /* Well-known numbers held for use by this runtime's contexts. */
  69.     jsdouble            *jsNaN;
  70.     jsdouble            *jsNegativeInfinity;
  71.     jsdouble            *jsPositiveInfinity;
  72.  
  73.     /* Empty string held for use by this runtime's contexts. */
  74.     JSString            *emptyString;
  75.  
  76.     /* Weak links to properties, indexed by quickened get/set opcodes. */
  77.     JSPropertyCache     propertyCache;
  78.  
  79.     /* List of active contexts sharing this runtime. */
  80.     PRCList             contextList;
  81.  
  82.     /* These are used for debugging and declared in jsdbgapi.h. */
  83.     void                *interruptHandler;
  84.     void                *interruptHandlerData;
  85.     void                *newScriptHookProc;
  86.     void                *newScriptHookProcData;
  87.     void                *destroyScriptHookProc;
  88.     void                *destroyScriptHookProcData;
  89.  
  90.     /* More debugging state, see jsdbgapi.c. */
  91.     PRCList             trapList;
  92.     PRCList             watchPointList;
  93.  
  94. #ifdef JS_THREADSAFE
  95.     /* Hook for js_lock_runtime/js_unlock_runtime/js_is_runtime_locked. */
  96.     void                *lockData;
  97. #endif
  98. };
  99.  
  100. struct JSContext {
  101.     PRCList             links;
  102.  
  103.     /* Interpreter activation count. */
  104.     uintN               interpLevel;
  105.  
  106.     /* Runtime version control identifier and equality operators. */
  107.     JSVersion           version;
  108.     jsbytecode          jsop_eq;
  109.     jsbytecode          jsop_ne;
  110.  
  111.     /* Data shared by threads in an address space. */
  112.     JSRuntime           *runtime;
  113.  
  114.     /* Stack arena pool and frame pointer register. */
  115.     PRArenaPool         stackPool;
  116.     JSStackFrame        *fp;
  117.  
  118.     /* Temporary arena pools used while compiling and decompiling. */
  119.     PRArenaPool         codePool;
  120.     PRArenaPool         tempPool;
  121.  
  122.     /* Top-level object and pointer to top stack frame's scope chain. */
  123.     JSObject            *globalObject;
  124.  
  125.     /* Most recently created things by type, members of the GC's root set. */
  126.     JSGCThing           *newborn[GCX_NTYPES];
  127.  
  128.     /* Regular expression class statics (XXX not shared globally). */
  129.     JSRegExpStatics     regExpStatics;
  130.  
  131.     /* State for object and array toSource conversion. */
  132.     JSSharpObjectMap    sharpObjectMap;
  133.  
  134.     /* Last message string and trace file for debugging. */
  135.     char                *lastMessage;
  136. #ifdef DEBUG
  137.     void                *tracefp;
  138. #endif
  139.  
  140.     /* Per-context optional user callbacks. */
  141.     JSBranchCallback    branchCallback;
  142.     JSErrorReporter     errorReporter;
  143.  
  144.     /* Java environment and JS errors to throw as exceptions. */
  145.     void                *javaEnv;
  146.     void                *savedErrors;
  147.  
  148. #ifdef NETSCAPE_INTERNAL
  149.     /* I18n multibyte character scanning and transcoding support. */
  150.     const char          *charSetName;
  151.     size_t              charSetNameLength;
  152.     int                 charSetId;
  153.     JSCharScanner       charScanner;
  154. #endif
  155. };
  156.  
  157. typedef struct JSInterpreterHooks {
  158.     void (*destroyContext)(JSContext *cx);
  159.     void (*destroyScript)(JSContext *cx, JSScript *script);
  160.     void (*destroyFrame)(JSContext *cx, JSStackFrame *frame);
  161. } JSInterpreterHooks;
  162.  
  163. extern JSInterpreterHooks *js_InterpreterHooks;
  164.  
  165. extern JS_FRIEND_API(void)
  166. js_SetInterpreterHooks(JSInterpreterHooks *hooks);
  167.  
  168. extern JSContext *
  169. js_NewContext(JSRuntime *rt, size_t stacksize);
  170.  
  171. extern void
  172. js_DestroyContext(JSContext *cx);
  173.  
  174. extern JSContext *
  175. js_ContextIterator(JSRuntime *rt, JSContext **iterp);
  176.  
  177. /*
  178.  * Report an exception, which is currently realized as a printf-style format
  179.  * string and its arguments.
  180.  */
  181. #ifdef va_start
  182. extern void
  183. js_ReportErrorVA(JSContext *cx, const char *format, va_list ap);
  184. #endif
  185.  
  186. /*
  187.  * Report an exception using a previously composed JSErrorReport.
  188.  */
  189. extern JS_FRIEND_API(void)
  190. js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
  191.  
  192. extern void
  193. js_ReportIsNotDefined(JSContext *cx, const char *name);
  194.  
  195. PR_END_EXTERN_C
  196.  
  197. #endif /* jscntxt_h___ */
  198.