Back to index

lightning-sunbird  0.9+nobinonly
jsdbgapi.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef jsdbgapi_h___
00041 #define jsdbgapi_h___
00042 /*
00043  * JS debugger API.
00044  */
00045 #include "jsapi.h"
00046 #include "jsopcode.h"
00047 #include "jsprvtd.h"
00048 
00049 JS_BEGIN_EXTERN_C
00050 
00051 extern void
00052 js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
00053 
00054 extern JS_PUBLIC_API(JSBool)
00055 JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
00056            JSTrapHandler handler, void *closure);
00057 
00058 extern JS_PUBLIC_API(JSOp)
00059 JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
00060 
00061 extern JS_PUBLIC_API(void)
00062 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
00063              JSTrapHandler *handlerp, void **closurep);
00064 
00065 extern JS_PUBLIC_API(void)
00066 JS_ClearScriptTraps(JSContext *cx, JSScript *script);
00067 
00068 extern JS_PUBLIC_API(void)
00069 JS_ClearAllTraps(JSContext *cx);
00070 
00071 extern JS_PUBLIC_API(JSTrapStatus)
00072 JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
00073 
00074 extern JS_PUBLIC_API(JSBool)
00075 JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure);
00076 
00077 extern JS_PUBLIC_API(JSBool)
00078 JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep);
00079 
00080 /************************************************************************/
00081 
00082 extern JS_PUBLIC_API(JSBool)
00083 JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
00084                  JSWatchPointHandler handler, void *closure);
00085 
00086 extern JS_PUBLIC_API(JSBool)
00087 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
00088                    JSWatchPointHandler *handlerp, void **closurep);
00089 
00090 extern JS_PUBLIC_API(JSBool)
00091 JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
00092 
00093 extern JS_PUBLIC_API(JSBool)
00094 JS_ClearAllWatchPoints(JSContext *cx);
00095 
00096 #ifdef JS_HAS_OBJ_WATCHPOINT
00097 /*
00098  * Hide these non-API function prototypes by testing whether the internal
00099  * header file "jsconfig.h" has been included.
00100  */
00101 extern void
00102 js_MarkWatchPoints(JSContext *cx);
00103 
00104 extern JSScopeProperty *
00105 js_FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id);
00106 
00107 extern JSPropertyOp
00108 js_GetWatchedSetter(JSRuntime *rt, JSScope *scope,
00109                     const JSScopeProperty *sprop);
00110 
00111 extern JSBool JS_DLL_CALLBACK
00112 js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00113 
00114 extern JSBool JS_DLL_CALLBACK
00115 js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
00116                      jsval *rval);
00117 
00118 extern JSPropertyOp
00119 js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter);
00120 
00121 #endif /* JS_HAS_OBJ_WATCHPOINT */
00122 
00123 /************************************************************************/
00124 
00125 extern JS_PUBLIC_API(uintN)
00126 JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
00127 
00128 extern JS_PUBLIC_API(jsbytecode *)
00129 JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
00130 
00131 extern JS_PUBLIC_API(JSScript *)
00132 JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
00133 
00134 extern JS_PUBLIC_API(JSNative)
00135 JS_GetFunctionNative(JSContext *cx, JSFunction *fun);
00136 
00137 extern JS_PUBLIC_API(JSPrincipals *)
00138 JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
00139 
00140 /*
00141  * Stack Frame Iterator
00142  *
00143  * Used to iterate through the JS stack frames to extract
00144  * information from the frames.
00145  */
00146 
00147 extern JS_PUBLIC_API(JSStackFrame *)
00148 JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
00149 
00150 extern JS_PUBLIC_API(JSScript *)
00151 JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
00152 
00153 extern JS_PUBLIC_API(jsbytecode *)
00154 JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
00155 
00156 /*
00157  * Get the closest scripted frame below fp.  If fp is null, start from cx->fp.
00158  */
00159 extern JS_PUBLIC_API(JSStackFrame *)
00160 JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
00161 
00162 /*
00163  * Return a weak reference to fp's principals.  A null return does not denote
00164  * an error, it means there are no principals.
00165  */
00166 extern JS_PUBLIC_API(JSPrincipals *)
00167 JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
00168 
00169 /*
00170  * This API is like JS_StackFramePrincipals(cx, caller), except that if
00171  * cx->runtime->findObjectPrincipals is non-null, it returns the weaker of
00172  * the caller's principals and the object principals of fp's callee function
00173  * object (fp->argv[-2]), which is eval, Function, or a similar eval-like
00174  * method.  The caller parameter should be JS_GetScriptedCaller(cx, fp).
00175  *
00176  * All eval-like methods must use JS_EvalFramePrincipals to acquire a weak
00177  * reference to the correct principals for the eval call to be secure, given
00178  * an embedding that calls JS_SetObjectPrincipalsFinder (see jsapi.h).
00179  */
00180 extern JS_PUBLIC_API(JSPrincipals *)
00181 JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller);
00182 
00183 extern JS_PUBLIC_API(void *)
00184 JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
00185 
00186 extern JS_PUBLIC_API(void)
00187 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
00188 
00189 extern JS_PUBLIC_API(void *)
00190 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
00191 
00192 extern JS_PUBLIC_API(JSBool)
00193 JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp);
00194 
00195 /* this is deprecated, use JS_GetFrameScopeChain instead */
00196 extern JS_PUBLIC_API(JSObject *)
00197 JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
00198 
00199 extern JS_PUBLIC_API(JSObject *)
00200 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
00201 
00202 extern JS_PUBLIC_API(JSObject *)
00203 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
00204 
00205 extern JS_PUBLIC_API(JSObject *)
00206 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp);
00207 
00208 extern JS_PUBLIC_API(JSFunction *)
00209 JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
00210 
00211 extern JS_PUBLIC_API(JSObject *)
00212 JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
00213 
00214 /* XXXrginda Initially published with typo */
00215 #define JS_IsContructorFrame JS_IsConstructorFrame
00216 extern JS_PUBLIC_API(JSBool)
00217 JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
00218 
00219 extern JS_PUBLIC_API(JSBool)
00220 JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
00221 
00222 extern JS_PUBLIC_API(jsval)
00223 JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
00224 
00225 extern JS_PUBLIC_API(void)
00226 JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
00227 
00231 extern JS_PUBLIC_API(JSObject *)
00232 JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp);
00233 
00234 /************************************************************************/
00235 
00236 extern JS_PUBLIC_API(const char *)
00237 JS_GetScriptFilename(JSContext *cx, JSScript *script);
00238 
00239 extern JS_PUBLIC_API(uintN)
00240 JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
00241 
00242 extern JS_PUBLIC_API(uintN)
00243 JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
00244 
00245 extern JS_PUBLIC_API(JSVersion)
00246 JS_GetScriptVersion(JSContext *cx, JSScript *script);
00247 
00248 /************************************************************************/
00249 
00250 /*
00251  * Hook setters for script creation and destruction, see jsprvtd.h for the
00252  * typedefs.  These macros provide binary compatibility and newer, shorter
00253  * synonyms.
00254  */
00255 #define JS_SetNewScriptHook     JS_SetNewScriptHookProc
00256 #define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
00257 
00258 extern JS_PUBLIC_API(void)
00259 JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
00260 
00261 extern JS_PUBLIC_API(void)
00262 JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
00263                         void *callerdata);
00264 
00265 /************************************************************************/
00266 
00267 extern JS_PUBLIC_API(JSBool)
00268 JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
00269                           const jschar *chars, uintN length,
00270                           const char *filename, uintN lineno,
00271                           jsval *rval);
00272 
00273 extern JS_PUBLIC_API(JSBool)
00274 JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
00275                         const char *bytes, uintN length,
00276                         const char *filename, uintN lineno,
00277                         jsval *rval);
00278 
00279 /************************************************************************/
00280 
00281 typedef struct JSPropertyDesc {
00282     jsval           id;         /* primary id, a string or int */
00283     jsval           value;      /* property value */
00284     uint8           flags;      /* flags, see below */
00285     uint8           spare;      /* unused */
00286     uint16          slot;       /* argument/variable slot */
00287     jsval           alias;      /* alias id if JSPD_ALIAS flag */
00288 } JSPropertyDesc;
00289 
00290 #define JSPD_ENUMERATE  0x01    /* visible to for/in loop */
00291 #define JSPD_READONLY   0x02    /* assignment is error */
00292 #define JSPD_PERMANENT  0x04    /* property cannot be deleted */
00293 #define JSPD_ALIAS      0x08    /* property has an alias id */
00294 #define JSPD_ARGUMENT   0x10    /* argument to function */
00295 #define JSPD_VARIABLE   0x20    /* local variable in function */
00296 #define JSPD_EXCEPTION  0x40    /* exception occurred fetching the property, */
00297                                 /* value is exception */
00298 #define JSPD_ERROR      0x80    /* native getter returned JS_FALSE without */
00299                                 /* throwing an exception */
00300 
00301 typedef struct JSPropertyDescArray {
00302     uint32          length;     /* number of elements in array */
00303     JSPropertyDesc  *array;     /* alloc'd by Get, freed by Put */
00304 } JSPropertyDescArray;
00305 
00306 extern JS_PUBLIC_API(JSScopeProperty *)
00307 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
00308 
00309 extern JS_PUBLIC_API(JSBool)
00310 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
00311                    JSPropertyDesc *pd);
00312 
00313 extern JS_PUBLIC_API(JSBool)
00314 JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
00315 
00316 extern JS_PUBLIC_API(void)
00317 JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
00318 
00319 /************************************************************************/
00320 
00321 extern JS_PUBLIC_API(JSBool)
00322 JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
00323 
00324 extern JS_PUBLIC_API(JSBool)
00325 JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
00326 
00327 extern JS_PUBLIC_API(JSBool)
00328 JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
00329 
00330 extern JS_PUBLIC_API(JSBool)
00331 JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
00332 
00333 extern JS_PUBLIC_API(JSBool)
00334 JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure);
00335 
00336 extern JS_PUBLIC_API(JSBool)
00337 JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure);
00338 
00339 extern JS_PUBLIC_API(JSBool)
00340 JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
00341 
00342 /************************************************************************/
00343 
00344 extern JS_PUBLIC_API(size_t)
00345 JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
00346 
00347 extern JS_PUBLIC_API(size_t)
00348 JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
00349 
00350 extern JS_PUBLIC_API(size_t)
00351 JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
00352 
00353 /*
00354  * Get the top-most running script on cx starting from fp, or from the top of
00355  * cx's frame stack if fp is null, and return its script filename flags.  If
00356  * the script has a null filename member, return JSFILENAME_NULL.
00357  */
00358 extern JS_PUBLIC_API(uint32)
00359 JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
00360 
00361 /*
00362  * Get the script filename flags for the script.  If the script doesn't have a
00363  * filename, return JSFILENAME_NULL.
00364  */
00365 extern JS_PUBLIC_API(uint32)
00366 JS_GetScriptFilenameFlags(JSScript *script);
00367 
00368 /*
00369  * Associate flags with a script filename prefix in rt, so that any subsequent
00370  * script compilation will inherit those flags if the script's filename is the
00371  * same as prefix, or if prefix is a substring of the script's filename.
00372  *
00373  * The API defines only one flag bit, JSFILENAME_SYSTEM, leaving the remaining
00374  * 31 bits up to the API client to define.  The union of all 32 bits must not
00375  * be a legal combination, however, in order to preserve JSFILENAME_NULL as a
00376  * unique value.  API clients may depend on JSFILENAME_SYSTEM being a set bit
00377  * in JSFILENAME_NULL -- a script with a null filename member is presumed to
00378  * be a "system" script.
00379  */
00380 extern JS_PUBLIC_API(JSBool)
00381 JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags);
00382 
00383 #define JSFILENAME_NULL         0xffffffff      /* null script filename */
00384 #define JSFILENAME_SYSTEM       0x00000001      /* "system" script, see below */
00385 
00386 /*
00387  * Return true if obj is a "system" object, that is, one flagged by a prior
00388  * call to JS_FlagSystemObject(cx, obj).  What "system" means is up to the API
00389  * client, but it can be used to coordinate access control policies based on
00390  * script filenames and their prefixes, using JS_FlagScriptFilenamePrefix and
00391  * JS_GetTopScriptFilenameFlags.
00392  */
00393 extern JS_PUBLIC_API(JSBool)
00394 JS_IsSystemObject(JSContext *cx, JSObject *obj);
00395 
00396 /*
00397  * Flag obj as a "system" object.  The API client can flag system objects to
00398  * optimize access control checks.  The engine stores but does not interpret
00399  * the per-object flag set by this call.
00400  */
00401 extern JS_PUBLIC_API(void)
00402 JS_FlagSystemObject(JSContext *cx, JSObject *obj);
00403 
00404 JS_END_EXTERN_C
00405 
00406 #endif /* jsdbgapi_h___ */