Back to index

lightning-sunbird  0.9+nobinonly
jsd.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Header for JavaScript Debugging support - Internal ONLY declarations
00040  */
00041 
00042 #ifndef jsd_h___
00043 #define jsd_h___
00044 
00045 /*
00046 * NOTE: This is a *private* header file and should only be included by
00047 * the sources in js/jsd. Defining EXPORT_JSD_API in an outside module
00048 * using jsd would be bad.
00049 */
00050 #define EXPORT_JSD_API 1 /* if used, must be set before include of jsdebug.h */
00051 
00052 /*
00053 * These can be controled by the makefile, but this allows a place to set
00054 * the values always used in the mozilla client, but perhaps done differnetly
00055 * in other embeddings.
00056 */
00057 #ifdef MOZILLA_CLIENT
00058 #define JSD_THREADSAFE 1
00059 /* define JSD_HAS_DANGEROUS_THREAD 1 */
00060 #define JSD_USE_NSPR_LOCKS 1
00061 #endif /* MOZILLA_CLIENT */
00062 
00063 
00064 /* Get jstypes.h included first. After that we can use PR macros for doing
00065 *  this extern "C" stuff!
00066 */
00067 #ifdef __cplusplus
00068 extern "C"
00069 {
00070 #endif
00071 #include "jstypes.h"
00072 #ifdef __cplusplus
00073 }
00074 #endif
00075 
00076 JS_BEGIN_EXTERN_C
00077 #include "jsprf.h"
00078 #include "jsutil.h" /* Added by JSIFY */
00079 #include "jshash.h" /* Added by JSIFY */
00080 #include "jsclist.h"
00081 #include "jsdebug.h"
00082 #include "jsapi.h"
00083 #include "jsdbgapi.h"
00084 #include "jsd_lock.h"
00085 
00086 #include <stdio.h>
00087 #include <stdlib.h>
00088 #include <string.h>
00089 
00090 #ifdef LIVEWIRE
00091 #include <base/pblock.h>
00092 #include <base/session.h>
00093 #include <frame/log.h>
00094 #include <frame/req.h>
00095 #endif /* LIVEWIRE */
00096 JS_END_EXTERN_C
00097 
00098 JS_BEGIN_EXTERN_C
00099 
00100 #define JSD_MAJOR_VERSION 1
00101 #define JSD_MINOR_VERSION 1
00102 
00103 /***************************************************************************/
00104 /* handy macros */
00105 #undef  CHECK_BIT_FLAG
00106 #define CHECK_BIT_FLAG(f,b) ((f)&(b))
00107 #undef  SET_BIT_FLAG
00108 #define SET_BIT_FLAG(f,b)   ((f)|=(b))
00109 #undef  CLEAR_BIT_FLAG
00110 #define CLEAR_BIT_FLAG(f,b) ((f)&=(~(b)))
00111 
00112 #define JSD_IS_DEBUG_ENABLED(jsdc,jsdscript)                                   \
00113         (!(((jsdc->flags & JSD_DEBUG_WHEN_SET) ? 1 : 0)  ^                     \
00114            ((jsdscript->flags & JSD_SCRIPT_DEBUG_BIT) ?  1 : 0)))
00115 #define JSD_IS_PROFILE_ENABLED(jsdc,jsdscript)                                 \
00116         ((jsdc->flags & JSD_COLLECT_PROFILE_DATA) &&                           \
00117          (!(((jsdc->flags & JSD_PROFILE_WHEN_SET) ? 1 : 0) ^                   \
00118             ((jsdscript->flags & JSD_SCRIPT_PROFILE_BIT) ? 1 : 0))))
00119 
00120 
00121 /***************************************************************************/
00122 /* These are not exposed in jsdebug.h - typedef here for consistency */
00123 
00124 typedef struct JSDExecHook          JSDExecHook;
00125 typedef struct JSDAtom              JSDAtom;
00126 typedef struct JSDProfileData       JSDProfileData;
00127 /***************************************************************************/
00128 /* Our structures */
00129 
00130 /*
00131 * XXX What I'm calling a JSDContext is really more of a JSDTaskState. 
00132 */
00133 
00134 struct JSDContext
00135 {
00136     JSCList                 links;      /* we are part of a JSCList */
00137     JSBool                  inited;
00138     void*                   data;
00139     uint32                  flags;
00140     JSD_ScriptHookProc      scriptHook;
00141     void*                   scriptHookData;
00142     JSD_ExecutionHookProc   interruptHook;
00143     void*                   interruptHookData;
00144     JSRuntime*              jsrt;
00145     JSD_ErrorReporter       errorReporter;
00146     void*                   errorReporterData;
00147     JSCList                 threadsStates;
00148     JSD_ExecutionHookProc   debugBreakHook;
00149     void*                   debugBreakHookData;
00150     JSD_ExecutionHookProc   debuggerHook;
00151     void*                   debuggerHookData;
00152     JSD_ExecutionHookProc   throwHook;
00153     void*                   throwHookData;
00154     JSD_CallHookProc        functionHook;
00155     void*                   functionHookData;
00156     JSD_CallHookProc        toplevelHook;
00157     void*                   toplevelHookData;
00158     JSContext*              dumbContext;
00159     JSObject*               glob;
00160     JSD_UserCallbacks       userCallbacks;
00161     void*                   user;
00162     JSCList                 scripts;
00163     JSHashTable*            scriptsTable;
00164     JSCList                 sources;
00165     JSCList                 removedSources;
00166     uintN                   sourceAlterCount;
00167     JSHashTable*            atoms;
00168     JSCList                 objectsList;
00169     JSHashTable*            objectsTable;
00170     JSDProfileData*         callingFunctionPData;
00171     int64                   lastReturnTime;
00172 #ifdef JSD_THREADSAFE
00173     void*                   scriptsLock;
00174     void*                   sourceTextLock;
00175     void*                   objectsLock;
00176     void*                   atomsLock;
00177     void*                   threadStatesLock;
00178 #endif /* JSD_THREADSAFE */
00179 #ifdef JSD_HAS_DANGEROUS_THREAD
00180     void*                   dangerousThread;
00181 #endif /* JSD_HAS_DANGEROUS_THREAD */
00182 
00183 };
00184 
00185 struct JSDScript
00186 {
00187     JSCList     links;      /* we are part of a JSCList */
00188     JSDContext* jsdc;       /* JSDContext for this jsdscript */
00189     JSScript*   script;     /* script we are wrapping */
00190     JSFunction* function;   /* back pointer to owning function (can be NULL) */
00191     uintN       lineBase;   /* we cache this */
00192     uintN       lineExtent; /* we cache this */
00193     JSCList     hooks;      /* JSCList of JSDExecHooks for this script */
00194     char*       url;
00195     uint32      flags;
00196     void*       data;
00197 
00198     JSDProfileData  *profileData;
00199 
00200 #ifdef LIVEWIRE
00201     LWDBGApp*    app;
00202     LWDBGScript* lwscript;
00203 #endif
00204 };
00205 
00206 struct JSDProfileData
00207 {
00208     JSDProfileData* caller;
00209     int64    lastCallStart;
00210     int64    runningTime;
00211     uintN    callCount;
00212     uintN    recurseDepth;
00213     uintN    maxRecurseDepth;
00214     jsdouble minExecutionTime;
00215     jsdouble maxExecutionTime;
00216     jsdouble totalExecutionTime;
00217     jsdouble minOwnExecutionTime;
00218     jsdouble maxOwnExecutionTime;
00219     jsdouble totalOwnExecutionTime;
00220 };
00221 
00222 struct JSDSourceText
00223 {
00224     JSCList          links;      /* we are part of a JSCList */
00225     char*            url;
00226     char*            text;
00227     uintN            textLength;
00228     uintN            textSpace;
00229     JSBool           dirty;
00230     JSDSourceStatus  status;
00231     uintN            alterCount;
00232     JSBool           doingEval;
00233 };
00234 
00235 struct JSDExecHook
00236 {
00237     JSCList               links;        /* we are part of a JSCList */
00238     JSDScript*            jsdscript;
00239     jsuword               pc;
00240     JSD_ExecutionHookProc hook;
00241     void*                 callerdata;
00242 };
00243 
00244 #define TS_HAS_DISABLED_FRAME 0x01
00245 
00246 struct JSDThreadState
00247 {
00248     JSCList             links;        /* we are part of a JSCList */
00249     JSContext*          context;
00250     void*               thread;
00251     JSCList             stack;
00252     uintN               stackDepth;
00253     uintN               flags;
00254 };
00255 
00256 struct JSDStackFrameInfo
00257 {
00258     JSCList             links;        /* we are part of a JSCList */
00259     JSDThreadState*     jsdthreadstate;
00260     JSDScript*          jsdscript;
00261     jsuword             pc;
00262     JSStackFrame*       fp;
00263 };
00264 
00265 #define GOT_PROTO   ((short) (1 << 0))
00266 #define GOT_PROPS   ((short) (1 << 1))
00267 #define GOT_PARENT  ((short) (1 << 2))
00268 #define GOT_CTOR    ((short) (1 << 3))
00269 
00270 struct JSDValue
00271 {
00272     jsval       val;
00273     intN        nref;
00274     JSCList     props;
00275     JSString*   string;
00276     const char* funName;
00277     const char* className;
00278     JSDValue*   proto;
00279     JSDValue*   parent;
00280     JSDValue*   ctor;
00281     uintN       flags;
00282 };
00283 
00284 struct JSDProperty
00285 {
00286     JSCList     links;      /* we are part of a JSCList */
00287     intN        nref;
00288     JSDValue*   val;
00289     JSDValue*   name;
00290     JSDValue*   alias;
00291     uintN       slot;
00292     uintN       flags;
00293 };
00294 
00295 struct JSDAtom
00296 {
00297     char* str;      /* must be first element in stuct for compare */
00298     intN  refcount;
00299 };
00300 
00301 struct JSDObject
00302 {
00303     JSCList     links;      /* we are part of a JSCList */
00304     JSObject*   obj;
00305     JSDAtom*    newURL;
00306     uintN       newLineno;
00307     JSDAtom*    ctorURL;
00308     uintN       ctorLineno;
00309     JSDAtom*    ctorName;
00310 };
00311 
00312 /***************************************************************************/
00313 /* Code validation support */
00314 
00315 #ifdef DEBUG
00316 extern void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc);
00317 extern void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript);
00318 extern void JSD_ASSERT_VALID_SOURCE_TEXT(JSDSourceText* jsdsrc);
00319 extern void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate);
00320 extern void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe);
00321 extern void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook);
00322 extern void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval);
00323 extern void JSD_ASSERT_VALID_PROPERTY(JSDProperty* jsdprop);
00324 extern void JSD_ASSERT_VALID_OBJECT(JSDObject* jsdobj);
00325 #else
00326 #define JSD_ASSERT_VALID_CONTEXT(x)     ((void)0)
00327 #define JSD_ASSERT_VALID_SCRIPT(x)      ((void)0)
00328 #define JSD_ASSERT_VALID_SOURCE_TEXT(x) ((void)0)
00329 #define JSD_ASSERT_VALID_THREAD_STATE(x)((void)0)
00330 #define JSD_ASSERT_VALID_STACK_FRAME(x) ((void)0)
00331 #define JSD_ASSERT_VALID_EXEC_HOOK(x)   ((void)0)
00332 #define JSD_ASSERT_VALID_VALUE(x)       ((void)0)
00333 #define JSD_ASSERT_VALID_PROPERTY(x)    ((void)0)
00334 #define JSD_ASSERT_VALID_OBJECT(x)      ((void)0)
00335 #endif
00336 
00337 /***************************************************************************/
00338 /* higher level functions */
00339 
00340 extern JSDContext*
00341 jsd_DebuggerOnForUser(JSRuntime*         jsrt,
00342                       JSD_UserCallbacks* callbacks,
00343                       void*              user);
00344 extern JSDContext*
00345 jsd_DebuggerOn(void);
00346 
00347 extern void
00348 jsd_DebuggerOff(JSDContext* jsdc);
00349 
00350 extern void
00351 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user);
00352 
00353 extern JSDContext*
00354 jsd_JSDContextForJSContext(JSContext* context);
00355 
00356 extern void*
00357 jsd_SetContextPrivate(JSDContext* jsdc, void *data);
00358 
00359 extern void*
00360 jsd_GetContextPrivate(JSDContext* jsdc);
00361 
00362 extern void
00363 jsd_ClearAllProfileData(JSDContext* jsdc);
00364 
00365 extern JSBool
00366 jsd_SetErrorReporter(JSDContext*       jsdc,
00367                      JSD_ErrorReporter reporter,
00368                      void*             callerdata);
00369 
00370 extern JSBool
00371 jsd_GetErrorReporter(JSDContext*        jsdc,
00372                      JSD_ErrorReporter* reporter,
00373                      void**             callerdata);
00374 
00375 JS_STATIC_DLL_CALLBACK(JSBool)
00376 jsd_DebugErrorHook(JSContext *cx, const char *message,
00377                    JSErrorReport *report, void *closure);
00378 
00379 /***************************************************************************/
00380 /* Script functions */
00381 
00382 extern JSBool
00383 jsd_InitScriptManager(JSDContext *jsdc);
00384 
00385 extern void
00386 jsd_DestroyScriptManager(JSDContext* jsdc);
00387 
00388 extern JSDScript*
00389 jsd_FindJSDScript(JSDContext*  jsdc,
00390                   JSScript     *script);
00391 
00392 extern JSDProfileData*
00393 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
00394 
00395 extern uint32
00396 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
00397 
00398 extern void
00399 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags);
00400 
00401 extern uintN
00402 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
00403 
00404 extern  uintN
00405 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
00406 
00407 extern jsdouble
00408 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
00409 
00410 extern jsdouble
00411 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
00412 
00413 extern jsdouble
00414 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
00415 
00416 extern jsdouble
00417 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
00418 
00419 extern jsdouble
00420 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
00421 
00422 extern jsdouble
00423 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
00424 
00425 extern void
00426 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
00427 
00428 extern JSScript *
00429 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script);
00430 
00431 extern JSFunction *
00432 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script);
00433 
00434 extern JSDScript*
00435 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
00436 
00437 extern void *
00438 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data);
00439 
00440 extern void *
00441 jsd_GetScriptPrivate (JSDScript *jsdscript);
00442 
00443 extern JSBool
00444 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
00445 
00446 extern const char*
00447 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
00448 
00449 extern const char*
00450 jsd_GetScriptFunctionName(JSDContext* jsdc, JSDScript *jsdscript);
00451 
00452 extern uintN
00453 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
00454 
00455 extern uintN
00456 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
00457 
00458 extern JSBool
00459 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
00460 
00461 extern JSBool
00462 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
00463 
00464 extern jsuword
00465 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line);
00466 
00467 extern uintN
00468 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
00469 
00470 extern void JS_DLL_CALLBACK
00471 jsd_NewScriptHookProc(
00472                 JSContext   *cx,
00473                 const char  *filename,      /* URL this script loads from */
00474                 uintN       lineno,         /* line where this script starts */
00475                 JSScript    *script,
00476                 JSFunction  *fun,
00477                 void*       callerdata);
00478 
00479 extern void JS_DLL_CALLBACK
00480 jsd_DestroyScriptHookProc(
00481                 JSContext   *cx,
00482                 JSScript    *script,
00483                 void*       callerdata);
00484 
00485 /* Script execution hook functions */
00486 
00487 extern JSBool
00488 jsd_SetExecutionHook(JSDContext*           jsdc,
00489                      JSDScript*            jsdscript,
00490                      jsuword               pc,
00491                      JSD_ExecutionHookProc hook,
00492                      void*                 callerdata);
00493 
00494 extern JSBool
00495 jsd_ClearExecutionHook(JSDContext*           jsdc,
00496                        JSDScript*            jsdscript,
00497                        jsuword               pc);
00498 
00499 extern JSBool
00500 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
00501 
00502 extern JSBool
00503 jsd_ClearAllExecutionHooks(JSDContext* jsdc);
00504 
00505 extern void
00506 jsd_ScriptCreated(JSDContext* jsdc,
00507                   JSContext   *cx,
00508                   const char  *filename,    /* URL this script loads from */
00509                   uintN       lineno,       /* line where this script starts */
00510                   JSScript    *script,
00511                   JSFunction  *fun);
00512 
00513 extern void
00514 jsd_ScriptDestroyed(JSDContext* jsdc,
00515                     JSContext   *cx,
00516                     JSScript    *script);
00517 
00518 /***************************************************************************/
00519 /* Source Text functions */
00520 
00521 extern JSDSourceText*
00522 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
00523 
00524 extern JSDSourceText*
00525 jsd_FindSourceForURL(JSDContext* jsdc, const char* url);
00526 
00527 extern const char*
00528 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
00529 
00530 extern JSBool
00531 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
00532                   const char** ppBuf, intN* pLen);
00533 
00534 extern void
00535 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
00536 
00537 extern JSDSourceStatus
00538 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
00539 
00540 extern JSBool
00541 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
00542 
00543 extern void
00544 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, JSBool dirty);
00545 
00546 extern uintN
00547 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
00548 
00549 extern uintN
00550 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
00551 
00552 extern JSDSourceText*
00553 jsd_NewSourceText(JSDContext* jsdc, const char* url);
00554 
00555 extern JSDSourceText*
00556 jsd_AppendSourceText(JSDContext* jsdc,
00557                      JSDSourceText* jsdsrc,
00558                      const char* text,       /* *not* zero terminated */
00559                      size_t length,
00560                      JSDSourceStatus status);
00561 
00562 extern JSDSourceText*
00563 jsd_AppendUCSourceText(JSDContext* jsdc,
00564                        JSDSourceText* jsdsrc,
00565                        const jschar* text,       /* *not* zero terminated */
00566                        size_t length,
00567                        JSDSourceStatus status);
00568 
00569 /* convienence function for adding complete source of url in one call */
00570 extern JSBool
00571 jsd_AddFullSourceText(JSDContext* jsdc,
00572                       const char* text,       /* *not* zero terminated */
00573                       size_t      length,
00574                       const char* url);
00575 
00576 extern void
00577 jsd_DestroyAllSources(JSDContext* jsdc);
00578 
00579 extern const char*
00580 jsd_BuildNormalizedURL(const char* url_string);
00581 
00582 extern void
00583 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
00584 
00585 extern void
00586 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
00587 
00588 /***************************************************************************/
00589 /* Interrupt Hook functions */
00590 
00591 extern JSBool
00592 jsd_SetInterruptHook(JSDContext*           jsdc,
00593                      JSD_ExecutionHookProc hook,
00594                      void*                 callerdata);
00595 
00596 extern JSBool
00597 jsd_ClearInterruptHook(JSDContext* jsdc);
00598 
00599 extern JSBool
00600 jsd_SetDebugBreakHook(JSDContext*           jsdc,
00601                       JSD_ExecutionHookProc hook,
00602                       void*                 callerdata);
00603 
00604 extern JSBool
00605 jsd_ClearDebugBreakHook(JSDContext* jsdc);
00606 
00607 extern JSBool
00608 jsd_SetDebuggerHook(JSDContext*           jsdc,
00609                     JSD_ExecutionHookProc hook,
00610                     void*                 callerdata);
00611 
00612 extern JSBool
00613 jsd_ClearDebuggerHook(JSDContext* jsdc);
00614 
00615 extern JSTrapStatus
00616 jsd_CallExecutionHook(JSDContext*           jsdc,
00617                       JSContext*            cx,
00618                       uintN                 type,
00619                       JSD_ExecutionHookProc hook,
00620                       void*                 hookData,
00621                       jsval*                rval);
00622 
00623 extern JSBool
00624 jsd_CallCallHook (JSDContext*      jsdc,
00625                   JSContext*       cx,
00626                   uintN            type,
00627                   JSD_CallHookProc hook,
00628                   void*            hookData);
00629 
00630 extern JSBool
00631 jsd_SetThrowHook(JSDContext*           jsdc,
00632                  JSD_ExecutionHookProc hook,
00633                  void*                 callerdata);
00634 extern JSBool
00635 jsd_ClearThrowHook(JSDContext* jsdc);
00636 
00637 extern JSTrapStatus JS_DLL_CALLBACK
00638 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
00639                     jsval *rval, void *closure);
00640 
00641 extern JSTrapStatus JS_DLL_CALLBACK
00642 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
00643                  jsval *rval, void *closure);
00644 
00645 extern JSBool
00646 jsd_SetFunctionHook(JSDContext*      jsdc,
00647                     JSD_CallHookProc hook,
00648                     void*            callerdata);
00649 
00650 extern JSBool
00651 jsd_ClearFunctionHook(JSDContext* jsdc);
00652 
00653 extern JSBool
00654 jsd_SetTopLevelHook(JSDContext*      jsdc,
00655                     JSD_CallHookProc hook,
00656                     void*            callerdata);
00657 
00658 extern JSBool
00659 jsd_ClearTopLevelHook(JSDContext* jsdc);
00660 
00661 /***************************************************************************/
00662 /* Stack Frame functions */
00663 
00664 extern uintN
00665 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
00666 
00667 extern JSDStackFrameInfo*
00668 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
00669 
00670 extern JSContext*
00671 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
00672 
00673 extern JSDStackFrameInfo*
00674 jsd_GetCallingStackFrame(JSDContext* jsdc,
00675                          JSDThreadState* jsdthreadstate,
00676                          JSDStackFrameInfo* jsdframe);
00677 
00678 extern JSDScript*
00679 jsd_GetScriptForStackFrame(JSDContext* jsdc,
00680                            JSDThreadState* jsdthreadstate,
00681                            JSDStackFrameInfo* jsdframe);
00682 
00683 extern jsuword
00684 jsd_GetPCForStackFrame(JSDContext* jsdc,
00685                        JSDThreadState* jsdthreadstate,
00686                        JSDStackFrameInfo* jsdframe);
00687 
00688 extern JSDValue*
00689 jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
00690                                JSDThreadState* jsdthreadstate,
00691                                JSDStackFrameInfo* jsdframe);
00692 
00693 extern JSDValue*
00694 jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
00695                                JSDThreadState* jsdthreadstate,
00696                                JSDStackFrameInfo* jsdframe);
00697 
00698 extern JSBool
00699 jsd_IsStackFrameNative(JSDContext* jsdc, 
00700                        JSDThreadState* jsdthreadstate,
00701                        JSDStackFrameInfo* jsdframe);
00702 
00703 extern JSBool
00704 jsd_IsStackFrameDebugger(JSDContext* jsdc, 
00705                          JSDThreadState* jsdthreadstate,
00706                          JSDStackFrameInfo* jsdframe);
00707 
00708 extern JSBool
00709 jsd_IsStackFrameConstructing(JSDContext* jsdc, 
00710                              JSDThreadState* jsdthreadstate,
00711                              JSDStackFrameInfo* jsdframe);
00712 
00713 extern JSDValue*
00714 jsd_GetThisForStackFrame(JSDContext* jsdc,
00715                          JSDThreadState* jsdthreadstate,
00716                          JSDStackFrameInfo* jsdframe);
00717 
00718 extern const char*
00719 jsd_GetNameForStackFrame(JSDContext* jsdc, 
00720                          JSDThreadState* jsdthreadstate,
00721                          JSDStackFrameInfo* jsdframe);
00722 
00723 extern JSDThreadState*
00724 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx);
00725 
00726 extern void
00727 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
00728 
00729 extern JSBool
00730 jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
00731                                  JSDThreadState* jsdthreadstate,
00732                                  JSDStackFrameInfo* jsdframe,
00733                                  const jschar *bytes, uintN length,
00734                                  const char *filename, uintN lineno,
00735                                  JSBool eatExceptions, jsval *rval);
00736 
00737 extern JSBool
00738 jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
00739                                JSDThreadState* jsdthreadstate,
00740                                JSDStackFrameInfo* jsdframe,
00741                                const char *bytes, uintN length,
00742                                const char *filename, uintN lineno,
00743                                JSBool eatExceptions, jsval *rval);
00744 
00745 extern JSString*
00746 jsd_ValToStringInStackFrame(JSDContext* jsdc,
00747                             JSDThreadState* jsdthreadstate,
00748                             JSDStackFrameInfo* jsdframe,
00749                             jsval val);
00750 
00751 extern JSBool
00752 jsd_IsValidThreadState(JSDContext*        jsdc,
00753                        JSDThreadState*    jsdthreadstate);
00754 
00755 extern JSBool
00756 jsd_IsValidFrameInThreadState(JSDContext*        jsdc,
00757                               JSDThreadState*    jsdthreadstate,
00758                               JSDStackFrameInfo* jsdframe);
00759 
00760 extern JSDValue*
00761 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
00762 
00763 extern JSBool
00764 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, 
00765                  JSDValue* jsdval);
00766 
00767 /***************************************************************************/
00768 /* Locking support */
00769 
00770 /* protos are in js_lock.h for:
00771  *      jsd_CreateLock
00772  *      jsd_Lock
00773  *      jsd_Unlock
00774  *      jsd_IsLocked
00775  *      jsd_CurrentThread
00776  */
00777 
00778 #ifdef JSD_THREADSAFE
00779 
00780 /* the system-wide lock */
00781 extern void* _jsd_global_lock;
00782 #define JSD_LOCK()                               \
00783     JS_BEGIN_MACRO                               \
00784         if(!_jsd_global_lock)                    \
00785             _jsd_global_lock = jsd_CreateLock(); \
00786         JS_ASSERT(_jsd_global_lock);             \
00787         jsd_Lock(_jsd_global_lock);              \
00788     JS_END_MACRO
00789 
00790 #define JSD_UNLOCK()                             \
00791     JS_BEGIN_MACRO                               \
00792         JS_ASSERT(_jsd_global_lock);             \
00793         jsd_Unlock(_jsd_global_lock);            \
00794     JS_END_MACRO
00795 
00796 /* locks for the subsystems of a given context */
00797 #define JSD_INIT_LOCKS(jsdc)                                    \
00798     ( (NULL != (jsdc->scriptsLock      = jsd_CreateLock())) &&  \
00799       (NULL != (jsdc->sourceTextLock   = jsd_CreateLock())) &&  \
00800       (NULL != (jsdc->atomsLock        = jsd_CreateLock())) &&  \
00801       (NULL != (jsdc->objectsLock      = jsd_CreateLock())) &&  \
00802       (NULL != (jsdc->threadStatesLock = jsd_CreateLock())) )
00803 
00804 #define JSD_LOCK_SCRIPTS(jsdc)        jsd_Lock(jsdc->scriptsLock)
00805 #define JSD_UNLOCK_SCRIPTS(jsdc)      jsd_Unlock(jsdc->scriptsLock)
00806 
00807 #define JSD_LOCK_SOURCE_TEXT(jsdc)    jsd_Lock(jsdc->sourceTextLock)
00808 #define JSD_UNLOCK_SOURCE_TEXT(jsdc)  jsd_Unlock(jsdc->sourceTextLock)
00809 
00810 #define JSD_LOCK_ATOMS(jsdc)          jsd_Lock(jsdc->atomsLock)
00811 #define JSD_UNLOCK_ATOMS(jsdc)        jsd_Unlock(jsdc->atomsLock)
00812 
00813 #define JSD_LOCK_OBJECTS(jsdc)        jsd_Lock(jsdc->objectsLock)
00814 #define JSD_UNLOCK_OBJECTS(jsdc)      jsd_Unlock(jsdc->objectsLock)
00815 
00816 #define JSD_LOCK_THREADSTATES(jsdc)   jsd_Lock(jsdc->threadStatesLock)
00817 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock)
00818 
00819 #else  /* !JSD_THREADSAFE */
00820 
00821 #define JSD_LOCK()                    ((void)0)
00822 #define JSD_UNLOCK()                  ((void)0)
00823 
00824 #define JSD_INIT_LOCKS(jsdc)          1
00825 
00826 #define JSD_LOCK_SCRIPTS(jsdc)        ((void)0)
00827 #define JSD_UNLOCK_SCRIPTS(jsdc)      ((void)0)
00828 
00829 #define JSD_LOCK_SOURCE_TEXT(jsdc)    ((void)0)
00830 #define JSD_UNLOCK_SOURCE_TEXT(jsdc)  ((void)0)
00831 
00832 #define JSD_LOCK_ATOMS(jsdc)          ((void)0)
00833 #define JSD_UNLOCK_ATOMS(jsdc)        ((void)0)
00834 
00835 #define JSD_LOCK_OBJECTS(jsdc)        ((void)0)
00836 #define JSD_UNLOCK_OBJECTS(jsdc)      ((void)0)
00837 
00838 #define JSD_LOCK_THREADSTATES(jsdc)   ((void)0)
00839 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0)
00840 
00841 #endif /* JSD_THREADSAFE */
00842 
00843 /* NOTE: These are intended for ASSERTs. Thus we supply checks for both
00844  * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in
00845  * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds
00846  * without having to special case things in the code.
00847  */
00848 #if defined(JSD_THREADSAFE) && defined(DEBUG)
00849 #define JSD_SCRIPTS_LOCKED(jsdc)        (jsd_IsLocked(jsdc->scriptsLock))
00850 #define JSD_SOURCE_TEXT_LOCKED(jsdc)    (jsd_IsLocked(jsdc->sourceTextLock))
00851 #define JSD_ATOMS_LOCKED(jsdc)          (jsd_IsLocked(jsdc->atomsLock))
00852 #define JSD_OBJECTS_LOCKED(jsdc)        (jsd_IsLocked(jsdc->objectsLock))
00853 #define JSD_THREADSTATES_LOCKED(jsdc)   (jsd_IsLocked(jsdc->threadStatesLock))
00854 #define JSD_SCRIPTS_UNLOCKED(jsdc)      (!jsd_IsLocked(jsdc->scriptsLock))
00855 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc)  (!jsd_IsLocked(jsdc->sourceTextLock))
00856 #define JSD_ATOMS_UNLOCKED(jsdc)        (!jsd_IsLocked(jsdc->atomsLock))
00857 #define JSD_OBJECTS_UNLOCKED(jsdc)      (!jsd_IsLocked(jsdc->objectsLock))
00858 #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock))
00859 #else
00860 #define JSD_SCRIPTS_LOCKED(jsdc)        1
00861 #define JSD_SOURCE_TEXT_LOCKED(jsdc)    1
00862 #define JSD_ATOMS_LOCKED(jsdc)          1
00863 #define JSD_OBJECTS_LOCKED(jsdc)        1
00864 #define JSD_THREADSTATES_LOCKED(jsdc)   1
00865 #define JSD_SCRIPTS_UNLOCKED(jsdc)      1
00866 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc)  1
00867 #define JSD_ATOMS_UNLOCKED(jsdc)        1
00868 #define JSD_OBJECTS_UNLOCKED(jsdc)      1
00869 #define JSD_THREADSTATES_UNLOCKED(jsdc) 1
00870 #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */
00871 
00872 /***************************************************************************/
00873 /* Threading support */
00874 
00875 #ifdef JSD_THREADSAFE
00876 
00877 #define JSD_CURRENT_THREAD()        jsd_CurrentThread()
00878 
00879 #else  /* !JSD_THREADSAFE */
00880 
00881 #define JSD_CURRENT_THREAD()        ((void*)0)
00882 
00883 #endif /* JSD_THREADSAFE */
00884 
00885 /***************************************************************************/
00886 /* Dangerous thread support */
00887 
00888 #ifdef JSD_HAS_DANGEROUS_THREAD
00889 
00890 #define JSD_IS_DANGEROUS_THREAD(jsdc) \
00891     (JSD_CURRENT_THREAD() == jsdc->dangerousThread)
00892 
00893 #else  /* !JSD_HAS_DANGEROUS_THREAD */
00894 
00895 #define JSD_IS_DANGEROUS_THREAD(jsdc)   0
00896 
00897 #endif /* JSD_HAS_DANGEROUS_THREAD */
00898 
00899 /***************************************************************************/
00900 /* Value and Property Functions */
00901 
00902 extern JSDValue*
00903 jsd_NewValue(JSDContext* jsdc, jsval val);
00904 
00905 extern void
00906 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval);
00907 
00908 extern jsval
00909 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
00910 
00911 extern void
00912 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
00913 
00914 /**************************************************/
00915 
00916 extern JSBool
00917 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
00918 
00919 extern JSBool
00920 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
00921 
00922 extern JSBool
00923 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
00924 
00925 extern JSBool
00926 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
00927 
00928 extern JSBool
00929 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
00930 
00931 extern JSBool
00932 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
00933 
00934 extern JSBool
00935 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
00936 
00937 extern JSBool
00938 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
00939 
00940 extern JSBool
00941 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
00942 
00943 extern JSBool
00944 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
00945 
00946 extern JSBool
00947 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
00948 
00949 /**************************************************/
00950 
00951 extern JSBool
00952 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
00953 
00954 extern int32
00955 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
00956 
00957 extern jsdouble*
00958 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
00959 
00960 extern JSString*
00961 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
00962 
00963 extern const char*
00964 jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval);
00965 
00966 /**************************************************/
00967 
00968 extern uintN
00969 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
00970 
00971 extern JSDProperty*
00972 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
00973 
00974 extern JSDProperty*
00975 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
00976 
00977 extern JSDValue*
00978 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
00979 
00980 extern JSDValue*
00981 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
00982 
00983 extern JSDValue*
00984 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
00985 
00986 extern const char*
00987 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
00988 
00989 /**************************************************/
00990 
00991 extern void
00992 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
00993 
00994 extern JSDValue*
00995 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
00996 
00997 extern JSDValue*
00998 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
00999 
01000 extern JSDValue*
01001 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
01002 
01003 extern uintN
01004 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
01005 
01006 extern uintN
01007 jsd_GetPropertyVarArgSlot(JSDContext* jsdc, JSDProperty* jsdprop);
01008 
01009 /**************************************************/
01010 /* Stepping Functions */
01011 
01012 extern void * JS_DLL_CALLBACK
01013 jsd_FunctionCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
01014                      JSBool *ok, void *closure);
01015 
01016 extern void * JS_DLL_CALLBACK
01017 jsd_TopLevelCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
01018                      JSBool *ok, void *closure);
01019 
01020 /**************************************************/
01021 /* Object Functions */
01022 
01023 extern JSBool
01024 jsd_InitObjectManager(JSDContext* jsdc);
01025 
01026 extern void
01027 jsd_DestroyObjectManager(JSDContext* jsdc);
01028 
01029 extern void JS_DLL_CALLBACK
01030 jsd_ObjectHook(JSContext *cx, JSObject *obj, JSBool isNew, void *closure);
01031 
01032 extern void
01033 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
01034                  JSStackFrame *fp);
01035 
01036 extern JSDObject*
01037 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
01038 
01039 extern JSObject*
01040 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
01041 
01042 extern const char*
01043 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
01044 
01045 extern uintN
01046 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
01047 
01048 extern const char*
01049 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
01050 
01051 extern uintN
01052 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
01053 
01054 extern const char*
01055 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
01056 
01057 extern JSDObject*
01058 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
01059 
01060 extern JSDObject*
01061 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
01062 
01063 /*
01064 * returns new refcounted JSDValue
01065 */
01066 extern JSDValue*
01067 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
01068 
01069 /**************************************************/
01070 /* Atom Functions */
01071 
01072 extern JSBool
01073 jsd_CreateAtomTable(JSDContext* jsdc);
01074 
01075 extern void
01076 jsd_DestroyAtomTable(JSDContext* jsdc);
01077 
01078 extern JSDAtom*
01079 jsd_AddAtom(JSDContext* jsdc, const char* str);
01080 
01081 extern JSDAtom*
01082 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom);
01083 
01084 extern void
01085 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom);
01086 
01087 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str))
01088 
01089 /***************************************************************************/
01090 /* Livewire specific API */
01091 #ifdef LIVEWIRE
01092 
01093 extern LWDBGScript*
01094 jsdlw_GetLWScript(JSDContext* jsdc, JSDScript* jsdscript);
01095 
01096 extern char*
01097 jsdlw_BuildAppRelativeFilename(LWDBGApp* app, const char* filename);
01098 
01099 extern JSDSourceText*
01100 jsdlw_PreLoadSource(JSDContext* jsdc, LWDBGApp* app,
01101                      const char* filename, JSBool clear);
01102 
01103 extern JSDSourceText*
01104 jsdlw_ForceLoadSource(JSDContext* jsdc, JSDSourceText* jsdsrc);
01105 
01106 extern JSBool
01107 jsdlw_UserCodeAtPC(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
01108 
01109 extern JSBool
01110 jsdlw_RawToProcessedLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
01111                                uintN lineIn, uintN* lineOut);
01112 
01113 extern JSBool
01114 jsdlw_ProcessedToRawLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
01115                                uintN lineIn, uintN* lineOut);
01116 
01117 
01118 #if 0
01119 /* our hook proc for LiveWire app start/stop */
01120 extern void JS_DLL_CALLBACK
01121 jsdlw_AppHookProc(LWDBGApp* app,
01122                   JSBool created,
01123                   void *callerdata);
01124 #endif
01125 
01126 
01127 #endif
01128 /***************************************************************************/
01129 
01130 JS_END_EXTERN_C
01131 
01132 #endif /* jsd_h___ */