Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / jsd / jsd.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 /*
39  * Header for JavaScript Debugging support - Internal ONLY declarations
40  */
41
42 #ifndef jsd_h___
43 #define jsd_h___
44
45 /*
46 * NOTE: This is a *private* header file and should only be included by
47 * the sources in js/jsd. Defining EXPORT_JSD_API in an outside module
48 * using jsd would be bad.
49 */
50 #define EXPORT_JSD_API 1 /* if used, must be set before include of jsdebug.h */
51
52 /*
53 * These can be controled by the makefile, but this allows a place to set
54 * the values always used in the mozilla client, but perhaps done differently
55 * in other embeddings.
56 */
57 #ifdef MOZILLA_CLIENT
58 #define JSD_THREADSAFE 1
59 /* define JSD_HAS_DANGEROUS_THREAD 1 */
60 #define JSD_USE_NSPR_LOCKS 1
61 #endif /* MOZILLA_CLIENT */
62
63
64 /* Get jstypes.h included first. After that we can use PR macros for doing
65 *  this extern "C" stuff!
66 */
67 #ifdef __cplusplus
68 extern "C"
69 {
70 #endif
71 #include "jstypes.h"
72 #ifdef __cplusplus
73 }
74 #endif
75
76 JS_BEGIN_EXTERN_C
77 #include "jsprf.h"
78 #include "jsutil.h" /* Added by JSIFY */
79 #include "jshash.h" /* Added by JSIFY */
80 #include "jsclist.h"
81 #include "jsdebug.h"
82 #include "jsapi.h"
83 #include "jsdbgapi.h"
84 #include "jsd_lock.h"
85
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
89
90 #ifdef LIVEWIRE
91 #include <base/pblock.h>
92 #include <base/session.h>
93 #include <frame/log.h>
94 #include <frame/req.h>
95 #endif /* LIVEWIRE */
96 JS_END_EXTERN_C
97
98 JS_BEGIN_EXTERN_C
99
100 #define JSD_MAJOR_VERSION 1
101 #define JSD_MINOR_VERSION 1
102
103 /***************************************************************************/
104 /* handy macros */
105 #undef  CHECK_BIT_FLAG
106 #define CHECK_BIT_FLAG(f,b) ((f)&(b))
107 #undef  SET_BIT_FLAG
108 #define SET_BIT_FLAG(f,b)   ((f)|=(b))
109 #undef  CLEAR_BIT_FLAG
110 #define CLEAR_BIT_FLAG(f,b) ((f)&=(~(b)))
111
112 #define JSD_IS_DEBUG_ENABLED(jsdc,jsdscript)                                   \
113         (!(((jsdc->flags & JSD_DEBUG_WHEN_SET) ? 1 : 0)  ^                     \
114            ((jsdscript->flags & JSD_SCRIPT_DEBUG_BIT) ?  1 : 0)))
115 #define JSD_IS_PROFILE_ENABLED(jsdc,jsdscript)                                 \
116         ((jsdc->flags & JSD_COLLECT_PROFILE_DATA) &&                           \
117          (!(((jsdc->flags & JSD_PROFILE_WHEN_SET) ? 1 : 0) ^                   \
118             ((jsdscript->flags & JSD_SCRIPT_PROFILE_BIT) ? 1 : 0))))
119
120
121 /***************************************************************************/
122 /* These are not exposed in jsdebug.h - typedef here for consistency */
123
124 typedef struct JSDExecHook          JSDExecHook;
125 typedef struct JSDAtom              JSDAtom;
126 typedef struct JSDProfileData       JSDProfileData;
127 /***************************************************************************/
128 /* Our structures */
129
130 /*
131 * XXX What I'm calling a JSDContext is really more of a JSDTaskState. 
132 */
133
134 struct JSDContext
135 {
136     JSCList                 links;      /* we are part of a JSCList */
137     JSBool                  inited;
138     void*                   data;
139     uint32                  flags;
140     JSD_ScriptHookProc      scriptHook;
141     void*                   scriptHookData;
142     JSD_ExecutionHookProc   interruptHook;
143     void*                   interruptHookData;
144     JSRuntime*              jsrt;
145     JSD_ErrorReporter       errorReporter;
146     void*                   errorReporterData;
147     JSCList                 threadsStates;
148     JSD_ExecutionHookProc   debugBreakHook;
149     void*                   debugBreakHookData;
150     JSD_ExecutionHookProc   debuggerHook;
151     void*                   debuggerHookData;
152     JSD_ExecutionHookProc   throwHook;
153     void*                   throwHookData;
154     JSD_CallHookProc        functionHook;
155     void*                   functionHookData;
156     JSD_CallHookProc        toplevelHook;
157     void*                   toplevelHookData;
158     JSContext*              dumbContext;
159     JSObject*               glob;
160     JSD_UserCallbacks       userCallbacks;
161     void*                   user;
162     JSCList                 scripts;
163     JSHashTable*            scriptsTable;
164     JSCList                 sources;
165     JSCList                 removedSources;
166     uintN                   sourceAlterCount;
167     JSHashTable*            atoms;
168     JSCList                 objectsList;
169     JSHashTable*            objectsTable;
170     JSDProfileData*         callingFunctionPData;
171     int64                   lastReturnTime;
172 #ifdef JSD_THREADSAFE
173     void*                   scriptsLock;
174     void*                   sourceTextLock;
175     void*                   objectsLock;
176     void*                   atomsLock;
177     void*                   threadStatesLock;
178 #endif /* JSD_THREADSAFE */
179 #ifdef JSD_HAS_DANGEROUS_THREAD
180     void*                   dangerousThread;
181 #endif /* JSD_HAS_DANGEROUS_THREAD */
182
183 };
184
185 struct JSDScript
186 {
187     JSCList     links;      /* we are part of a JSCList */
188     JSDContext* jsdc;       /* JSDContext for this jsdscript */
189     JSScript*   script;     /* script we are wrapping */
190     JSFunction* function;   /* back pointer to owning function (can be NULL) */
191     uintN       lineBase;   /* we cache this */
192     uintN       lineExtent; /* we cache this */
193     JSCList     hooks;      /* JSCList of JSDExecHooks for this script */
194     char*       url;
195     uint32      flags;
196     void*       data;
197
198     JSDProfileData  *profileData;
199
200 #ifdef LIVEWIRE
201     LWDBGApp*    app;
202     LWDBGScript* lwscript;
203 #endif
204 };
205
206 struct JSDProfileData
207 {
208     JSDProfileData* caller;
209     int64    lastCallStart;
210     int64    runningTime;
211     uintN    callCount;
212     uintN    recurseDepth;
213     uintN    maxRecurseDepth;
214     jsdouble minExecutionTime;
215     jsdouble maxExecutionTime;
216     jsdouble totalExecutionTime;
217     jsdouble minOwnExecutionTime;
218     jsdouble maxOwnExecutionTime;
219     jsdouble totalOwnExecutionTime;
220 };
221
222 struct JSDSourceText
223 {
224     JSCList          links;      /* we are part of a JSCList */
225     char*            url;
226     char*            text;
227     uintN            textLength;
228     uintN            textSpace;
229     JSBool           dirty;
230     JSDSourceStatus  status;
231     uintN            alterCount;
232     JSBool           doingEval;
233 };
234
235 struct JSDExecHook
236 {
237     JSCList               links;        /* we are part of a JSCList */
238     JSDScript*            jsdscript;
239     jsuword               pc;
240     JSD_ExecutionHookProc hook;
241     void*                 callerdata;
242 };
243
244 #define TS_HAS_DISABLED_FRAME 0x01
245
246 struct JSDThreadState
247 {
248     JSCList             links;        /* we are part of a JSCList */
249     JSContext*          context;
250     void*               thread;
251     JSCList             stack;
252     uintN               stackDepth;
253     uintN               flags;
254 };
255
256 struct JSDStackFrameInfo
257 {
258     JSCList             links;        /* we are part of a JSCList */
259     JSDThreadState*     jsdthreadstate;
260     JSDScript*          jsdscript;
261     jsuword             pc;
262     JSStackFrame*       fp;
263 };
264
265 #define GOT_PROTO   ((short) (1 << 0))
266 #define GOT_PROPS   ((short) (1 << 1))
267 #define GOT_PARENT  ((short) (1 << 2))
268 #define GOT_CTOR    ((short) (1 << 3))
269
270 struct JSDValue
271 {
272     jsval       val;
273     intN        nref;
274     JSCList     props;
275     JSString*   string;
276     JSString*   funName;
277     const char* className;
278     JSDValue*   proto;
279     JSDValue*   parent;
280     JSDValue*   ctor;
281     uintN       flags;
282 };
283
284 struct JSDProperty
285 {
286     JSCList     links;      /* we are part of a JSCList */
287     intN        nref;
288     JSDValue*   val;
289     JSDValue*   name;
290     JSDValue*   alias;
291     uintN       slot;
292     uintN       flags;
293 };
294
295 struct JSDAtom
296 {
297     char* str;      /* must be first element in struct for compare */
298     intN  refcount;
299 };
300
301 struct JSDObject
302 {
303     JSCList     links;      /* we are part of a JSCList */
304     JSObject*   obj;
305     JSDAtom*    newURL;
306     uintN       newLineno;
307     JSDAtom*    ctorURL;
308     uintN       ctorLineno;
309     JSDAtom*    ctorName;
310 };
311
312 /***************************************************************************/
313 /* Code validation support */
314
315 #ifdef DEBUG
316 extern void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc);
317 extern void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript);
318 extern void JSD_ASSERT_VALID_SOURCE_TEXT(JSDSourceText* jsdsrc);
319 extern void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate);
320 extern void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe);
321 extern void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook);
322 extern void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval);
323 extern void JSD_ASSERT_VALID_PROPERTY(JSDProperty* jsdprop);
324 extern void JSD_ASSERT_VALID_OBJECT(JSDObject* jsdobj);
325 #else
326 #define JSD_ASSERT_VALID_CONTEXT(x)     ((void)0)
327 #define JSD_ASSERT_VALID_SCRIPT(x)      ((void)0)
328 #define JSD_ASSERT_VALID_SOURCE_TEXT(x) ((void)0)
329 #define JSD_ASSERT_VALID_THREAD_STATE(x)((void)0)
330 #define JSD_ASSERT_VALID_STACK_FRAME(x) ((void)0)
331 #define JSD_ASSERT_VALID_EXEC_HOOK(x)   ((void)0)
332 #define JSD_ASSERT_VALID_VALUE(x)       ((void)0)
333 #define JSD_ASSERT_VALID_PROPERTY(x)    ((void)0)
334 #define JSD_ASSERT_VALID_OBJECT(x)      ((void)0)
335 #endif
336
337 /***************************************************************************/
338 /* higher level functions */
339
340 extern JSDContext*
341 jsd_DebuggerOnForUser(JSRuntime*         jsrt,
342                       JSD_UserCallbacks* callbacks,
343                       void*              user,
344                       JSObject*          scopeobj);
345
346 extern JSDContext*
347 jsd_DebuggerOn(void);
348
349 extern void
350 jsd_DebuggerOff(JSDContext* jsdc);
351
352 extern void
353 jsd_DebuggerPause(JSDContext* jsdc, JSBool forceAllHooksOff);
354
355 extern void
356 jsd_DebuggerUnpause(JSDContext* jsdc);
357
358 extern void
359 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user);
360
361 extern JSDContext*
362 jsd_JSDContextForJSContext(JSContext* context);
363
364 extern void*
365 jsd_SetContextPrivate(JSDContext* jsdc, void *data);
366
367 extern void*
368 jsd_GetContextPrivate(JSDContext* jsdc);
369
370 extern void
371 jsd_ClearAllProfileData(JSDContext* jsdc);
372
373 extern JSBool
374 jsd_SetErrorReporter(JSDContext*       jsdc,
375                      JSD_ErrorReporter reporter,
376                      void*             callerdata);
377
378 extern JSBool
379 jsd_GetErrorReporter(JSDContext*        jsdc,
380                      JSD_ErrorReporter* reporter,
381                      void**             callerdata);
382
383 static JSBool
384 jsd_DebugErrorHook(JSContext *cx, const char *message,
385                    JSErrorReport *report, void *closure);
386
387 /***************************************************************************/
388 /* Script functions */
389
390 extern JSBool
391 jsd_InitScriptManager(JSDContext *jsdc);
392
393 extern void
394 jsd_DestroyScriptManager(JSDContext* jsdc);
395
396 extern JSDScript*
397 jsd_FindJSDScript(JSDContext*  jsdc,
398                   JSScript     *script);
399
400 extern JSDScript*
401 jsd_FindOrCreateJSDScript(JSDContext    *jsdc,
402                           JSContext     *cx,
403                           JSScript      *script,
404                           JSStackFrame  *fp);
405
406 extern JSDProfileData*
407 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
408
409 extern uint32
410 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
411
412 extern void
413 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags);
414
415 extern uintN
416 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
417
418 extern  uintN
419 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
420
421 extern jsdouble
422 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
423
424 extern jsdouble
425 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
426
427 extern jsdouble
428 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
429
430 extern jsdouble
431 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
432
433 extern jsdouble
434 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
435
436 extern jsdouble
437 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
438
439 extern void
440 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
441
442 extern JSScript *
443 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script);
444
445 extern JSFunction *
446 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script);
447
448 extern JSDScript*
449 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
450
451 extern void *
452 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data);
453
454 extern void *
455 jsd_GetScriptPrivate (JSDScript *jsdscript);
456
457 extern JSBool
458 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
459
460 extern const char*
461 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
462
463 extern JSString*
464 jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript);
465
466 extern uintN
467 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
468
469 extern uintN
470 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
471
472 extern JSBool
473 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
474
475 extern JSBool
476 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
477
478 extern jsuword
479 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line);
480
481 extern uintN
482 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
483
484 extern void
485 jsd_NewScriptHookProc(
486                 JSContext   *cx,
487                 const char  *filename,      /* URL this script loads from */
488                 uintN       lineno,         /* line where this script starts */
489                 JSScript    *script,
490                 JSFunction  *fun,
491                 void*       callerdata);
492
493 extern void
494 jsd_DestroyScriptHookProc(
495                 JSContext   *cx,
496                 JSScript    *script,
497                 void*       callerdata);
498
499 /* Script execution hook functions */
500
501 extern JSBool
502 jsd_SetExecutionHook(JSDContext*           jsdc,
503                      JSDScript*            jsdscript,
504                      jsuword               pc,
505                      JSD_ExecutionHookProc hook,
506                      void*                 callerdata);
507
508 extern JSBool
509 jsd_ClearExecutionHook(JSDContext*           jsdc,
510                        JSDScript*            jsdscript,
511                        jsuword               pc);
512
513 extern JSBool
514 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
515
516 extern JSBool
517 jsd_ClearAllExecutionHooks(JSDContext* jsdc);
518
519 extern void
520 jsd_ScriptCreated(JSDContext* jsdc,
521                   JSContext   *cx,
522                   const char  *filename,    /* URL this script loads from */
523                   uintN       lineno,       /* line where this script starts */
524                   JSScript    *script,
525                   JSFunction  *fun);
526
527 extern void
528 jsd_ScriptDestroyed(JSDContext* jsdc,
529                     JSContext   *cx,
530                     JSScript    *script);
531
532 /***************************************************************************/
533 /* Source Text functions */
534
535 extern JSDSourceText*
536 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
537
538 extern JSDSourceText*
539 jsd_FindSourceForURL(JSDContext* jsdc, const char* url);
540
541 extern const char*
542 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
543
544 extern JSBool
545 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
546                   const char** ppBuf, intN* pLen);
547
548 extern void
549 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
550
551 extern JSDSourceStatus
552 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
553
554 extern JSBool
555 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
556
557 extern void
558 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, JSBool dirty);
559
560 extern uintN
561 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
562
563 extern uintN
564 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
565
566 extern JSDSourceText*
567 jsd_NewSourceText(JSDContext* jsdc, const char* url);
568
569 extern JSDSourceText*
570 jsd_AppendSourceText(JSDContext* jsdc,
571                      JSDSourceText* jsdsrc,
572                      const char* text,       /* *not* zero terminated */
573                      size_t length,
574                      JSDSourceStatus status);
575
576 extern JSDSourceText*
577 jsd_AppendUCSourceText(JSDContext* jsdc,
578                        JSDSourceText* jsdsrc,
579                        const jschar* text,       /* *not* zero terminated */
580                        size_t length,
581                        JSDSourceStatus status);
582
583 /* convienence function for adding complete source of url in one call */
584 extern JSBool
585 jsd_AddFullSourceText(JSDContext* jsdc,
586                       const char* text,       /* *not* zero terminated */
587                       size_t      length,
588                       const char* url);
589
590 extern void
591 jsd_DestroyAllSources(JSDContext* jsdc);
592
593 extern const char*
594 jsd_BuildNormalizedURL(const char* url_string);
595
596 extern void
597 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
598
599 extern void
600 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
601
602 /***************************************************************************/
603 /* Interrupt Hook functions */
604
605 extern JSBool
606 jsd_SetInterruptHook(JSDContext*           jsdc,
607                      JSD_ExecutionHookProc hook,
608                      void*                 callerdata);
609
610 extern JSBool
611 jsd_ClearInterruptHook(JSDContext* jsdc);
612
613 extern JSBool
614 jsd_EnableSingleStepInterrupts(JSDContext* jsdc,
615                                JSDScript*  jsdscript,
616                                JSBool      enable);
617
618 extern JSBool
619 jsd_SetDebugBreakHook(JSDContext*           jsdc,
620                       JSD_ExecutionHookProc hook,
621                       void*                 callerdata);
622
623 extern JSBool
624 jsd_ClearDebugBreakHook(JSDContext* jsdc);
625
626 extern JSBool
627 jsd_SetDebuggerHook(JSDContext*           jsdc,
628                     JSD_ExecutionHookProc hook,
629                     void*                 callerdata);
630
631 extern JSBool
632 jsd_ClearDebuggerHook(JSDContext* jsdc);
633
634 extern JSTrapStatus
635 jsd_CallExecutionHook(JSDContext*           jsdc,
636                       JSContext*            cx,
637                       uintN                 type,
638                       JSD_ExecutionHookProc hook,
639                       void*                 hookData,
640                       jsval*                rval);
641
642 extern JSBool
643 jsd_CallCallHook (JSDContext*      jsdc,
644                   JSContext*       cx,
645                   uintN            type,
646                   JSD_CallHookProc hook,
647                   void*            hookData);
648
649 extern JSBool
650 jsd_SetThrowHook(JSDContext*           jsdc,
651                  JSD_ExecutionHookProc hook,
652                  void*                 callerdata);
653 extern JSBool
654 jsd_ClearThrowHook(JSDContext* jsdc);
655
656 extern JSTrapStatus
657 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
658                     jsval *rval, void *closure);
659
660 extern JSTrapStatus
661 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
662                  jsval *rval, void *closure);
663
664 extern JSBool
665 jsd_SetFunctionHook(JSDContext*      jsdc,
666                     JSD_CallHookProc hook,
667                     void*            callerdata);
668
669 extern JSBool
670 jsd_ClearFunctionHook(JSDContext* jsdc);
671
672 extern JSBool
673 jsd_SetTopLevelHook(JSDContext*      jsdc,
674                     JSD_CallHookProc hook,
675                     void*            callerdata);
676
677 extern JSBool
678 jsd_ClearTopLevelHook(JSDContext* jsdc);
679
680 /***************************************************************************/
681 /* Stack Frame functions */
682
683 extern uintN
684 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
685
686 extern JSDStackFrameInfo*
687 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
688
689 extern JSContext*
690 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
691
692 extern JSDStackFrameInfo*
693 jsd_GetCallingStackFrame(JSDContext* jsdc,
694                          JSDThreadState* jsdthreadstate,
695                          JSDStackFrameInfo* jsdframe);
696
697 extern JSDScript*
698 jsd_GetScriptForStackFrame(JSDContext* jsdc,
699                            JSDThreadState* jsdthreadstate,
700                            JSDStackFrameInfo* jsdframe);
701
702 extern jsuword
703 jsd_GetPCForStackFrame(JSDContext* jsdc,
704                        JSDThreadState* jsdthreadstate,
705                        JSDStackFrameInfo* jsdframe);
706
707 extern JSDValue*
708 jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
709                                JSDThreadState* jsdthreadstate,
710                                JSDStackFrameInfo* jsdframe);
711
712 extern JSDValue*
713 jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
714                                JSDThreadState* jsdthreadstate,
715                                JSDStackFrameInfo* jsdframe);
716
717 extern JSBool
718 jsd_IsStackFrameDebugger(JSDContext* jsdc, 
719                          JSDThreadState* jsdthreadstate,
720                          JSDStackFrameInfo* jsdframe);
721
722 extern JSBool
723 jsd_IsStackFrameConstructing(JSDContext* jsdc, 
724                              JSDThreadState* jsdthreadstate,
725                              JSDStackFrameInfo* jsdframe);
726
727 extern JSDValue*
728 jsd_GetThisForStackFrame(JSDContext* jsdc,
729                          JSDThreadState* jsdthreadstate,
730                          JSDStackFrameInfo* jsdframe);
731
732 extern JSString*
733 jsd_GetIdForStackFrame(JSDContext* jsdc, 
734                        JSDThreadState* jsdthreadstate,
735                        JSDStackFrameInfo* jsdframe);
736
737 extern JSDThreadState*
738 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx);
739
740 extern void
741 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
742
743 extern JSBool
744 jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
745                                  JSDThreadState* jsdthreadstate,
746                                  JSDStackFrameInfo* jsdframe,
747                                  const jschar *bytes, uintN length,
748                                  const char *filename, uintN lineno,
749                                  JSBool eatExceptions, jsval *rval);
750
751 extern JSBool
752 jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
753                                JSDThreadState* jsdthreadstate,
754                                JSDStackFrameInfo* jsdframe,
755                                const char *bytes, uintN length,
756                                const char *filename, uintN lineno,
757                                JSBool eatExceptions, jsval *rval);
758
759 extern JSString*
760 jsd_ValToStringInStackFrame(JSDContext* jsdc,
761                             JSDThreadState* jsdthreadstate,
762                             JSDStackFrameInfo* jsdframe,
763                             jsval val);
764
765 extern JSBool
766 jsd_IsValidThreadState(JSDContext*        jsdc,
767                        JSDThreadState*    jsdthreadstate);
768
769 extern JSBool
770 jsd_IsValidFrameInThreadState(JSDContext*        jsdc,
771                               JSDThreadState*    jsdthreadstate,
772                               JSDStackFrameInfo* jsdframe);
773
774 extern JSDValue*
775 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
776
777 extern JSBool
778 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, 
779                  JSDValue* jsdval);
780
781 /***************************************************************************/
782 /* Locking support */
783
784 /* protos are in js_lock.h for:
785  *      jsd_CreateLock
786  *      jsd_Lock
787  *      jsd_Unlock
788  *      jsd_IsLocked
789  *      jsd_CurrentThread
790  */
791
792 #ifdef JSD_THREADSAFE
793
794 /* the system-wide lock */
795 extern void* _jsd_global_lock;
796 #define JSD_LOCK()                               \
797     JS_BEGIN_MACRO                               \
798         if(!_jsd_global_lock)                    \
799             _jsd_global_lock = jsd_CreateLock(); \
800         JS_ASSERT(_jsd_global_lock);             \
801         jsd_Lock(_jsd_global_lock);              \
802     JS_END_MACRO
803
804 #define JSD_UNLOCK()                             \
805     JS_BEGIN_MACRO                               \
806         JS_ASSERT(_jsd_global_lock);             \
807         jsd_Unlock(_jsd_global_lock);            \
808     JS_END_MACRO
809
810 /* locks for the subsystems of a given context */
811 #define JSD_INIT_LOCKS(jsdc)                                    \
812     ( (NULL != (jsdc->scriptsLock      = jsd_CreateLock())) &&  \
813       (NULL != (jsdc->sourceTextLock   = jsd_CreateLock())) &&  \
814       (NULL != (jsdc->atomsLock        = jsd_CreateLock())) &&  \
815       (NULL != (jsdc->objectsLock      = jsd_CreateLock())) &&  \
816       (NULL != (jsdc->threadStatesLock = jsd_CreateLock())) )
817
818 #define JSD_LOCK_SCRIPTS(jsdc)        jsd_Lock(jsdc->scriptsLock)
819 #define JSD_UNLOCK_SCRIPTS(jsdc)      jsd_Unlock(jsdc->scriptsLock)
820
821 #define JSD_LOCK_SOURCE_TEXT(jsdc)    jsd_Lock(jsdc->sourceTextLock)
822 #define JSD_UNLOCK_SOURCE_TEXT(jsdc)  jsd_Unlock(jsdc->sourceTextLock)
823
824 #define JSD_LOCK_ATOMS(jsdc)          jsd_Lock(jsdc->atomsLock)
825 #define JSD_UNLOCK_ATOMS(jsdc)        jsd_Unlock(jsdc->atomsLock)
826
827 #define JSD_LOCK_OBJECTS(jsdc)        jsd_Lock(jsdc->objectsLock)
828 #define JSD_UNLOCK_OBJECTS(jsdc)      jsd_Unlock(jsdc->objectsLock)
829
830 #define JSD_LOCK_THREADSTATES(jsdc)   jsd_Lock(jsdc->threadStatesLock)
831 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock)
832
833 #else  /* !JSD_THREADSAFE */
834
835 #define JSD_LOCK()                    ((void)0)
836 #define JSD_UNLOCK()                  ((void)0)
837
838 #define JSD_INIT_LOCKS(jsdc)          1
839
840 #define JSD_LOCK_SCRIPTS(jsdc)        ((void)0)
841 #define JSD_UNLOCK_SCRIPTS(jsdc)      ((void)0)
842
843 #define JSD_LOCK_SOURCE_TEXT(jsdc)    ((void)0)
844 #define JSD_UNLOCK_SOURCE_TEXT(jsdc)  ((void)0)
845
846 #define JSD_LOCK_ATOMS(jsdc)          ((void)0)
847 #define JSD_UNLOCK_ATOMS(jsdc)        ((void)0)
848
849 #define JSD_LOCK_OBJECTS(jsdc)        ((void)0)
850 #define JSD_UNLOCK_OBJECTS(jsdc)      ((void)0)
851
852 #define JSD_LOCK_THREADSTATES(jsdc)   ((void)0)
853 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0)
854
855 #endif /* JSD_THREADSAFE */
856
857 /* NOTE: These are intended for ASSERTs. Thus we supply checks for both
858  * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in
859  * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds
860  * without having to special case things in the code.
861  */
862 #if defined(JSD_THREADSAFE) && defined(DEBUG)
863 #define JSD_SCRIPTS_LOCKED(jsdc)        (jsd_IsLocked(jsdc->scriptsLock))
864 #define JSD_SOURCE_TEXT_LOCKED(jsdc)    (jsd_IsLocked(jsdc->sourceTextLock))
865 #define JSD_ATOMS_LOCKED(jsdc)          (jsd_IsLocked(jsdc->atomsLock))
866 #define JSD_OBJECTS_LOCKED(jsdc)        (jsd_IsLocked(jsdc->objectsLock))
867 #define JSD_THREADSTATES_LOCKED(jsdc)   (jsd_IsLocked(jsdc->threadStatesLock))
868 #define JSD_SCRIPTS_UNLOCKED(jsdc)      (!jsd_IsLocked(jsdc->scriptsLock))
869 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc)  (!jsd_IsLocked(jsdc->sourceTextLock))
870 #define JSD_ATOMS_UNLOCKED(jsdc)        (!jsd_IsLocked(jsdc->atomsLock))
871 #define JSD_OBJECTS_UNLOCKED(jsdc)      (!jsd_IsLocked(jsdc->objectsLock))
872 #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock))
873 #else
874 #define JSD_SCRIPTS_LOCKED(jsdc)        1
875 #define JSD_SOURCE_TEXT_LOCKED(jsdc)    1
876 #define JSD_ATOMS_LOCKED(jsdc)          1
877 #define JSD_OBJECTS_LOCKED(jsdc)        1
878 #define JSD_THREADSTATES_LOCKED(jsdc)   1
879 #define JSD_SCRIPTS_UNLOCKED(jsdc)      1
880 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc)  1
881 #define JSD_ATOMS_UNLOCKED(jsdc)        1
882 #define JSD_OBJECTS_UNLOCKED(jsdc)      1
883 #define JSD_THREADSTATES_UNLOCKED(jsdc) 1
884 #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */
885
886 /***************************************************************************/
887 /* Threading support */
888
889 #ifdef JSD_THREADSAFE
890
891 #define JSD_CURRENT_THREAD()        jsd_CurrentThread()
892
893 #else  /* !JSD_THREADSAFE */
894
895 #define JSD_CURRENT_THREAD()        ((void*)0)
896
897 #endif /* JSD_THREADSAFE */
898
899 /***************************************************************************/
900 /* Dangerous thread support */
901
902 #ifdef JSD_HAS_DANGEROUS_THREAD
903
904 #define JSD_IS_DANGEROUS_THREAD(jsdc) \
905     (JSD_CURRENT_THREAD() == jsdc->dangerousThread)
906
907 #else  /* !JSD_HAS_DANGEROUS_THREAD */
908
909 #define JSD_IS_DANGEROUS_THREAD(jsdc)   0
910
911 #endif /* JSD_HAS_DANGEROUS_THREAD */
912
913 /***************************************************************************/
914 /* Value and Property Functions */
915
916 extern JSDValue*
917 jsd_NewValue(JSDContext* jsdc, jsval val);
918
919 extern void
920 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval);
921
922 extern jsval
923 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
924
925 extern void
926 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
927
928 /**************************************************/
929
930 extern JSBool
931 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
932
933 extern JSBool
934 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
935
936 extern JSBool
937 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
938
939 extern JSBool
940 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
941
942 extern JSBool
943 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
944
945 extern JSBool
946 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
947
948 extern JSBool
949 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
950
951 extern JSBool
952 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
953
954 extern JSBool
955 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
956
957 extern JSBool
958 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
959
960 extern JSBool
961 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
962
963 /**************************************************/
964
965 extern JSBool
966 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
967
968 extern int32
969 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
970
971 extern jsdouble
972 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
973
974 extern JSString*
975 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
976
977 extern JSString*
978 jsd_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval);
979
980 extern JSFunction*
981 jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
982
983 /**************************************************/
984
985 extern uintN
986 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
987
988 extern JSDProperty*
989 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
990
991 extern JSDProperty*
992 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
993
994 extern JSDValue*
995 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
996
997 extern JSDValue*
998 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
999
1000 extern JSDValue*
1001 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
1002
1003 extern const char*
1004 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
1005
1006 extern JSDScript*
1007 jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval);
1008
1009 /**************************************************/
1010
1011 extern void
1012 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
1013
1014 extern JSDValue*
1015 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
1016
1017 extern JSDValue*
1018 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
1019
1020 extern JSDValue*
1021 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
1022
1023 extern uintN
1024 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
1025
1026 extern uintN
1027 jsd_GetPropertyVarArgSlot(JSDContext* jsdc, JSDProperty* jsdprop);
1028
1029 /**************************************************/
1030 /* Stepping Functions */
1031
1032 extern void *
1033 jsd_FunctionCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1034                      JSBool *ok, void *closure);
1035
1036 extern void *
1037 jsd_TopLevelCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1038                      JSBool *ok, void *closure);
1039
1040 /**************************************************/
1041 /* Object Functions */
1042
1043 extern JSBool
1044 jsd_InitObjectManager(JSDContext* jsdc);
1045
1046 extern void
1047 jsd_DestroyObjectManager(JSDContext* jsdc);
1048
1049 extern void
1050 jsd_DestroyObjects(JSDContext* jsdc);
1051
1052 extern void
1053 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
1054                  JSStackFrame *fp);
1055
1056 extern JSDObject*
1057 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
1058
1059 extern JSObject*
1060 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
1061
1062 extern const char*
1063 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
1064
1065 extern uintN
1066 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1067
1068 extern const char*
1069 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
1070
1071 extern uintN
1072 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1073
1074 extern const char*
1075 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
1076
1077 extern JSDObject*
1078 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
1079
1080 extern JSDObject*
1081 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
1082
1083 /*
1084 * returns new refcounted JSDValue
1085 */
1086 extern JSDValue*
1087 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
1088
1089 /**************************************************/
1090 /* Atom Functions */
1091
1092 extern JSBool
1093 jsd_CreateAtomTable(JSDContext* jsdc);
1094
1095 extern void
1096 jsd_DestroyAtomTable(JSDContext* jsdc);
1097
1098 extern JSDAtom*
1099 jsd_AddAtom(JSDContext* jsdc, const char* str);
1100
1101 extern JSDAtom*
1102 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom);
1103
1104 extern void
1105 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom);
1106
1107 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str))
1108
1109 /***************************************************************************/
1110 /* Livewire specific API */
1111 #ifdef LIVEWIRE
1112
1113 extern LWDBGScript*
1114 jsdlw_GetLWScript(JSDContext* jsdc, JSDScript* jsdscript);
1115
1116 extern char*
1117 jsdlw_BuildAppRelativeFilename(LWDBGApp* app, const char* filename);
1118
1119 extern JSDSourceText*
1120 jsdlw_PreLoadSource(JSDContext* jsdc, LWDBGApp* app,
1121                      const char* filename, JSBool clear);
1122
1123 extern JSDSourceText*
1124 jsdlw_ForceLoadSource(JSDContext* jsdc, JSDSourceText* jsdsrc);
1125
1126 extern JSBool
1127 jsdlw_UserCodeAtPC(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
1128
1129 extern JSBool
1130 jsdlw_RawToProcessedLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1131                                uintN lineIn, uintN* lineOut);
1132
1133 extern JSBool
1134 jsdlw_ProcessedToRawLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1135                                uintN lineIn, uintN* lineOut);
1136
1137
1138 #if 0
1139 /* our hook proc for LiveWire app start/stop */
1140 extern void
1141 jsdlw_AppHookProc(LWDBGApp* app,
1142                   JSBool created,
1143                   void *callerdata);
1144 #endif
1145
1146
1147 #endif
1148 /***************************************************************************/
1149
1150 JS_END_EXTERN_C
1151
1152 #endif /* jsd_h___ */