~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/jsd/jsdebug.h

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* This Source Code Form is subject to the terms of the Mozilla Public
 
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
5
 
 
6
/*
 
7
 * Header for JavaScript Debugging support - All public functions
 
8
 */
 
9
 
 
10
#ifndef jsdebug_h___
 
11
#define jsdebug_h___
 
12
 
 
13
/* Get jstypes.h included first. After that we can use PR macros for doing
 
14
*  this extern "C" stuff!
 
15
*/
 
16
#ifdef __cplusplus
 
17
extern "C"
 
18
{
 
19
#endif
 
20
#include "jstypes.h"
 
21
#ifdef __cplusplus
 
22
}
 
23
#endif
 
24
 
 
25
#include "jsapi.h"
 
26
#include "jsdbgapi.h"
 
27
#ifdef LIVEWIRE
 
28
#include "lwdbgapi.h"
 
29
#endif
 
30
 
 
31
JS_BEGIN_EXTERN_C
 
32
 
 
33
/*
 
34
 * The linkage of JSD API functions differs depending on whether the file is
 
35
 * used within the JSD library or not.  Any source file within the JSD
 
36
 * libraray should define EXPORT_JSD_API whereas any client of the library
 
37
 * should not.
 
38
 */
 
39
#ifdef EXPORT_JSD_API
 
40
#define JSD_PUBLIC_API(t)    JS_EXPORT_API(t)
 
41
#define JSD_PUBLIC_DATA(t)   JS_EXPORT_DATA(t)
 
42
#else
 
43
#define JSD_PUBLIC_API(t)    JS_IMPORT_API(t)
 
44
#define JSD_PUBLIC_DATA(t)   JS_IMPORT_DATA(t)
 
45
#endif
 
46
 
 
47
#define JSD_FRIEND_API(t)    JSD_PUBLIC_API(t)
 
48
#define JSD_FRIEND_DATA(t)   JSD_PUBLIC_DATA(t)
 
49
 
 
50
/***************************************************************************/
 
51
/* Opaque typedefs for handles */
 
52
 
 
53
typedef struct JSDContext        JSDContext;
 
54
typedef struct JSDScript         JSDScript;
 
55
typedef struct JSDSourceText     JSDSourceText;
 
56
typedef struct JSDThreadState    JSDThreadState;
 
57
typedef struct JSDStackFrameInfo JSDStackFrameInfo;
 
58
typedef struct JSDValue          JSDValue;
 
59
typedef struct JSDProperty       JSDProperty;
 
60
typedef struct JSDObject         JSDObject;
 
61
 
 
62
/***************************************************************************/
 
63
/* High Level calls */
 
64
 
 
65
/*
 
66
* callback stuff for calls in EXE to be accessed by this code
 
67
* when it lives in an explicitly loaded DLL
 
68
*/
 
69
 
 
70
/*
 
71
* This callback allows JSD to inform the embedding when JSD has been
 
72
* turned on or off. This is especially useful in the Java-based debugging
 
73
* system used in mozilla because the debugger applet controls starting
 
74
* up the JSD system.
 
75
*/
 
76
typedef void
 
77
(* JSD_SetContextProc)(JSDContext* jsdc, void* user);
 
78
 
 
79
/* This struct could have more fields in future versions */
 
80
typedef struct
 
81
{
 
82
    unsigned              size;       /* size of this struct (init before use)*/
 
83
    JSD_SetContextProc setContext;
 
84
} JSD_UserCallbacks;
 
85
 
 
86
/*
 
87
* Used by an embedding to tell JSD what JSRuntime to use and to set
 
88
* callbacks without starting up JSD. This assumes only one JSRuntime
 
89
* will be used. This exists to support the mozilla Java-based debugger
 
90
* system.
 
91
*/
 
92
extern JSD_PUBLIC_API(void)
 
93
JSD_SetUserCallbacks(JSRuntime*         jsrt,
 
94
                     JSD_UserCallbacks* callbacks,
 
95
                     void*              user);
 
96
 
 
97
/*
 
98
* Startup JSD.
 
99
* This version of the init function requires that JSD_SetUserCallbacks()
 
100
* has been previously called (with a non-NULL callback struct pointer)
 
101
*/
 
102
extern JSD_PUBLIC_API(JSDContext*)
 
103
JSD_DebuggerOn(void);
 
104
 
 
105
/*
 
106
* Startup JSD on a particular JSRuntime with (optional) callbacks
 
107
*/
 
108
extern JSD_PUBLIC_API(JSDContext*)
 
109
JSD_DebuggerOnForUser(JSRuntime*         jsrt,
 
110
                      JSD_UserCallbacks* callbacks,
 
111
                      void*              user);
 
112
 
 
113
/*
 
114
 * Startup JSD in an application that uses compartments. Debugger
 
115
 * objects will be allocated in the same compartment as scopeobj.
 
116
 */
 
117
extern JSD_PUBLIC_API(JSDContext*)
 
118
JSD_DebuggerOnForUserWithCompartment(JSRuntime*         jsrt,
 
119
                                     JSD_UserCallbacks* callbacks,
 
120
                                     void*              user,
 
121
                                     JSObject*          scopeobj);
 
122
 
 
123
/*
 
124
* Shutdown JSD for this JSDContext
 
125
*/
 
126
extern JSD_PUBLIC_API(void)
 
127
JSD_DebuggerOff(JSDContext* jsdc);
 
128
 
 
129
/*
 
130
 * Pause JSD for this JSDContext
 
131
 */
 
132
extern JSD_PUBLIC_API(void)
 
133
JSD_DebuggerPause(JSDContext* jsdc);
 
134
 
 
135
/*
 
136
 * Unpause JSD for this JSDContext
 
137
 */
 
138
extern JSD_PUBLIC_API(void)
 
139
JSD_DebuggerUnpause(JSDContext* jsdc);
 
140
 
 
141
/*
 
142
* Get the Major Version (initial JSD release used major version = 1)
 
143
*/
 
144
extern JSD_PUBLIC_API(unsigned)
 
145
JSD_GetMajorVersion(void);
 
146
 
 
147
/*
 
148
* Get the Minor Version (initial JSD release used minor version = 0)
 
149
*/
 
150
extern JSD_PUBLIC_API(unsigned)
 
151
JSD_GetMinorVersion(void);
 
152
 
 
153
/*
 
154
* Returns a 'dumb' JSContext that can be used for utility purposes as needed
 
155
*/
 
156
extern JSD_PUBLIC_API(JSContext*)
 
157
JSD_GetDefaultJSContext(JSDContext* jsdc);
 
158
 
 
159
/*
 
160
* Returns a JSRuntime this context is associated with
 
161
*/
 
162
extern JSD_PUBLIC_API(JSRuntime*)
 
163
JSD_GetJSRuntime(JSDContext* jsdc);
 
164
 
 
165
/*
 
166
* Set the private data for this context, returns previous value
 
167
*/
 
168
extern JSD_PUBLIC_API(void *)
 
169
JSD_SetContextPrivate(JSDContext *jsdc, void *data);
 
170
 
 
171
/*
 
172
* Get the private data for this context
 
173
*/
 
174
extern JSD_PUBLIC_API(void *)
 
175
JSD_GetContextPrivate(JSDContext *jsdc);
 
176
 
 
177
/*
 
178
* Clear profile data for all scripts
 
179
*/
 
180
extern JSD_PUBLIC_API(void)
 
181
JSD_ClearAllProfileData(JSDContext* jsdc);
 
182
 
 
183
/*
 
184
* Context flags.
 
185
*/
 
186
 
 
187
/* Include native frames in JSDThreadStates. */
 
188
#define JSD_INCLUDE_NATIVE_FRAMES 0x01
 
189
/*
 
190
* Normally, if a script has a 0 in JSD_SCRIPT_PROFILE_BIT it is included in
 
191
* profile data, otherwise it is not profiled.  Setting the JSD_PROFILE_WHEN_SET
 
192
* flag reverses this convention.
 
193
*/
 
194
#define JSD_PROFILE_WHEN_SET      0x02
 
195
/*
 
196
* Normally, when the script in the top frame of a thread state has a 1 in
 
197
* JSD_SCRIPT_DEBUG_BIT, the execution hook is ignored.  Setting the
 
198
* JSD_DEBUG_WHEN_SET flag reverses this convention.
 
199
*/
 
200
#define JSD_DEBUG_WHEN_SET        0x04
 
201
/*
 
202
* When this flag is set the internal call hook will collect profile data.
 
203
*/
 
204
#define JSD_COLLECT_PROFILE_DATA  0x08
 
205
/*
 
206
* When this flag is set, stack frames that are disabled for debugging
 
207
* will not appear in the call stack chain.
 
208
*/
 
209
#define JSD_HIDE_DISABLED_FRAMES  0x10
 
210
/*
 
211
* When this flag is set, the debugger will only check the
 
212
* JSD_SCRIPT_DEBUG_BIT on the top (most recent) stack frame.  This
 
213
* makes it possible to stop in an enabled frame which was called from
 
214
* a stack that contains a disabled frame.
 
215
*
 
216
* When this flag is *not* set, any stack that contains a disabled frame
 
217
* will not be debugged (the execution hook will not be invoked.)
 
218
*
 
219
* This only applies when the reason for calling the hook would have
 
220
* been JSD_HOOK_INTERRUPTED or JSD_HOOK_THROW.  JSD_HOOK_BREAKPOINT,
 
221
* JSD_HOOK_DEBUG_REQUESTED, and JSD_HOOK_DEBUGGER_KEYWORD always stop,
 
222
* regardless of this setting, as long as the top frame is not disabled.
 
223
*
 
224
* If JSD_HIDE_DISABLED_FRAMES is set, this is effectively set as well.
 
225
*/
 
226
#define JSD_MASK_TOP_FRAME_ONLY   0x20
 
227
 
 
228
/*
 
229
* 0x40 was formerly used to hook into object creation.
 
230
*/
 
231
#define JSD_DISABLE_OBJECT_TRACE_RETIRED 0x40
 
232
 
 
233
 
 
234
extern JSD_PUBLIC_API(void)
 
235
JSD_SetContextFlags (JSDContext* jsdc, uint32_t flags);
 
236
 
 
237
extern JSD_PUBLIC_API(uint32_t)
 
238
JSD_GetContextFlags (JSDContext* jsdc);     
 
239
 
 
240
/*
 
241
* Notify JSD that this JSContext is 'in use'. This allows JSD to hook the
 
242
* ErrorReporter. For the most part this is done automatically whenever
 
243
* events like script loading happen. But, it is a good idea to call this
 
244
* from the embedding when new contexts come into use.
 
245
*/
 
246
extern JSD_PUBLIC_API(void)
 
247
JSD_JSContextInUse(JSDContext* jsdc, JSContext* context);
 
248
 
 
249
/*
 
250
* Find the JSDContext (if any) associated with the JSRuntime of a
 
251
* given JSContext.
 
252
*/
 
253
extern JSD_PUBLIC_API(JSDContext*)
 
254
JSD_JSDContextForJSContext(JSContext* context);
 
255
 
 
256
/***************************************************************************/
 
257
/* Script functions */
 
258
 
 
259
/*
 
260
* Lock the entire script subsystem. This grabs a highlevel lock that
 
261
* protects the JSD internal information about scripts. It is important
 
262
* to wrap script related calls in this lock in multithreaded situations
 
263
* -- i.e. where the debugger is running on a different thread than the
 
264
* interpreter -- or when multiple debugger threads may be accessing this
 
265
* subsystem. It is safe (and best) to use this locking even if the
 
266
* environment might not be multi-threaded. Safely nestable.
 
267
*/
 
268
extern JSD_PUBLIC_API(void)
 
269
JSD_LockScriptSubsystem(JSDContext* jsdc);
 
270
 
 
271
/*
 
272
* Unlock the entire script subsystem -- see JSD_LockScriptSubsystem
 
273
*/
 
274
extern JSD_PUBLIC_API(void)
 
275
JSD_UnlockScriptSubsystem(JSDContext* jsdc);
 
276
 
 
277
/*
 
278
* Iterate through all the active scripts for this JSDContext.
 
279
* NOTE: must initialize iterp to NULL to start iteration.
 
280
* NOTE: must lock and unlock the subsystem
 
281
* example:
 
282
*
 
283
*  JSDScript jsdscript;
 
284
*  JSDScript iter = NULL;
 
285
*
 
286
*  JSD_LockScriptSubsystem(jsdc);
 
287
*  while((jsdscript = JSD_IterateScripts(jsdc, &iter)) != NULL) {
 
288
*     *** use jsdscript here ***
 
289
*  }
 
290
*  JSD_UnlockScriptSubsystem(jsdc);
 
291
*/
 
292
extern JSD_PUBLIC_API(JSDScript*)
 
293
JSD_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
 
294
 
 
295
/*
 
296
* Get the number of times this script has been called.
 
297
*/
 
298
extern JSD_PUBLIC_API(unsigned)
 
299
JSD_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
 
300
 
 
301
/*
 
302
* Get the max number of times this script called itself, directly or indirectly.
 
303
*/
 
304
extern JSD_PUBLIC_API(unsigned)
 
305
JSD_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
 
306
 
 
307
/*
 
308
* Get the shortest execution time recorded.
 
309
*/
 
310
extern JSD_PUBLIC_API(double)
 
311
JSD_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
 
312
 
 
313
/*
 
314
* Get the longest execution time recorded.
 
315
*/
 
316
extern JSD_PUBLIC_API(double)
 
317
JSD_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
 
318
 
 
319
/*
 
320
* Get the total amount of time spent in this script.
 
321
*/
 
322
extern JSD_PUBLIC_API(double)
 
323
JSD_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
 
324
 
 
325
/*
 
326
* Get the shortest execution time recorded, excluding time spent in called
 
327
* functions.
 
328
*/
 
329
extern JSD_PUBLIC_API(double)
 
330
JSD_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
 
331
 
 
332
/*
 
333
* Get the longest execution time recorded, excluding time spent in called
 
334
* functions.
 
335
*/
 
336
extern JSD_PUBLIC_API(double)
 
337
JSD_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
 
338
 
 
339
/*
 
340
* Get the total amount of time spent in this script, excluding time spent
 
341
* in called functions.
 
342
*/
 
343
extern JSD_PUBLIC_API(double)
 
344
JSD_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
 
345
 
 
346
/*
 
347
* Clear profile data for this script.
 
348
*/
 
349
extern JSD_PUBLIC_API(void)
 
350
JSD_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
 
351
 
 
352
/*
 
353
* Get the JSScript for a JSDScript
 
354
*/
 
355
extern JSD_PUBLIC_API(JSScript*)
 
356
JSD_GetJSScript(JSDContext* jsdc, JSDScript *script);
 
357
 
 
358
/*
 
359
* Get the JSFunction for a JSDScript
 
360
*/
 
361
extern JSD_PUBLIC_API(JSFunction*)
 
362
JSD_GetJSFunction(JSDContext* jsdc, JSDScript *script);
 
363
 
 
364
/*
 
365
* Determines whether or not to collect profile information for this
 
366
* script.  The context flag JSD_PROFILE_WHEN_SET decides the logic.
 
367
*/
 
368
#define JSD_SCRIPT_PROFILE_BIT 0x01
 
369
/*
 
370
* Determines whether or not to ignore breakpoints, etc. in this script.
 
371
* The context flag JSD_DEBUG_WHEN_SET decides the logic.
 
372
*/
 
373
#define JSD_SCRIPT_DEBUG_BIT   0x02
 
374
/*
 
375
 * Determines whether to invoke the onScriptDestroy callback for this
 
376
 * script. The default is for this to be true if the onScriptCreated
 
377
 * callback was invoked for this script.
 
378
 */
 
379
#define JSD_SCRIPT_CALL_DESTROY_HOOK_BIT 0x04
 
380
 
 
381
extern JSD_PUBLIC_API(uint32_t)
 
382
JSD_GetScriptFlags(JSDContext *jsdc, JSDScript* jsdscript);
 
383
 
 
384
extern JSD_PUBLIC_API(void)
 
385
JSD_SetScriptFlags(JSDContext *jsdc, JSDScript* jsdscript, uint32_t flags);
 
386
 
 
387
/*
 
388
* Set the private data for this script, returns previous value
 
389
*/
 
390
extern JSD_PUBLIC_API(void *)
 
391
JSD_SetScriptPrivate(JSDScript* jsdscript, void *data);
 
392
 
 
393
/*
 
394
* Get the private data for this script
 
395
*/
 
396
extern JSD_PUBLIC_API(void *)
 
397
JSD_GetScriptPrivate(JSDScript* jsdscript);
 
398
 
 
399
/*
 
400
* Determine if this script is still loaded in the interpreter
 
401
*/
 
402
extern JSD_PUBLIC_API(JSBool)
 
403
JSD_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
 
404
 
 
405
/*
 
406
* Get the filename associated with this script
 
407
*/
 
408
extern JSD_PUBLIC_API(const char*)
 
409
JSD_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
 
410
 
 
411
/*
 
412
* Get the function name associated with this script (NULL if not a function).
 
413
* If the function does not have a name the result is the string "anonymous".
 
414
* *** new for gecko 2.0 ****
 
415
*/
 
416
extern JSD_PUBLIC_API(JSString *)
 
417
JSD_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript);
 
418
 
 
419
/*
 
420
* Get the base linenumber of the sourcefile from which this script was loaded.
 
421
* This is one-based -- i.e. the first line of a file is line '1'. This may
 
422
* return 0 if this infomation is unknown.
 
423
*/
 
424
extern JSD_PUBLIC_API(unsigned)
 
425
JSD_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
 
426
 
 
427
/*
 
428
* Get the count of source lines associated with this script (1 or greater)
 
429
*/
 
430
extern JSD_PUBLIC_API(unsigned)
 
431
JSD_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
 
432
 
 
433
/*
 
434
* Declaration of callback for notification of script creation and destruction.
 
435
* 'creating' is JS_TRUE if creating new script, JS_FALSE if destroying existing
 
436
* script (callback called just before actual destruction).
 
437
* 'callerdata' is what was passed to JSD_SetScriptHook to set the hook.
 
438
*/
 
439
typedef void
 
440
(* JSD_ScriptHookProc)(JSDContext* jsdc,
 
441
                       JSDScript*  jsdscript,
 
442
                       JSBool      creating,
 
443
                       void*       callerdata);
 
444
 
 
445
/*
 
446
* Set a hook to be called when scripts are created or destroyed (loaded or
 
447
* unloaded).
 
448
* 'callerdata' can be whatever you want it to be.
 
449
*/
 
450
extern JSD_PUBLIC_API(JSBool)
 
451
JSD_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
 
452
 
 
453
/*
 
454
* Get the current script hook.
 
455
*/
 
456
extern JSD_PUBLIC_API(JSBool)
 
457
JSD_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
 
458
 
 
459
/*
 
460
* Get a 'Program Counter' value for a given line. This represents the location
 
461
* of the first bit of executable code for this line of source. This 'pc' should 
 
462
* be considered an opaque handle.
 
463
* 0 is returned for invalid scripts, or lines that lie outside the script.
 
464
* If no code is on the given line, then the returned pc represents the first
 
465
* code within the script (if any) after the given line.
 
466
* This function can be used to set breakpoints -- see JSD_SetExecutionHook
 
467
*/
 
468
extern JSD_PUBLIC_API(uintptr_t)
 
469
JSD_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line);
 
470
 
 
471
/*
 
472
* Get the source line number for a given 'Program Counter' location.
 
473
* Returns 0 if no source line information is appropriate (or available) for
 
474
* the given pc.
 
475
*/
 
476
extern JSD_PUBLIC_API(unsigned)
 
477
JSD_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc);
 
478
 
 
479
/*
 
480
 * Get a list of lines and the corresponding earliest PC for each (see
 
481
 * JSD_GetClosestPC). Lines with no PCs associated will not be returned. NULL
 
482
 * may be passed for either lines or pcs to avoid filling anything in for that
 
483
 * argument.
 
484
 */
 
485
extern JSD_PUBLIC_API(JSBool)
 
486
JSD_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
 
487
               unsigned startLine, unsigned maxLines,
 
488
               unsigned* count, unsigned** lines, uintptr_t** pcs);
 
489
 
 
490
/* these are only used in cases where scripts are created outside of JS*/
 
491
 
 
492
/*
 
493
* Direct call to notify JSD that a script has been created.
 
494
* Embeddings that use the normal jsapi script functions need not call this.
 
495
* Any embedding that follows the (discouraged!) practice of contructing script
 
496
* structures manually should call this function to inform JSD. (older ssjs
 
497
* systems do this).
 
498
*/
 
499
extern JSD_PUBLIC_API(void)
 
500
JSD_ScriptCreated(JSDContext* jsdc,
 
501
                  JSContext   *cx,
 
502
                  const char  *filename,    /* URL this script loads from */
 
503
                  unsigned       lineno,       /* line where this script starts */
 
504
                  JSScript    *script,
 
505
                  JSFunction  *fun);
 
506
 
 
507
/*
 
508
* see JSD_ScriptCreated
 
509
*/
 
510
extern JSD_PUBLIC_API(void)
 
511
JSD_ScriptDestroyed(JSDContext* jsdc,
 
512
                    JSFreeOp    *fop,
 
513
                    JSScript    *script);
 
514
 
 
515
/***************************************************************************/
 
516
/* Source Text functions */
 
517
 
 
518
/*
 
519
* In some embeddings (e.g. mozilla) JavaScript source code from a 'file' may be
 
520
* execute before the entire 'file' has even been loaded. This system supports
 
521
* access to such incrmentally loaded source. It also allows for the possibility
 
522
* that source loading may fail or be aborted (though the source that did load
 
523
* may still be usable). Remember that this source is the entire 'file'
 
524
* contents and that the JavaScript code may only be part of that source.
 
525
*
 
526
* For any given URL there can only be one source text item (the most recently
 
527
* loaded).
 
528
*/
 
529
 
 
530
/* these coorespond to netscape.jsdebug.SourceTextItem.java values -
 
531
*  change in both places if anywhere
 
532
*/
 
533
 
 
534
typedef enum
 
535
{
 
536
    JSD_SOURCE_INITED       = 0, /* initialized, but contains no source yet */
 
537
    JSD_SOURCE_PARTIAL      = 1, /* some source loaded, more expected */
 
538
    JSD_SOURCE_COMPLETED    = 2, /* all source finished loading */
 
539
    JSD_SOURCE_ABORTED      = 3, /* user aborted loading, some may be loaded */
 
540
    JSD_SOURCE_FAILED       = 4, /* loading failed, some may be loaded */
 
541
    JSD_SOURCE_CLEARED      = 5  /* text has been cleared by debugger */
 
542
} JSDSourceStatus;
 
543
 
 
544
/*
 
545
* Lock the entire source text subsystem. This grabs a highlevel lock that
 
546
* protects the JSD internal information about sources. It is important to
 
547
* wrap source text related calls in this lock in multithreaded situations
 
548
* -- i.e. where the debugger is running on a different thread than the
 
549
* interpreter (or the loader of sources) -- or when multiple debugger
 
550
* threads may be accessing this subsystem. It is safe (and best) to use
 
551
* this locking even if the environment might not be multi-threaded.
 
552
* Safely Nestable.
 
553
*/
 
554
extern JSD_PUBLIC_API(void)
 
555
JSD_LockSourceTextSubsystem(JSDContext* jsdc);
 
556
 
 
557
/*
 
558
* Unlock the entire source text subsystem. see JSD_LockSourceTextSubsystem.
 
559
*/
 
560
extern JSD_PUBLIC_API(void)
 
561
JSD_UnlockSourceTextSubsystem(JSDContext* jsdc);
 
562
 
 
563
/*
 
564
* Iterate the source test items. Use the same pattern of calls shown in
 
565
* the example for JSD_IterateScripts - NOTE that the SourceTextSubsystem.
 
566
* must be locked before and unlocked after iterating.
 
567
*/
 
568
extern JSD_PUBLIC_API(JSDSourceText*)
 
569
JSD_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
 
570
 
 
571
/*
 
572
* Find the source text item for the given URL (or filename - or whatever
 
573
* string the given embedding uses to describe source locations).
 
574
* Returns NULL is not found.
 
575
*/
 
576
extern JSD_PUBLIC_API(JSDSourceText*)
 
577
JSD_FindSourceForURL(JSDContext* jsdc, const char* url);
 
578
 
 
579
/*
 
580
* Get the URL string associated with the given source text item
 
581
*/
 
582
extern JSD_PUBLIC_API(const char*)
 
583
JSD_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
584
 
 
585
/*
 
586
* Get the actual source text. This gives access to the actual storage of
 
587
* the source - it sHould *not* be written to.
 
588
* The buffer is NOT zero terminated (nor is it guaranteed to have space to
 
589
* hold a zero terminating char).
 
590
* XXX this is 8-bit character data. Unicode source is not yet supported.
 
591
*/
 
592
extern JSD_PUBLIC_API(JSBool)
 
593
JSD_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
 
594
                  const char** ppBuf, int* pLen);
 
595
 
 
596
/*
 
597
* Clear the text -- delete the text and set the status to JSD_SOURCE_CLEARED.
 
598
* This is useful if source is done loading and the debugger wishes to store
 
599
* the text data itself (e.g. in a Java String). This allows avoidance of
 
600
* storing the same text in multiple places.
 
601
*/
 
602
extern JSD_PUBLIC_API(void)
 
603
JSD_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
604
 
 
605
/*
 
606
* Return the status of the source text item. see JSDSourceStatus enum.
 
607
*/
 
608
extern JSD_PUBLIC_API(JSDSourceStatus)
 
609
JSD_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
610
 
 
611
/*
 
612
* Has the source been altered since the last call to JSD_SetSourceDirty?
 
613
* Use of JSD_IsSourceDirty and JSD_SetSourceDirty is still supported, but
 
614
* discouraged in favor of the JSD_GetSourceAlterCount system. This dirty
 
615
* scheme ASSUMES that there is only one consumer of the data.
 
616
*/
 
617
extern JSD_PUBLIC_API(JSBool)
 
618
JSD_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
619
 
 
620
/*
 
621
* Clear the dirty flag
 
622
*/
 
623
extern JSD_PUBLIC_API(void)
 
624
JSD_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, JSBool dirty);
 
625
 
 
626
/*
 
627
* Each time a source text item is altered this value is incremented. Any
 
628
* consumer can store this value when they retieve other data about the
 
629
* source text item and then check later to see if the current value is
 
630
* different from their stored value. Thus they can know if they have stale
 
631
* data or not. NOTE: this value is not gauranteed to start at any given number.
 
632
*/
 
633
extern JSD_PUBLIC_API(unsigned)
 
634
JSD_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
635
 
 
636
/*
 
637
* Force an increment in the alter count for a source text item. This is
 
638
* normally automatic when the item changes, but a give consumer may want to
 
639
* force this to amke an item appear to have changed even if it has not.
 
640
*/
 
641
extern JSD_PUBLIC_API(unsigned)
 
642
JSD_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
643
 
 
644
/*
 
645
* Destroy *all* the source text items
 
646
* (new for server-side USE WITH CARE)
 
647
*/
 
648
extern JSD_PUBLIC_API(void)
 
649
JSD_DestroyAllSources( JSDContext* jsdc );
 
650
 
 
651
/* functions for adding source items */
 
652
 
 
653
/*
 
654
* Add a new item for a given URL. If an iten already exists for the given URL
 
655
* then the old item is removed.
 
656
* 'url' may not be NULL.
 
657
*
 
658
* ifdef LIVEWIRE url is treated as a char* and ownership is claimed by jsd
 
659
*/
 
660
extern JSD_PUBLIC_API(JSDSourceText*)
 
661
JSD_NewSourceText(JSDContext* jsdc, const char* url);
 
662
 
 
663
/*
 
664
* Append text (or change status -- e.g. set completed) for a source text
 
665
* item. Text need not be zero terminated. Callers should consider the returned
 
666
* JSDSourceText to be the 'current' item for future use. This may return NULL
 
667
* if called after this item has been replaced by a call to JSD_NewSourceText.
 
668
*/
 
669
extern JSD_PUBLIC_API(JSDSourceText*)
 
670
JSD_AppendSourceText(JSDContext*     jsdc,
 
671
                     JSDSourceText*  jsdsrc,
 
672
                     const char*     text,       /* *not* zero terminated */
 
673
                     size_t          length,
 
674
                     JSDSourceStatus status);
 
675
 
 
676
/*
 
677
* Unicode varient of JSD_AppendSourceText.
 
678
*
 
679
* NOTE: At this point text is stored in 8bit ASCII so this function just
 
680
* extracts the bottom 8bits from each jschar. At some future point we may
 
681
* switch to storing and exposing 16bit Unicode.
 
682
*/
 
683
extern JSD_PUBLIC_API(JSDSourceText*)
 
684
JSD_AppendUCSourceText(JSDContext*     jsdc,
 
685
                       JSDSourceText*  jsdsrc,
 
686
                       const jschar*   text,       /* *not* zero terminated */
 
687
                       size_t          length,
 
688
                       JSDSourceStatus status);
 
689
/*
 
690
 * Convienence function for adding complete source of url in one call.
 
691
 * same as:
 
692
 *   JSDSourceText* jsdsrc;
 
693
 *   JSD_LOCK_SOURCE_TEXT(jsdc);
 
694
 *   jsdsrc = jsd_NewSourceText(jsdc, url);
 
695
 *   if(jsdsrc)
 
696
 *       jsdsrc = jsd_AppendSourceText(jsdc, jsdsrc,
 
697
 *                                     text, length, JSD_SOURCE_PARTIAL);
 
698
 *   if(jsdsrc)
 
699
 *       jsdsrc = jsd_AppendSourceText(jsdc, jsdsrc,
 
700
 *                                     NULL, 0, JSD_SOURCE_COMPLETED);
 
701
 *   JSD_UNLOCK_SOURCE_TEXT(jsdc);
 
702
 *   return jsdsrc ? JS_TRUE : JS_FALSE;
 
703
 */
 
704
extern JSD_PUBLIC_API(JSBool)
 
705
JSD_AddFullSourceText(JSDContext* jsdc,
 
706
                      const char* text,       /* *not* zero terminated */
 
707
                      size_t      length,
 
708
                      const char* url);
 
709
 
 
710
/***************************************************************************/
 
711
/* Execution/Interrupt Hook functions */
 
712
 
 
713
/* possible 'type' params for JSD_ExecutionHookProc */
 
714
#define JSD_HOOK_INTERRUPTED            0
 
715
#define JSD_HOOK_BREAKPOINT             1
 
716
#define JSD_HOOK_DEBUG_REQUESTED        2
 
717
#define JSD_HOOK_DEBUGGER_KEYWORD       3
 
718
#define JSD_HOOK_THROW                  4
 
719
 
 
720
/* legal return values for JSD_ExecutionHookProc */
 
721
#define JSD_HOOK_RETURN_HOOK_ERROR      0
 
722
#define JSD_HOOK_RETURN_CONTINUE        1
 
723
#define JSD_HOOK_RETURN_ABORT           2
 
724
#define JSD_HOOK_RETURN_RET_WITH_VAL    3
 
725
#define JSD_HOOK_RETURN_THROW_WITH_VAL  4
 
726
#define JSD_HOOK_RETURN_CONTINUE_THROW  5
 
727
 
 
728
/*
 
729
* Implement a callback of this form in order to hook execution.
 
730
*/
 
731
typedef unsigned
 
732
(* JSD_ExecutionHookProc)(JSDContext*     jsdc,
 
733
                          JSDThreadState* jsdthreadstate,
 
734
                          unsigned           type,
 
735
                          void*           callerdata,
 
736
                          jsval*          rval);
 
737
 
 
738
/* possible 'type' params for JSD_CallHookProc */
 
739
#define JSD_HOOK_TOPLEVEL_START  0   /* about to evaluate top level script */
 
740
#define JSD_HOOK_TOPLEVEL_END    1   /* done evaluting top level script    */
 
741
#define JSD_HOOK_FUNCTION_CALL   2   /* about to call a function           */
 
742
#define JSD_HOOK_FUNCTION_RETURN 3   /* done calling function              */
 
743
 
 
744
/*
 
745
* Implement a callback of this form in order to hook function call/returns.
 
746
* Return JS_TRUE from a TOPLEVEL_START or FUNCTION_CALL type call hook if you
 
747
* want to hear about the TOPLEVEL_END or FUNCTION_RETURN too.  Return value is
 
748
* ignored to TOPLEVEL_END and FUNCTION_RETURN type hooks.
 
749
*/
 
750
typedef JSBool
 
751
(* JSD_CallHookProc)(JSDContext*     jsdc,
 
752
                     JSDThreadState* jsdthreadstate,
 
753
                     unsigned           type,
 
754
                     void*           callerdata);
 
755
 
 
756
/*
 
757
* Set Hook to be called whenever the given pc is about to be executed --
 
758
* i.e. for 'trap' or 'breakpoint'
 
759
*/
 
760
extern JSD_PUBLIC_API(JSBool)
 
761
JSD_SetExecutionHook(JSDContext*           jsdc,
 
762
                     JSDScript*            jsdscript,
 
763
                     uintptr_t             pc,
 
764
                     JSD_ExecutionHookProc hook,
 
765
                     void*                 callerdata);
 
766
 
 
767
/*
 
768
* Clear the hook for this pc
 
769
*/
 
770
extern JSD_PUBLIC_API(JSBool)
 
771
JSD_ClearExecutionHook(JSDContext*          jsdc,
 
772
                       JSDScript*           jsdscript,
 
773
                       uintptr_t            pc);
 
774
 
 
775
/*
 
776
* Clear all the pc specific hooks for this script
 
777
*/
 
778
extern JSD_PUBLIC_API(JSBool)
 
779
JSD_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
 
780
 
 
781
/*
 
782
* Clear all the pc specific hooks for the entire JSRuntime associated with
 
783
* this JSDContext
 
784
*/
 
785
extern JSD_PUBLIC_API(JSBool)
 
786
JSD_ClearAllExecutionHooks(JSDContext* jsdc);
 
787
 
 
788
/*
 
789
* Set a hook to be called before the next instruction is executed. Depending
 
790
* on the threading situation and whether or not an JS code is currently
 
791
* executing the hook might be called before this call returns, or at some
 
792
* future time. The hook will continue to be called as each instruction
 
793
* executes until cleared.
 
794
*/
 
795
extern JSD_PUBLIC_API(JSBool)
 
796
JSD_SetInterruptHook(JSDContext*           jsdc,
 
797
                     JSD_ExecutionHookProc hook,
 
798
                     void*                 callerdata);
 
799
 
 
800
/*
 
801
* Call the interrupt hook at least once per source line
 
802
*/
 
803
extern JSD_PUBLIC_API(JSBool)
 
804
JSD_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript *jsdscript, JSBool enable);
 
805
 
 
806
/*
 
807
* Clear the current interrupt hook.
 
808
*/
 
809
extern JSD_PUBLIC_API(JSBool)
 
810
JSD_ClearInterruptHook(JSDContext* jsdc);
 
811
 
 
812
/*
 
813
* Set the hook that should be called whenever a JSD_ErrorReporter hook
 
814
* returns JSD_ERROR_REPORTER_DEBUG.
 
815
*/
 
816
extern JSD_PUBLIC_API(JSBool)
 
817
JSD_SetDebugBreakHook(JSDContext*           jsdc,
 
818
                      JSD_ExecutionHookProc hook,
 
819
                      void*                 callerdata);
 
820
 
 
821
/*
 
822
* Clear the debug break hook
 
823
*/
 
824
extern JSD_PUBLIC_API(JSBool)
 
825
JSD_ClearDebugBreakHook(JSDContext* jsdc);
 
826
 
 
827
/*
 
828
* Set the hook that should be called when the 'debugger' keyword is
 
829
* encountered by the JavaScript interpreter during execution.
 
830
*/
 
831
extern JSD_PUBLIC_API(JSBool)
 
832
JSD_SetDebuggerHook(JSDContext*           jsdc,
 
833
                    JSD_ExecutionHookProc hook,
 
834
                    void*                 callerdata);
 
835
 
 
836
/*
 
837
* Clear the 'debugger' keyword hook
 
838
*/
 
839
extern JSD_PUBLIC_API(JSBool)
 
840
JSD_ClearDebuggerHook(JSDContext* jsdc);
 
841
 
 
842
/*
 
843
* Set the hook that should be called when a JS exception is thrown.
 
844
* NOTE: the 'do default' return value is: JSD_HOOK_RETURN_CONTINUE_THROW
 
845
*/
 
846
extern JSD_PUBLIC_API(JSBool)
 
847
JSD_SetThrowHook(JSDContext*           jsdc,
 
848
                 JSD_ExecutionHookProc hook,
 
849
                 void*                 callerdata);
 
850
/*
 
851
* Clear the throw hook
 
852
*/
 
853
extern JSD_PUBLIC_API(JSBool)
 
854
JSD_ClearThrowHook(JSDContext* jsdc);
 
855
 
 
856
/*
 
857
* Set the hook that should be called when a toplevel script begins or completes.
 
858
*/
 
859
extern JSD_PUBLIC_API(JSBool)
 
860
JSD_SetTopLevelHook(JSDContext*      jsdc,
 
861
                    JSD_CallHookProc hook,
 
862
                    void*            callerdata);
 
863
/*
 
864
* Clear the toplevel call hook
 
865
*/
 
866
extern JSD_PUBLIC_API(JSBool)
 
867
JSD_ClearTopLevelHook(JSDContext* jsdc);
 
868
 
 
869
/*
 
870
* Set the hook that should be called when a function call or return happens.
 
871
*/
 
872
extern JSD_PUBLIC_API(JSBool)
 
873
JSD_SetFunctionHook(JSDContext*      jsdc,
 
874
                    JSD_CallHookProc hook,
 
875
                    void*            callerdata);
 
876
/*
 
877
* Clear the function call hook
 
878
*/
 
879
extern JSD_PUBLIC_API(JSBool)
 
880
JSD_ClearFunctionHook(JSDContext* jsdc);
 
881
 
 
882
/***************************************************************************/
 
883
/* Stack Frame functions */
 
884
 
 
885
/*
 
886
* Get the count of call stack frames for the given JSDThreadState
 
887
*/
 
888
extern JSD_PUBLIC_API(unsigned)
 
889
JSD_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
 
890
 
 
891
/*
 
892
* Get the 'current' call stack frame for the given JSDThreadState
 
893
*/
 
894
extern JSD_PUBLIC_API(JSDStackFrameInfo*)
 
895
JSD_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
 
896
 
 
897
/*
 
898
* Get the JSContext for the given JSDThreadState
 
899
*/
 
900
extern JSD_PUBLIC_API(JSContext*)
 
901
JSD_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
 
902
 
 
903
/*
 
904
* Get the calling call stack frame for the given frame
 
905
*/
 
906
extern JSD_PUBLIC_API(JSDStackFrameInfo*)
 
907
JSD_GetCallingStackFrame(JSDContext* jsdc,
 
908
                         JSDThreadState* jsdthreadstate,
 
909
                         JSDStackFrameInfo* jsdframe);
 
910
 
 
911
/*
 
912
* Get the script for the given call stack frame
 
913
*/
 
914
extern JSD_PUBLIC_API(JSDScript*)
 
915
JSD_GetScriptForStackFrame(JSDContext* jsdc,
 
916
                           JSDThreadState* jsdthreadstate,
 
917
                           JSDStackFrameInfo* jsdframe);
 
918
 
 
919
/*
 
920
* Get the 'Program Counter' for the given call stack frame
 
921
*/
 
922
extern JSD_PUBLIC_API(uintptr_t)
 
923
JSD_GetPCForStackFrame(JSDContext* jsdc,
 
924
                       JSDThreadState* jsdthreadstate,
 
925
                       JSDStackFrameInfo* jsdframe);
 
926
 
 
927
/*
 
928
* Get the JavaScript Call Object for the given call stack frame.
 
929
* *** new for version 1.1 ****
 
930
*/
 
931
extern JSD_PUBLIC_API(JSDValue*)
 
932
JSD_GetCallObjectForStackFrame(JSDContext* jsdc,
 
933
                               JSDThreadState* jsdthreadstate,
 
934
                               JSDStackFrameInfo* jsdframe);
 
935
 
 
936
/*
 
937
* Get the head of the scope chain for the given call stack frame.
 
938
* the chain can be traversed using JSD_GetValueParent.
 
939
* *** new for version 1.1 ****
 
940
*/
 
941
extern JSD_PUBLIC_API(JSDValue*)
 
942
JSD_GetScopeChainForStackFrame(JSDContext* jsdc,
 
943
                               JSDThreadState* jsdthreadstate,
 
944
                               JSDStackFrameInfo* jsdframe);
 
945
 
 
946
/*
 
947
* Get the 'this' Object for the given call stack frame.
 
948
* *** new for version 1.1 ****
 
949
*/
 
950
extern JSD_PUBLIC_API(JSDValue*)
 
951
JSD_GetThisForStackFrame(JSDContext* jsdc,
 
952
                         JSDThreadState* jsdthreadstate,
 
953
                         JSDStackFrameInfo* jsdframe);
 
954
 
 
955
/*
 
956
* Get the name of the function executing in this stack frame.  Especially useful
 
957
* for native frames (without script objects.)
 
958
* *** new for gecko 2.0 ****
 
959
*/
 
960
extern JSD_PUBLIC_API(JSString *)
 
961
JSD_GetIdForStackFrame(JSDContext* jsdc,
 
962
                       JSDThreadState* jsdthreadstate,
 
963
                       JSDStackFrameInfo* jsdframe);
 
964
 
 
965
/*
 
966
* True if stack frame represents a frame created as a result of a debugger
 
967
* evaluation.
 
968
*/
 
969
extern JSD_PUBLIC_API(JSBool)
 
970
JSD_IsStackFrameDebugger(JSDContext* jsdc,
 
971
                         JSDThreadState* jsdthreadstate,
 
972
                         JSDStackFrameInfo* jsdframe);
 
973
 
 
974
/*
 
975
* True if stack frame is constructing a new object.
 
976
*/
 
977
extern JSD_PUBLIC_API(JSBool)
 
978
JSD_IsStackFrameConstructing(JSDContext* jsdc,
 
979
                             JSDThreadState* jsdthreadstate,
 
980
                             JSDStackFrameInfo* jsdframe);
 
981
 
 
982
/*
 
983
* Evaluate the given unicode source code in the context of the given stack frame.
 
984
* returns JS_TRUE and puts result in rval on success, JS_FALSE on failure.
 
985
* NOTE: The ErrorReporter hook might be called if this fails.
 
986
*/
 
987
extern JSD_PUBLIC_API(JSBool)
 
988
JSD_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
 
989
                                 JSDThreadState* jsdthreadstate,
 
990
                                 JSDStackFrameInfo* jsdframe,
 
991
                                 const jschar *bytes, unsigned length,
 
992
                                 const char *filename, unsigned lineno,
 
993
                                 jsval *rval);
 
994
 
 
995
/*
 
996
* Same as above, but does not eat exceptions.
 
997
*/
 
998
extern JSD_PUBLIC_API(JSBool)
 
999
JSD_AttemptUCScriptInStackFrame(JSDContext* jsdc,
 
1000
                                JSDThreadState* jsdthreadstate,
 
1001
                                JSDStackFrameInfo* jsdframe,
 
1002
                                const jschar *bytes, unsigned length,
 
1003
                                const char *filename, unsigned lineno,
 
1004
                                jsval *rval);
 
1005
 
 
1006
/* single byte character version of JSD_EvaluateUCScriptInStackFrame */
 
1007
extern JSD_PUBLIC_API(JSBool)
 
1008
JSD_EvaluateScriptInStackFrame(JSDContext* jsdc,
 
1009
                               JSDThreadState* jsdthreadstate,
 
1010
                               JSDStackFrameInfo* jsdframe,
 
1011
                               const char *bytes, unsigned length,
 
1012
                               const char *filename, unsigned lineno, jsval *rval);
 
1013
 
 
1014
/*
 
1015
* Same as above, but does not eat exceptions.
 
1016
*/
 
1017
extern JSD_PUBLIC_API(JSBool)
 
1018
JSD_AttemptScriptInStackFrame(JSDContext* jsdc,
 
1019
                              JSDThreadState* jsdthreadstate,
 
1020
                              JSDStackFrameInfo* jsdframe,
 
1021
                              const char *bytes, unsigned length,
 
1022
                              const char *filename, unsigned lineno, jsval *rval);
 
1023
 
 
1024
/*
 
1025
* Convert the given jsval to a string
 
1026
* NOTE: The ErrorReporter hook might be called if this fails.
 
1027
*/
 
1028
extern JSD_PUBLIC_API(JSString*)
 
1029
JSD_ValToStringInStackFrame(JSDContext* jsdc,
 
1030
                            JSDThreadState* jsdthreadstate,
 
1031
                            JSDStackFrameInfo* jsdframe,
 
1032
                            jsval val);
 
1033
 
 
1034
/*
 
1035
* Get the JSDValue currently being thrown as an exception (may be NULL).
 
1036
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1037
* *** new for version 1.1 ****
 
1038
*/
 
1039
extern JSD_PUBLIC_API(JSDValue*)
 
1040
JSD_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
 
1041
 
 
1042
/*
 
1043
* Set the JSDValue currently being thrown as an exception.
 
1044
* *** new for version 1.1 ****
 
1045
*/
 
1046
extern JSD_PUBLIC_API(JSBool)
 
1047
JSD_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, 
 
1048
                 JSDValue* jsdval);
 
1049
 
 
1050
/***************************************************************************/
 
1051
/* Error Reporter functions */
 
1052
 
 
1053
/*
 
1054
* XXX The ErrorReporter Hook scheme is going to change soon to more
 
1055
*     Fully support exceptions.
 
1056
*/
 
1057
 
 
1058
/* legal return values for JSD_ErrorReporter */
 
1059
#define JSD_ERROR_REPORTER_PASS_ALONG   0 /* pass along to regular reporter */
 
1060
#define JSD_ERROR_REPORTER_RETURN       1 /* don't pass to error reporter */
 
1061
#define JSD_ERROR_REPORTER_DEBUG        2 /* force call to DebugBreakHook */
 
1062
#define JSD_ERROR_REPORTER_CLEAR_RETURN 3 /* clear exception and don't pass */
 
1063
 
 
1064
/*
 
1065
* Implement a callback of this form in order to hook the ErrorReporter
 
1066
*/
 
1067
typedef unsigned
 
1068
(* JSD_ErrorReporter)(JSDContext*     jsdc,
 
1069
                      JSContext*      cx,
 
1070
                      const char*     message,
 
1071
                      JSErrorReport*  report,
 
1072
                      void*           callerdata);
 
1073
 
 
1074
/* Set ErrorReporter hook */
 
1075
extern JSD_PUBLIC_API(JSBool)
 
1076
JSD_SetErrorReporter(JSDContext*       jsdc,
 
1077
                     JSD_ErrorReporter reporter,
 
1078
                     void*             callerdata);
 
1079
 
 
1080
/* Get Current ErrorReporter hook */
 
1081
extern JSD_PUBLIC_API(JSBool)
 
1082
JSD_GetErrorReporter(JSDContext*        jsdc,
 
1083
                     JSD_ErrorReporter* reporter,
 
1084
                     void**             callerdata);
 
1085
 
 
1086
/***************************************************************************/
 
1087
/* Generic locks that callers can use for their own purposes */
 
1088
 
 
1089
/*
 
1090
* Is Locking and GetThread supported in this build?
 
1091
*/
 
1092
extern JSD_PUBLIC_API(JSBool)
 
1093
JSD_IsLockingAndThreadIdSupported();
 
1094
 
 
1095
/*
 
1096
* Create a reentrant/nestable lock
 
1097
*/
 
1098
extern JSD_PUBLIC_API(void*)
 
1099
JSD_CreateLock();
 
1100
 
 
1101
/*
 
1102
* Aquire lock for this thread (or block until available). Increments a
 
1103
* counter if this thread already owns the lock.
 
1104
*/
 
1105
extern JSD_PUBLIC_API(void)
 
1106
JSD_Lock(void* lock);
 
1107
 
 
1108
/*
 
1109
* Release lock for this thread (or decrement the counter if JSD_Lock
 
1110
* was previous called more than once).
 
1111
*/
 
1112
extern JSD_PUBLIC_API(void)
 
1113
JSD_Unlock(void* lock);
 
1114
 
 
1115
/*
 
1116
* For debugging only if not (JS_THREADSAFE AND DEBUG) then returns JS_TRUE
 
1117
*    So JSD_IsLocked(lock) may not equal !JSD_IsUnlocked(lock)
 
1118
*/
 
1119
extern JSD_PUBLIC_API(JSBool)
 
1120
JSD_IsLocked(void* lock);
 
1121
 
 
1122
/*
 
1123
* See above...
 
1124
*/
 
1125
extern JSD_PUBLIC_API(JSBool)
 
1126
JSD_IsUnlocked(void* lock);
 
1127
 
 
1128
/*
 
1129
* return an ID uniquely identifying this thread.
 
1130
*/
 
1131
extern JSD_PUBLIC_API(void*)
 
1132
JSD_CurrentThread();
 
1133
 
 
1134
/***************************************************************************/
 
1135
/* Value and Property Functions  --- All NEW for 1.1 --- */
 
1136
 
 
1137
/*
 
1138
* NOTE: JSDValue and JSDProperty objects are reference counted. This allows
 
1139
* for rooting these objects AND any underlying garbage collected jsvals.
 
1140
* ALL JSDValue and JSDProperty objects returned by the functions below
 
1141
* MUST eventually be released using the appropriate JSD_Dropxxx function.
 
1142
*/
 
1143
 
 
1144
/*
 
1145
* Create a new JSDValue to wrap the given jsval
 
1146
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1147
* *** new for version 1.1 ****
 
1148
*/
 
1149
extern JSD_PUBLIC_API(JSDValue*)
 
1150
JSD_NewValue(JSDContext* jsdc, jsval val);
 
1151
 
 
1152
/*
 
1153
* Release the JSDValue. After this call the object MUST not be referenced again!
 
1154
* *** new for version 1.1 ****
 
1155
*/
 
1156
extern JSD_PUBLIC_API(void)
 
1157
JSD_DropValue(JSDContext* jsdc, JSDValue* jsdval);
 
1158
 
 
1159
/*
 
1160
* Get the jsval wrapped by this JSDValue
 
1161
* *** new for version 1.1 ****
 
1162
*/
 
1163
extern JSD_PUBLIC_API(jsval)
 
1164
JSD_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
 
1165
 
 
1166
/*
 
1167
* Clear all property and association information about the given JSDValue.
 
1168
* Such information will be lazily regenerated when later accessed. This
 
1169
* function must be called to make changes to the properties of an object
 
1170
* visible to the accessor functions below (if the properties et.al. have
 
1171
* changed since a previous call to those accessors).
 
1172
* *** new for version 1.1 ****
 
1173
*/
 
1174
extern JSD_PUBLIC_API(void)
 
1175
JSD_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
 
1176
 
 
1177
/**************************************************/
 
1178
 
 
1179
/*
 
1180
* Does the JSDValue wrap a JSObject?
 
1181
* *** new for version 1.1 ****
 
1182
*/
 
1183
extern JSD_PUBLIC_API(JSBool)
 
1184
JSD_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
 
1185
 
 
1186
/*
 
1187
* Does the JSDValue wrap a number (int or double)?
 
1188
* *** new for version 1.1 ****
 
1189
*/
 
1190
extern JSD_PUBLIC_API(JSBool)
 
1191
JSD_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
 
1192
 
 
1193
/*
 
1194
* Does the JSDValue wrap an int?
 
1195
* *** new for version 1.1 ****
 
1196
*/
 
1197
extern JSD_PUBLIC_API(JSBool)
 
1198
JSD_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
 
1199
 
 
1200
/*
 
1201
* Does the JSDValue wrap a double?
 
1202
* *** new for version 1.1 ****
 
1203
*/
 
1204
extern JSD_PUBLIC_API(JSBool)
 
1205
JSD_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
 
1206
 
 
1207
/*
 
1208
* Does the JSDValue wrap a JSString?
 
1209
* *** new for version 1.1 ****
 
1210
*/
 
1211
extern JSD_PUBLIC_API(JSBool)
 
1212
JSD_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
 
1213
 
 
1214
/*
 
1215
* Does the JSDValue wrap a JSBool?
 
1216
* *** new for version 1.1 ****
 
1217
*/
 
1218
extern JSD_PUBLIC_API(JSBool)
 
1219
JSD_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
 
1220
 
 
1221
/*
 
1222
* Does the JSDValue wrap a JSVAL_NULL?
 
1223
* *** new for version 1.1 ****
 
1224
*/
 
1225
extern JSD_PUBLIC_API(JSBool)
 
1226
JSD_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
 
1227
 
 
1228
/*
 
1229
* Does the JSDValue wrap a JSVAL_VOID?
 
1230
* *** new for version 1.1 ****
 
1231
*/
 
1232
extern JSD_PUBLIC_API(JSBool)
 
1233
JSD_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
 
1234
 
 
1235
/*
 
1236
* Does the JSDValue wrap a primative (not a JSObject)?
 
1237
* *** new for version 1.1 ****
 
1238
*/
 
1239
extern JSD_PUBLIC_API(JSBool)
 
1240
JSD_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
 
1241
 
 
1242
/*
 
1243
* Does the JSDValue wrap a function?
 
1244
* *** new for version 1.1 ****
 
1245
*/
 
1246
extern JSD_PUBLIC_API(JSBool)
 
1247
JSD_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
 
1248
 
 
1249
/*
 
1250
* Does the JSDValue wrap a native function?
 
1251
* *** new for version 1.1 ****
 
1252
*/
 
1253
extern JSD_PUBLIC_API(JSBool)
 
1254
JSD_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
 
1255
 
 
1256
/**************************************************/
 
1257
 
 
1258
/*
 
1259
* Return JSBool value (does NOT do conversion).
 
1260
* *** new for version 1.1 ****
 
1261
*/
 
1262
extern JSD_PUBLIC_API(JSBool)
 
1263
JSD_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
 
1264
 
 
1265
/*
 
1266
* Return int32_t value (does NOT do conversion).
 
1267
* *** new for version 1.1 ****
 
1268
*/
 
1269
extern JSD_PUBLIC_API(int32_t)
 
1270
JSD_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
 
1271
 
 
1272
/*
 
1273
* Return double value (does NOT do conversion).
 
1274
* *** new for version 1.1 ****
 
1275
*/
 
1276
extern JSD_PUBLIC_API(double)
 
1277
JSD_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
 
1278
 
 
1279
/*
 
1280
* Return JSString value (DOES do conversion if necessary).
 
1281
* NOTE that the JSString returned is not protected from garbage
 
1282
* collection. It should be immediately read or wrapped using
 
1283
* JSD_NewValue(jsdc,STRING_TO_JSVAL(str)) if necessary.
 
1284
* *** new for version 1.1 ****
 
1285
*/
 
1286
extern JSD_PUBLIC_API(JSString*)
 
1287
JSD_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
 
1288
 
 
1289
/*
 
1290
* Return name of function IFF JSDValue represents a function.
 
1291
* *** new for gecko 2.0 ****
 
1292
*/
 
1293
extern JSD_PUBLIC_API(JSString *)
 
1294
JSD_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval);
 
1295
 
 
1296
/*
 
1297
* Return function object IFF JSDValue represents a function or an object
 
1298
* wrapping a function.
 
1299
* *** new for version 1.1 ****
 
1300
*/
 
1301
extern JSD_PUBLIC_API(JSFunction*)
 
1302
JSD_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
 
1303
 
 
1304
/**************************************************/
 
1305
 
 
1306
/*
 
1307
* Return the number of properties for the JSDValue.
 
1308
* *** new for version 1.1 ****
 
1309
*/
 
1310
extern JSD_PUBLIC_API(unsigned)
 
1311
JSD_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
 
1312
 
 
1313
/*
 
1314
* Iterate through the properties of the JSDValue.
 
1315
* Use form similar to that shown for JSD_IterateScripts (no locking required).
 
1316
* NOTE: each JSDProperty returned must eventually be released by calling
 
1317
* JSD_DropProperty.
 
1318
* *** new for version 1.1 ****
 
1319
*/
 
1320
extern JSD_PUBLIC_API(JSDProperty*)
 
1321
JSD_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
 
1322
 
 
1323
/* 
 
1324
* Get the JSDProperty for the property of this JSDVal with this name.
 
1325
* NOTE: must eventually release by calling JSD_DropProperty (if not NULL)
 
1326
* *** new for version 1.1 ****
 
1327
*/
 
1328
extern JSD_PUBLIC_API(JSDProperty*)
 
1329
JSD_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
 
1330
 
 
1331
/*
 
1332
* Get the prototype object for this JSDValue.
 
1333
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1334
* *** new for version 1.1 ****
 
1335
*/
 
1336
extern JSD_PUBLIC_API(JSDValue*)
 
1337
JSD_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
 
1338
 
 
1339
/*
 
1340
* Get the parent object for this JSDValue.
 
1341
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1342
* *** new for version 1.1 ****
 
1343
*/
 
1344
extern JSD_PUBLIC_API(JSDValue*)
 
1345
JSD_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
 
1346
 
 
1347
/*
 
1348
* Get the ctor object for this JSDValue (or likely its prototype's ctor).
 
1349
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1350
* *** new for version 1.1 ****
 
1351
*/
 
1352
extern JSD_PUBLIC_API(JSDValue*)
 
1353
JSD_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
 
1354
 
 
1355
/*
 
1356
* Get the name of the class for this object.
 
1357
* *** new for version 1.1 ****
 
1358
*/
 
1359
extern JSD_PUBLIC_API(const char*)
 
1360
JSD_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
 
1361
 
 
1362
/*
 
1363
* Get the script for the given value if the given value represents a
 
1364
* scripted function.  Otherwise, return null.
 
1365
*/
 
1366
extern JSD_PUBLIC_API(JSDScript*)
 
1367
JSD_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval);
 
1368
 
 
1369
/**************************************************/
 
1370
 
 
1371
/* possible or'd together bitflags returned by JSD_GetPropertyFlags
 
1372
 *
 
1373
 * XXX these must stay the same as the JSPD_ flags in jsdbgapi.h
 
1374
 */
 
1375
#define JSDPD_ENUMERATE  JSPD_ENUMERATE    /* visible to for/in loop */
 
1376
#define JSDPD_READONLY   JSPD_READONLY     /* assignment is error */
 
1377
#define JSDPD_PERMANENT  JSPD_PERMANENT    /* property cannot be deleted */
 
1378
#define JSDPD_ALIAS      JSPD_ALIAS        /* property has an alias id */
 
1379
#define JSDPD_EXCEPTION  JSPD_EXCEPTION    /* exception occurred looking up */
 
1380
                                           /* proprety, value is exception  */
 
1381
#define JSDPD_ERROR      JSPD_ERROR        /* native getter returned JS_FALSE */
 
1382
                                           /* without throwing an exception */
 
1383
/* this is not one of the JSPD_ flags in jsdbgapi.h  - careful not to overlap*/
 
1384
#define JSDPD_HINTED     0x800             /* found via explicit lookup */
 
1385
 
 
1386
/*
 
1387
* Release this JSDProperty
 
1388
* *** new for version 1.1 ****
 
1389
*/
 
1390
extern JSD_PUBLIC_API(void)
 
1391
JSD_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
 
1392
 
 
1393
/*
 
1394
* Get the JSDValue represeting the name of this property (int or string)
 
1395
* NOTE: must eventually release by calling JSD_DropValue
 
1396
* *** new for version 1.1 ****
 
1397
*/
 
1398
extern JSD_PUBLIC_API(JSDValue*)
 
1399
JSD_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
 
1400
 
 
1401
/*
 
1402
* Get the JSDValue represeting the current value of this property
 
1403
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1404
* *** new for version 1.1 ****
 
1405
*/
 
1406
extern JSD_PUBLIC_API(JSDValue*)
 
1407
JSD_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
 
1408
 
 
1409
/*
 
1410
* Get the JSDValue represeting the alias of this property (if JSDPD_ALIAS set)
 
1411
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1412
* *** new for version 1.1 ****
 
1413
*/
 
1414
extern JSD_PUBLIC_API(JSDValue*)
 
1415
JSD_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
 
1416
 
 
1417
/*
 
1418
* Get the flags for this property
 
1419
* *** new for version 1.1 ****
 
1420
*/
 
1421
extern JSD_PUBLIC_API(unsigned)
 
1422
JSD_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
 
1423
 
 
1424
/***************************************************************************/
 
1425
/* Object Functions  --- All NEW for 1.1 --- */
 
1426
 
 
1427
/*
 
1428
* JSDObjects exist to allow a means of iterating through all JSObjects in the
 
1429
* engine. They are created and destroyed as the wrapped JSObjects are created
 
1430
* and destroyed in the engine. JSDObjects additionally track the location in
 
1431
* the JavaScript source where their wrapped JSObjects were created and the name
 
1432
* and location of the (non-native) constructor used.
 
1433
*
 
1434
* NOTE: JSDObjects are NOT reference counted. The have only weak links to
 
1435
* jsObjects - thus they do not inhibit garbage collection of JSObjects. If
 
1436
* you need a JSDObject to safely persist then wrap it in a JSDValue (using
 
1437
* jsd_GetValueForObject).
 
1438
*/
 
1439
 
 
1440
/*
 
1441
* Lock the entire Object subsystem -- see JSD_UnlockObjectSubsystem
 
1442
* *** new for version 1.1 ****
 
1443
*/
 
1444
extern JSD_PUBLIC_API(void)
 
1445
JSD_LockObjectSubsystem(JSDContext* jsdc);
 
1446
 
 
1447
/*
 
1448
* Unlock the entire Object subsystem -- see JSD_LockObjectSubsystem
 
1449
* *** new for version 1.1 ****
 
1450
*/
 
1451
extern JSD_PUBLIC_API(void)
 
1452
JSD_UnlockObjectSubsystem(JSDContext* jsdc);
 
1453
 
 
1454
/*
 
1455
* Iterate through the known objects
 
1456
* Use form similar to that shown for JSD_IterateScripts.
 
1457
* NOTE: the ObjectSubsystem must be locked before and unlocked after iterating.
 
1458
* *** new for version 1.1 ****
 
1459
*/
 
1460
extern JSD_PUBLIC_API(JSDObject*)
 
1461
JSD_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
 
1462
 
 
1463
/*
 
1464
* Get the JSObject represented by this JSDObject
 
1465
* *** new for version 1.1 ****
 
1466
*/
 
1467
extern JSD_PUBLIC_API(JSObject*)
 
1468
JSD_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
 
1469
 
 
1470
/*
 
1471
* Get the URL of the line of source that caused this object to be created.
 
1472
* May be NULL.
 
1473
* *** new for version 1.1 ****
 
1474
*/
 
1475
extern JSD_PUBLIC_API(const char*)
 
1476
JSD_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
 
1477
 
 
1478
/*
 
1479
* Get the line number of the line of source that caused this object to be
 
1480
* created. May be 0 indicating that the line number is unknown.
 
1481
* *** new for version 1.1 ****
 
1482
*/
 
1483
extern JSD_PUBLIC_API(unsigned)
 
1484
JSD_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
 
1485
 
 
1486
/*
 
1487
* Get the URL of the line of source of the constructor for this object.
 
1488
* May be NULL.
 
1489
* *** new for version 1.1 ****
 
1490
*/
 
1491
extern JSD_PUBLIC_API(const char*)
 
1492
JSD_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
 
1493
 
 
1494
/*
 
1495
* Get the line number of the line of source of the constructor for this object.
 
1496
* created. May be 0 indicating that the line number is unknown.
 
1497
* *** new for version 1.1 ****
 
1498
*/
 
1499
extern JSD_PUBLIC_API(unsigned)
 
1500
JSD_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
 
1501
 
 
1502
/*
 
1503
* Get the name of the constructor for this object.
 
1504
* May be NULL.
 
1505
* *** new for version 1.1 ****
 
1506
*/
 
1507
extern JSD_PUBLIC_API(const char*)
 
1508
JSD_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
 
1509
 
 
1510
/*
 
1511
* Get JSDObject representing this JSObject.
 
1512
* May return NULL.
 
1513
* *** new for version 1.1 ****
 
1514
*/
 
1515
extern JSD_PUBLIC_API(JSDObject*)
 
1516
JSD_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
 
1517
 
 
1518
/*
 
1519
* Get JSDObject representing this JSDValue.
 
1520
* May return NULL.
 
1521
* *** new for version 1.1 ****
 
1522
*/
 
1523
extern JSD_PUBLIC_API(JSDObject*)
 
1524
JSD_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
 
1525
 
 
1526
/*
 
1527
* Create a JSDValue to wrap (and root) this JSDObject.
 
1528
* NOTE: must eventually release by calling JSD_DropValue (if not NULL)
 
1529
* *** new for version 1.1 ****
 
1530
*/
 
1531
extern JSD_PUBLIC_API(JSDValue*)
 
1532
JSD_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
 
1533
 
 
1534
/***************************************************************************/
 
1535
/* Livewire specific API */
 
1536
#ifdef LIVEWIRE
 
1537
 
 
1538
extern JSD_PUBLIC_API(LWDBGScript*)
 
1539
JSDLW_GetLWScript(JSDContext* jsdc, JSDScript* jsdscript);
 
1540
 
 
1541
extern JSD_PUBLIC_API(JSDSourceText*)
 
1542
JSDLW_PreLoadSource(JSDContext* jsdc, LWDBGApp* app,
 
1543
                    const char* filename, JSBool clear);
 
1544
 
 
1545
extern JSD_PUBLIC_API(JSDSourceText*)
 
1546
JSDLW_ForceLoadSource(JSDContext* jsdc, JSDSourceText* jsdsrc);
 
1547
 
 
1548
extern JSD_PUBLIC_API(JSBool)
 
1549
JSDLW_RawToProcessedLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
 
1550
                               unsigned lineIn, unsigned* lineOut);
 
1551
 
 
1552
extern JSD_PUBLIC_API(JSBool)
 
1553
JSDLW_ProcessedToRawLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
 
1554
                               unsigned lineIn, unsigned* lineOut);
 
1555
 
 
1556
#endif
 
1557
/***************************************************************************/
 
1558
 
 
1559
JS_END_EXTERN_C
 
1560
 
 
1561
#endif /* jsdebug_h___ */