Code

fix 1243587 and misc fixes
[inkscape.git] / src / dom / js / jsdbgapi.h
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 ***** */
40 #ifndef jsdbgapi_h___
41 #define jsdbgapi_h___
42 /*
43  * JS debugger API.
44  */
45 #include "jsapi.h"
46 #include "jsopcode.h"
47 #include "jsprvtd.h"
49 JS_BEGIN_EXTERN_C
51 extern void
52 js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
54 extern JS_PUBLIC_API(JSBool)
55 JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
56            JSTrapHandler handler, void *closure);
58 extern JS_PUBLIC_API(JSOp)
59 JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
61 extern JS_PUBLIC_API(void)
62 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
63              JSTrapHandler *handlerp, void **closurep);
65 extern JS_PUBLIC_API(void)
66 JS_ClearScriptTraps(JSContext *cx, JSScript *script);
68 extern JS_PUBLIC_API(void)
69 JS_ClearAllTraps(JSContext *cx);
71 extern JS_PUBLIC_API(JSTrapStatus)
72 JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
74 extern JS_PUBLIC_API(JSBool)
75 JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure);
77 extern JS_PUBLIC_API(JSBool)
78 JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep);
80 /************************************************************************/
82 extern JS_PUBLIC_API(JSBool)
83 JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
84                  JSWatchPointHandler handler, void *closure);
86 extern JS_PUBLIC_API(JSBool)
87 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
88                    JSWatchPointHandler *handlerp, void **closurep);
90 extern JS_PUBLIC_API(JSBool)
91 JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
93 extern JS_PUBLIC_API(JSBool)
94 JS_ClearAllWatchPoints(JSContext *cx);
96 #ifdef JS_HAS_OBJ_WATCHPOINT
97 /*
98  * Hide these non-API function prototypes by testing whether the internal
99  * header file "jsconfig.h" has been included.
100  */
101 extern void
102 js_MarkWatchPoints(JSContext *cx);
104 extern JSScopeProperty *
105 js_FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id);
107 extern JSPropertyOp
108 js_GetWatchedSetter(JSRuntime *rt, JSScope *scope,
109                     const JSScopeProperty *sprop);
111 extern JSBool JS_DLL_CALLBACK
112 js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
114 extern JSBool JS_DLL_CALLBACK
115 js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
116                      jsval *rval);
118 extern JSPropertyOp
119 js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter);
121 #endif /* JS_HAS_OBJ_WATCHPOINT */
123 /************************************************************************/
125 extern JS_PUBLIC_API(uintN)
126 JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
128 extern JS_PUBLIC_API(jsbytecode *)
129 JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
131 extern JS_PUBLIC_API(JSScript *)
132 JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
134 extern JS_PUBLIC_API(JSNative)
135 JS_GetFunctionNative(JSContext *cx, JSFunction *fun);
137 extern JS_PUBLIC_API(JSPrincipals *)
138 JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
140 /*
141  * Stack Frame Iterator
142  *
143  * Used to iterate through the JS stack frames to extract
144  * information from the frames.
145  */
147 extern JS_PUBLIC_API(JSStackFrame *)
148 JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
150 extern JS_PUBLIC_API(JSScript *)
151 JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
153 extern JS_PUBLIC_API(jsbytecode *)
154 JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
156 /*
157  * Get the closest scripted frame below fp.  If fp is null, start from cx->fp.
158  */
159 extern JS_PUBLIC_API(JSStackFrame *)
160 JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
162 /*
163  * Return a weak reference to fp's principals.  A null return does not denote
164  * an error, it means there are no principals.
165  */
166 extern JS_PUBLIC_API(JSPrincipals *)
167 JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
169 /*
170  * This API is like JS_StackFramePrincipals(cx, caller), except that if
171  * cx->runtime->findObjectPrincipals is non-null, it returns the weaker of
172  * the caller's principals and the object principals of fp's callee function
173  * object (fp->argv[-2]), which is eval, Function, or a similar eval-like
174  * method.  The caller parameter should be JS_GetScriptedCaller(cx, fp).
175  *
176  * All eval-like methods must use JS_EvalFramePrincipals to acquire a weak
177  * reference to the correct principals for the eval call to be secure, given
178  * an embedding that calls JS_SetObjectPrincipalsFinder (see jsapi.h).
179  */
180 extern JS_PUBLIC_API(JSPrincipals *)
181 JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller);
183 extern JS_PUBLIC_API(void *)
184 JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
186 extern JS_PUBLIC_API(void)
187 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
189 extern JS_PUBLIC_API(void *)
190 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
192 extern JS_PUBLIC_API(JSBool)
193 JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp);
195 /* this is deprecated, use JS_GetFrameScopeChain instead */
196 extern JS_PUBLIC_API(JSObject *)
197 JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
199 extern JS_PUBLIC_API(JSObject *)
200 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
202 extern JS_PUBLIC_API(JSObject *)
203 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
205 extern JS_PUBLIC_API(JSObject *)
206 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp);
208 extern JS_PUBLIC_API(JSFunction *)
209 JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
211 extern JS_PUBLIC_API(JSObject *)
212 JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
214 /* XXXrginda Initially published with typo */
215 #define JS_IsContructorFrame JS_IsConstructorFrame
216 extern JS_PUBLIC_API(JSBool)
217 JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
219 extern JS_PUBLIC_API(JSBool)
220 JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
222 extern JS_PUBLIC_API(jsval)
223 JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
225 extern JS_PUBLIC_API(void)
226 JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
228 /**
229  * Return fp's callee function object (fp->argv[-2]) if it has one.
230  */
231 extern JS_PUBLIC_API(JSObject *)
232 JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp);
234 /************************************************************************/
236 extern JS_PUBLIC_API(const char *)
237 JS_GetScriptFilename(JSContext *cx, JSScript *script);
239 extern JS_PUBLIC_API(uintN)
240 JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
242 extern JS_PUBLIC_API(uintN)
243 JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
245 extern JS_PUBLIC_API(JSVersion)
246 JS_GetScriptVersion(JSContext *cx, JSScript *script);
248 /************************************************************************/
250 /*
251  * Hook setters for script creation and destruction, see jsprvtd.h for the
252  * typedefs.  These macros provide binary compatibility and newer, shorter
253  * synonyms.
254  */
255 #define JS_SetNewScriptHook     JS_SetNewScriptHookProc
256 #define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
258 extern JS_PUBLIC_API(void)
259 JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
261 extern JS_PUBLIC_API(void)
262 JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
263                         void *callerdata);
265 /************************************************************************/
267 extern JS_PUBLIC_API(JSBool)
268 JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
269                           const jschar *bytes, uintN length,
270                           const char *filename, uintN lineno,
271                           jsval *rval);
273 extern JS_PUBLIC_API(JSBool)
274 JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
275                         const char *bytes, uintN length,
276                         const char *filename, uintN lineno,
277                         jsval *rval);
279 /************************************************************************/
281 typedef struct JSPropertyDesc {
282     jsval           id;         /* primary id, a string or int */
283     jsval           value;      /* property value */
284     uint8           flags;      /* flags, see below */
285     uint8           spare;      /* unused */
286     uint16          slot;       /* argument/variable slot */
287     jsval           alias;      /* alias id if JSPD_ALIAS flag */
288 } JSPropertyDesc;
290 #define JSPD_ENUMERATE  0x01    /* visible to for/in loop */
291 #define JSPD_READONLY   0x02    /* assignment is error */
292 #define JSPD_PERMANENT  0x04    /* property cannot be deleted */
293 #define JSPD_ALIAS      0x08    /* property has an alias id */
294 #define JSPD_ARGUMENT   0x10    /* argument to function */
295 #define JSPD_VARIABLE   0x20    /* local variable in function */
296 #define JSPD_EXCEPTION  0x40    /* exception occurred fetching the property, */
297                                 /* value is exception */
298 #define JSPD_ERROR      0x80    /* native getter returned JS_FALSE without */
299                                 /* throwing an exception */
301 typedef struct JSPropertyDescArray {
302     uint32          length;     /* number of elements in array */
303     JSPropertyDesc  *array;     /* alloc'd by Get, freed by Put */
304 } JSPropertyDescArray;
306 extern JS_PUBLIC_API(JSScopeProperty *)
307 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
309 extern JS_PUBLIC_API(JSBool)
310 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
311                    JSPropertyDesc *pd);
313 extern JS_PUBLIC_API(JSBool)
314 JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
316 extern JS_PUBLIC_API(void)
317 JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
319 /************************************************************************/
321 extern JS_PUBLIC_API(JSBool)
322 JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
324 extern JS_PUBLIC_API(JSBool)
325 JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
327 extern JS_PUBLIC_API(JSBool)
328 JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
330 extern JS_PUBLIC_API(JSBool)
331 JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
333 extern JS_PUBLIC_API(JSBool)
334 JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure);
336 extern JS_PUBLIC_API(JSBool)
337 JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure);
339 extern JS_PUBLIC_API(JSBool)
340 JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
342 /************************************************************************/
344 extern JS_PUBLIC_API(size_t)
345 JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
347 extern JS_PUBLIC_API(size_t)
348 JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
350 extern JS_PUBLIC_API(size_t)
351 JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
353 /*
354  * Get the top-most running script on cx starting from fp, or from the top of
355  * cx's frame stack if fp is null, and return its script filename flags.  If
356  * the script has a null filename member, return JSFILENAME_NULL.
357  */
358 extern JS_PUBLIC_API(uint32)
359 JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
361 /*
362  * Get the script filename flags for the script.  If the script
363  * doesn't have a filename, return JSFILENAME_NULL.
364  */
365 extern JS_PUBLIC_API(uint32)
366 JS_GetScriptFilenameFlags(JSScript *script);
368 /*
369  * Associate flags with a script filename prefix in rt, so that any subsequent
370  * script compilation will inherit those flags if the script's filename is the
371  * same as prefix, or if prefix is a substring of the script's filename.
372  *
373  * The API defines only one flag bit, JSFILENAME_SYSTEM, leaving the remaining
374  * 31 bits up to the API client to define.  The union of all 32 bits must not
375  * be a legal combination, however, in order to preserve JSFILENAME_NULL as a
376  * unique value.  API clients may depend on JSFILENAME_SYSTEM being a set bit
377  * in JSFILENAME_NULL -- a script with a null filename member is presumed to
378  * be a "system" script.
379  */
380 extern JS_PUBLIC_API(JSBool)
381 JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags);
383 #define JSFILENAME_NULL         0xffffffff      /* null script filename */
384 #define JSFILENAME_SYSTEM       0x00000001      /* "system" script, see below */
386 /*
387  * Return true if obj is a "system" object, that is, one flagged by a prior
388  * call to JS_FlagSystemObject(cx, obj).  What "system" means is up to the API
389  * client, but it can be used to coordinate access control policies based on
390  * script filenames and their prefixes, using JS_FlagScriptFilenamePrefix and
391  * JS_GetTopScriptFilenameFlags.
392  */
393 extern JS_PUBLIC_API(JSBool)
394 JS_IsSystemObject(JSContext *cx, JSObject *obj);
396 /*
397  * Flag obj as a "system" object.  The API client can flag system objects to
398  * optimize access control checks.  The engine stores but does not interpret
399  * the per-object flag set by this call.
400  */
401 extern JS_PUBLIC_API(void)
402 JS_FlagSystemObject(JSContext *cx, JSObject *obj);
404 JS_END_EXTERN_C
406 #endif /* jsdbgapi_h___ */