Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / js / jsd / jsd.h
blobf6720c373782fb28765a4aa1ece12a8ce0c5e6aa
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
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/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
39 * Header for JavaScript Debugging support - Internal ONLY declarations
42 #ifndef jsd_h___
43 #define jsd_h___
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.
50 #define EXPORT_JSD_API 1 /* if used, must be set before include of jsdebug.h */
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 differnetly
55 * in other embeddings.
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 */
64 /* Get jstypes.h included first. After that we can use PR macros for doing
65 * this extern "C" stuff!
67 #ifdef __cplusplus
68 extern "C"
70 #endif
71 #include "jstypes.h"
72 #ifdef __cplusplus
74 #endif
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"
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
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
98 JS_BEGIN_EXTERN_C
100 #define JSD_MAJOR_VERSION 1
101 #define JSD_MINOR_VERSION 1
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)))
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))))
121 /***************************************************************************/
122 /* These are not exposed in jsdebug.h - typedef here for consistency */
124 typedef struct JSDExecHook JSDExecHook;
125 typedef struct JSDAtom JSDAtom;
126 typedef struct JSDProfileData JSDProfileData;
127 /***************************************************************************/
128 /* Our structures */
131 * XXX What I'm calling a JSDContext is really more of a JSDTaskState.
134 struct JSDContext
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 */
185 struct JSDScript
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;
198 JSDProfileData *profileData;
200 #ifdef LIVEWIRE
201 LWDBGApp* app;
202 LWDBGScript* lwscript;
203 #endif
206 struct JSDProfileData
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;
222 struct JSDSourceText
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;
235 struct JSDExecHook
237 JSCList links; /* we are part of a JSCList */
238 JSDScript* jsdscript;
239 jsuword pc;
240 JSD_ExecutionHookProc hook;
241 void* callerdata;
244 #define TS_HAS_DISABLED_FRAME 0x01
246 struct JSDThreadState
248 JSCList links; /* we are part of a JSCList */
249 JSContext* context;
250 void* thread;
251 JSCList stack;
252 uintN stackDepth;
253 uintN flags;
256 struct JSDStackFrameInfo
258 JSCList links; /* we are part of a JSCList */
259 JSDThreadState* jsdthreadstate;
260 JSDScript* jsdscript;
261 jsuword pc;
262 JSStackFrame* fp;
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))
270 struct JSDValue
272 jsval val;
273 intN nref;
274 JSCList props;
275 JSString* string;
276 const char* funName;
277 const char* className;
278 JSDValue* proto;
279 JSDValue* parent;
280 JSDValue* ctor;
281 uintN flags;
284 struct JSDProperty
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;
295 struct JSDAtom
297 char* str; /* must be first element in struct for compare */
298 intN refcount;
301 struct JSDObject
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;
312 /***************************************************************************/
313 /* Code validation support */
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
337 /***************************************************************************/
338 /* higher level functions */
340 extern JSDContext*
341 jsd_DebuggerOnForUser(JSRuntime* jsrt,
342 JSD_UserCallbacks* callbacks,
343 void* user);
344 extern JSDContext*
345 jsd_DebuggerOn(void);
347 extern void
348 jsd_DebuggerOff(JSDContext* jsdc);
350 extern void
351 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user);
353 extern JSDContext*
354 jsd_JSDContextForJSContext(JSContext* context);
356 extern void*
357 jsd_SetContextPrivate(JSDContext* jsdc, void *data);
359 extern void*
360 jsd_GetContextPrivate(JSDContext* jsdc);
362 extern void
363 jsd_ClearAllProfileData(JSDContext* jsdc);
365 extern JSBool
366 jsd_SetErrorReporter(JSDContext* jsdc,
367 JSD_ErrorReporter reporter,
368 void* callerdata);
370 extern JSBool
371 jsd_GetErrorReporter(JSDContext* jsdc,
372 JSD_ErrorReporter* reporter,
373 void** callerdata);
375 JS_STATIC_DLL_CALLBACK(JSBool)
376 jsd_DebugErrorHook(JSContext *cx, const char *message,
377 JSErrorReport *report, void *closure);
379 /***************************************************************************/
380 /* Script functions */
382 extern JSBool
383 jsd_InitScriptManager(JSDContext *jsdc);
385 extern void
386 jsd_DestroyScriptManager(JSDContext* jsdc);
388 extern JSDScript*
389 jsd_FindJSDScript(JSDContext* jsdc,
390 JSScript *script);
392 extern JSDProfileData*
393 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
395 extern uint32
396 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
398 extern void
399 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags);
401 extern uintN
402 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
404 extern uintN
405 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
407 extern jsdouble
408 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
410 extern jsdouble
411 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
413 extern jsdouble
414 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
416 extern jsdouble
417 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
419 extern jsdouble
420 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
422 extern jsdouble
423 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
425 extern void
426 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
428 extern JSScript *
429 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script);
431 extern JSFunction *
432 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script);
434 extern JSDScript*
435 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
437 extern void *
438 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data);
440 extern void *
441 jsd_GetScriptPrivate (JSDScript *jsdscript);
443 extern JSBool
444 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
446 extern const char*
447 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
449 extern const char*
450 jsd_GetScriptFunctionName(JSDContext* jsdc, JSDScript *jsdscript);
452 extern uintN
453 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
455 extern uintN
456 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
458 extern JSBool
459 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
461 extern JSBool
462 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
464 extern jsuword
465 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line);
467 extern uintN
468 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
470 extern void JS_DLL_CALLBACK
471 jsd_NewScriptHookProc(
472 JSContext *cx,
473 const char *filename, /* URL this script loads from */
474 uintN lineno, /* line where this script starts */
475 JSScript *script,
476 JSFunction *fun,
477 void* callerdata);
479 extern void JS_DLL_CALLBACK
480 jsd_DestroyScriptHookProc(
481 JSContext *cx,
482 JSScript *script,
483 void* callerdata);
485 /* Script execution hook functions */
487 extern JSBool
488 jsd_SetExecutionHook(JSDContext* jsdc,
489 JSDScript* jsdscript,
490 jsuword pc,
491 JSD_ExecutionHookProc hook,
492 void* callerdata);
494 extern JSBool
495 jsd_ClearExecutionHook(JSDContext* jsdc,
496 JSDScript* jsdscript,
497 jsuword pc);
499 extern JSBool
500 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
502 extern JSBool
503 jsd_ClearAllExecutionHooks(JSDContext* jsdc);
505 extern void
506 jsd_ScriptCreated(JSDContext* jsdc,
507 JSContext *cx,
508 const char *filename, /* URL this script loads from */
509 uintN lineno, /* line where this script starts */
510 JSScript *script,
511 JSFunction *fun);
513 extern void
514 jsd_ScriptDestroyed(JSDContext* jsdc,
515 JSContext *cx,
516 JSScript *script);
518 /***************************************************************************/
519 /* Source Text functions */
521 extern JSDSourceText*
522 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
524 extern JSDSourceText*
525 jsd_FindSourceForURL(JSDContext* jsdc, const char* url);
527 extern const char*
528 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
530 extern JSBool
531 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
532 const char** ppBuf, intN* pLen);
534 extern void
535 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
537 extern JSDSourceStatus
538 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
540 extern JSBool
541 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
543 extern void
544 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, JSBool dirty);
546 extern uintN
547 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
549 extern uintN
550 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
552 extern JSDSourceText*
553 jsd_NewSourceText(JSDContext* jsdc, const char* url);
555 extern JSDSourceText*
556 jsd_AppendSourceText(JSDContext* jsdc,
557 JSDSourceText* jsdsrc,
558 const char* text, /* *not* zero terminated */
559 size_t length,
560 JSDSourceStatus status);
562 extern JSDSourceText*
563 jsd_AppendUCSourceText(JSDContext* jsdc,
564 JSDSourceText* jsdsrc,
565 const jschar* text, /* *not* zero terminated */
566 size_t length,
567 JSDSourceStatus status);
569 /* convienence function for adding complete source of url in one call */
570 extern JSBool
571 jsd_AddFullSourceText(JSDContext* jsdc,
572 const char* text, /* *not* zero terminated */
573 size_t length,
574 const char* url);
576 extern void
577 jsd_DestroyAllSources(JSDContext* jsdc);
579 extern const char*
580 jsd_BuildNormalizedURL(const char* url_string);
582 extern void
583 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
585 extern void
586 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
588 /***************************************************************************/
589 /* Interrupt Hook functions */
591 extern JSBool
592 jsd_SetInterruptHook(JSDContext* jsdc,
593 JSD_ExecutionHookProc hook,
594 void* callerdata);
596 extern JSBool
597 jsd_ClearInterruptHook(JSDContext* jsdc);
599 extern JSBool
600 jsd_SetDebugBreakHook(JSDContext* jsdc,
601 JSD_ExecutionHookProc hook,
602 void* callerdata);
604 extern JSBool
605 jsd_ClearDebugBreakHook(JSDContext* jsdc);
607 extern JSBool
608 jsd_SetDebuggerHook(JSDContext* jsdc,
609 JSD_ExecutionHookProc hook,
610 void* callerdata);
612 extern JSBool
613 jsd_ClearDebuggerHook(JSDContext* jsdc);
615 extern JSTrapStatus
616 jsd_CallExecutionHook(JSDContext* jsdc,
617 JSContext* cx,
618 uintN type,
619 JSD_ExecutionHookProc hook,
620 void* hookData,
621 jsval* rval);
623 extern JSBool
624 jsd_CallCallHook (JSDContext* jsdc,
625 JSContext* cx,
626 uintN type,
627 JSD_CallHookProc hook,
628 void* hookData);
630 extern JSBool
631 jsd_SetThrowHook(JSDContext* jsdc,
632 JSD_ExecutionHookProc hook,
633 void* callerdata);
634 extern JSBool
635 jsd_ClearThrowHook(JSDContext* jsdc);
637 extern JSTrapStatus JS_DLL_CALLBACK
638 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
639 jsval *rval, void *closure);
641 extern JSTrapStatus JS_DLL_CALLBACK
642 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
643 jsval *rval, void *closure);
645 extern JSBool
646 jsd_SetFunctionHook(JSDContext* jsdc,
647 JSD_CallHookProc hook,
648 void* callerdata);
650 extern JSBool
651 jsd_ClearFunctionHook(JSDContext* jsdc);
653 extern JSBool
654 jsd_SetTopLevelHook(JSDContext* jsdc,
655 JSD_CallHookProc hook,
656 void* callerdata);
658 extern JSBool
659 jsd_ClearTopLevelHook(JSDContext* jsdc);
661 /***************************************************************************/
662 /* Stack Frame functions */
664 extern uintN
665 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
667 extern JSDStackFrameInfo*
668 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
670 extern JSContext*
671 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
673 extern JSDStackFrameInfo*
674 jsd_GetCallingStackFrame(JSDContext* jsdc,
675 JSDThreadState* jsdthreadstate,
676 JSDStackFrameInfo* jsdframe);
678 extern JSDScript*
679 jsd_GetScriptForStackFrame(JSDContext* jsdc,
680 JSDThreadState* jsdthreadstate,
681 JSDStackFrameInfo* jsdframe);
683 extern jsuword
684 jsd_GetPCForStackFrame(JSDContext* jsdc,
685 JSDThreadState* jsdthreadstate,
686 JSDStackFrameInfo* jsdframe);
688 extern JSDValue*
689 jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
690 JSDThreadState* jsdthreadstate,
691 JSDStackFrameInfo* jsdframe);
693 extern JSDValue*
694 jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
695 JSDThreadState* jsdthreadstate,
696 JSDStackFrameInfo* jsdframe);
698 extern JSBool
699 jsd_IsStackFrameNative(JSDContext* jsdc,
700 JSDThreadState* jsdthreadstate,
701 JSDStackFrameInfo* jsdframe);
703 extern JSBool
704 jsd_IsStackFrameDebugger(JSDContext* jsdc,
705 JSDThreadState* jsdthreadstate,
706 JSDStackFrameInfo* jsdframe);
708 extern JSBool
709 jsd_IsStackFrameConstructing(JSDContext* jsdc,
710 JSDThreadState* jsdthreadstate,
711 JSDStackFrameInfo* jsdframe);
713 extern JSDValue*
714 jsd_GetThisForStackFrame(JSDContext* jsdc,
715 JSDThreadState* jsdthreadstate,
716 JSDStackFrameInfo* jsdframe);
718 extern const char*
719 jsd_GetNameForStackFrame(JSDContext* jsdc,
720 JSDThreadState* jsdthreadstate,
721 JSDStackFrameInfo* jsdframe);
723 extern JSDThreadState*
724 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx);
726 extern void
727 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
729 extern JSBool
730 jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
731 JSDThreadState* jsdthreadstate,
732 JSDStackFrameInfo* jsdframe,
733 const jschar *bytes, uintN length,
734 const char *filename, uintN lineno,
735 JSBool eatExceptions, jsval *rval);
737 extern JSBool
738 jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
739 JSDThreadState* jsdthreadstate,
740 JSDStackFrameInfo* jsdframe,
741 const char *bytes, uintN length,
742 const char *filename, uintN lineno,
743 JSBool eatExceptions, jsval *rval);
745 extern JSString*
746 jsd_ValToStringInStackFrame(JSDContext* jsdc,
747 JSDThreadState* jsdthreadstate,
748 JSDStackFrameInfo* jsdframe,
749 jsval val);
751 extern JSBool
752 jsd_IsValidThreadState(JSDContext* jsdc,
753 JSDThreadState* jsdthreadstate);
755 extern JSBool
756 jsd_IsValidFrameInThreadState(JSDContext* jsdc,
757 JSDThreadState* jsdthreadstate,
758 JSDStackFrameInfo* jsdframe);
760 extern JSDValue*
761 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
763 extern JSBool
764 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate,
765 JSDValue* jsdval);
767 /***************************************************************************/
768 /* Locking support */
770 /* protos are in js_lock.h for:
771 * jsd_CreateLock
772 * jsd_Lock
773 * jsd_Unlock
774 * jsd_IsLocked
775 * jsd_CurrentThread
778 #ifdef JSD_THREADSAFE
780 /* the system-wide lock */
781 extern void* _jsd_global_lock;
782 #define JSD_LOCK() \
783 JS_BEGIN_MACRO \
784 if(!_jsd_global_lock) \
785 _jsd_global_lock = jsd_CreateLock(); \
786 JS_ASSERT(_jsd_global_lock); \
787 jsd_Lock(_jsd_global_lock); \
788 JS_END_MACRO
790 #define JSD_UNLOCK() \
791 JS_BEGIN_MACRO \
792 JS_ASSERT(_jsd_global_lock); \
793 jsd_Unlock(_jsd_global_lock); \
794 JS_END_MACRO
796 /* locks for the subsystems of a given context */
797 #define JSD_INIT_LOCKS(jsdc) \
798 ( (NULL != (jsdc->scriptsLock = jsd_CreateLock())) && \
799 (NULL != (jsdc->sourceTextLock = jsd_CreateLock())) && \
800 (NULL != (jsdc->atomsLock = jsd_CreateLock())) && \
801 (NULL != (jsdc->objectsLock = jsd_CreateLock())) && \
802 (NULL != (jsdc->threadStatesLock = jsd_CreateLock())) )
804 #define JSD_LOCK_SCRIPTS(jsdc) jsd_Lock(jsdc->scriptsLock)
805 #define JSD_UNLOCK_SCRIPTS(jsdc) jsd_Unlock(jsdc->scriptsLock)
807 #define JSD_LOCK_SOURCE_TEXT(jsdc) jsd_Lock(jsdc->sourceTextLock)
808 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) jsd_Unlock(jsdc->sourceTextLock)
810 #define JSD_LOCK_ATOMS(jsdc) jsd_Lock(jsdc->atomsLock)
811 #define JSD_UNLOCK_ATOMS(jsdc) jsd_Unlock(jsdc->atomsLock)
813 #define JSD_LOCK_OBJECTS(jsdc) jsd_Lock(jsdc->objectsLock)
814 #define JSD_UNLOCK_OBJECTS(jsdc) jsd_Unlock(jsdc->objectsLock)
816 #define JSD_LOCK_THREADSTATES(jsdc) jsd_Lock(jsdc->threadStatesLock)
817 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock)
819 #else /* !JSD_THREADSAFE */
821 #define JSD_LOCK() ((void)0)
822 #define JSD_UNLOCK() ((void)0)
824 #define JSD_INIT_LOCKS(jsdc) 1
826 #define JSD_LOCK_SCRIPTS(jsdc) ((void)0)
827 #define JSD_UNLOCK_SCRIPTS(jsdc) ((void)0)
829 #define JSD_LOCK_SOURCE_TEXT(jsdc) ((void)0)
830 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) ((void)0)
832 #define JSD_LOCK_ATOMS(jsdc) ((void)0)
833 #define JSD_UNLOCK_ATOMS(jsdc) ((void)0)
835 #define JSD_LOCK_OBJECTS(jsdc) ((void)0)
836 #define JSD_UNLOCK_OBJECTS(jsdc) ((void)0)
838 #define JSD_LOCK_THREADSTATES(jsdc) ((void)0)
839 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0)
841 #endif /* JSD_THREADSAFE */
843 /* NOTE: These are intended for ASSERTs. Thus we supply checks for both
844 * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in
845 * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds
846 * without having to special case things in the code.
848 #if defined(JSD_THREADSAFE) && defined(DEBUG)
849 #define JSD_SCRIPTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->scriptsLock))
850 #define JSD_SOURCE_TEXT_LOCKED(jsdc) (jsd_IsLocked(jsdc->sourceTextLock))
851 #define JSD_ATOMS_LOCKED(jsdc) (jsd_IsLocked(jsdc->atomsLock))
852 #define JSD_OBJECTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->objectsLock))
853 #define JSD_THREADSTATES_LOCKED(jsdc) (jsd_IsLocked(jsdc->threadStatesLock))
854 #define JSD_SCRIPTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->scriptsLock))
855 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->sourceTextLock))
856 #define JSD_ATOMS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->atomsLock))
857 #define JSD_OBJECTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->objectsLock))
858 #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock))
859 #else
860 #define JSD_SCRIPTS_LOCKED(jsdc) 1
861 #define JSD_SOURCE_TEXT_LOCKED(jsdc) 1
862 #define JSD_ATOMS_LOCKED(jsdc) 1
863 #define JSD_OBJECTS_LOCKED(jsdc) 1
864 #define JSD_THREADSTATES_LOCKED(jsdc) 1
865 #define JSD_SCRIPTS_UNLOCKED(jsdc) 1
866 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) 1
867 #define JSD_ATOMS_UNLOCKED(jsdc) 1
868 #define JSD_OBJECTS_UNLOCKED(jsdc) 1
869 #define JSD_THREADSTATES_UNLOCKED(jsdc) 1
870 #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */
872 /***************************************************************************/
873 /* Threading support */
875 #ifdef JSD_THREADSAFE
877 #define JSD_CURRENT_THREAD() jsd_CurrentThread()
879 #else /* !JSD_THREADSAFE */
881 #define JSD_CURRENT_THREAD() ((void*)0)
883 #endif /* JSD_THREADSAFE */
885 /***************************************************************************/
886 /* Dangerous thread support */
888 #ifdef JSD_HAS_DANGEROUS_THREAD
890 #define JSD_IS_DANGEROUS_THREAD(jsdc) \
891 (JSD_CURRENT_THREAD() == jsdc->dangerousThread)
893 #else /* !JSD_HAS_DANGEROUS_THREAD */
895 #define JSD_IS_DANGEROUS_THREAD(jsdc) 0
897 #endif /* JSD_HAS_DANGEROUS_THREAD */
899 /***************************************************************************/
900 /* Value and Property Functions */
902 extern JSDValue*
903 jsd_NewValue(JSDContext* jsdc, jsval val);
905 extern void
906 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval);
908 extern jsval
909 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
911 extern void
912 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
914 /**************************************************/
916 extern JSBool
917 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
919 extern JSBool
920 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
922 extern JSBool
923 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
925 extern JSBool
926 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
928 extern JSBool
929 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
931 extern JSBool
932 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
934 extern JSBool
935 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
937 extern JSBool
938 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
940 extern JSBool
941 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
943 extern JSBool
944 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
946 extern JSBool
947 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
949 /**************************************************/
951 extern JSBool
952 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
954 extern int32
955 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
957 extern jsdouble*
958 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
960 extern JSString*
961 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
963 extern const char*
964 jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval);
966 /**************************************************/
968 extern uintN
969 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
971 extern JSDProperty*
972 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
974 extern JSDProperty*
975 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
977 extern JSDValue*
978 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
980 extern JSDValue*
981 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
983 extern JSDValue*
984 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
986 extern const char*
987 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
989 /**************************************************/
991 extern void
992 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
994 extern JSDValue*
995 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
997 extern JSDValue*
998 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
1000 extern JSDValue*
1001 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
1003 extern uintN
1004 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
1006 extern uintN
1007 jsd_GetPropertyVarArgSlot(JSDContext* jsdc, JSDProperty* jsdprop);
1009 /**************************************************/
1010 /* Stepping Functions */
1012 extern void * JS_DLL_CALLBACK
1013 jsd_FunctionCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1014 JSBool *ok, void *closure);
1016 extern void * JS_DLL_CALLBACK
1017 jsd_TopLevelCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1018 JSBool *ok, void *closure);
1020 /**************************************************/
1021 /* Object Functions */
1023 extern JSBool
1024 jsd_InitObjectManager(JSDContext* jsdc);
1026 extern void
1027 jsd_DestroyObjectManager(JSDContext* jsdc);
1029 extern void JS_DLL_CALLBACK
1030 jsd_ObjectHook(JSContext *cx, JSObject *obj, JSBool isNew, void *closure);
1032 extern void
1033 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
1034 JSStackFrame *fp);
1036 extern JSDObject*
1037 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
1039 extern JSObject*
1040 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
1042 extern const char*
1043 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
1045 extern uintN
1046 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1048 extern const char*
1049 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
1051 extern uintN
1052 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1054 extern const char*
1055 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
1057 extern JSDObject*
1058 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
1060 extern JSDObject*
1061 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
1064 * returns new refcounted JSDValue
1066 extern JSDValue*
1067 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
1069 /**************************************************/
1070 /* Atom Functions */
1072 extern JSBool
1073 jsd_CreateAtomTable(JSDContext* jsdc);
1075 extern void
1076 jsd_DestroyAtomTable(JSDContext* jsdc);
1078 extern JSDAtom*
1079 jsd_AddAtom(JSDContext* jsdc, const char* str);
1081 extern JSDAtom*
1082 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom);
1084 extern void
1085 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom);
1087 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str))
1089 /***************************************************************************/
1090 /* Livewire specific API */
1091 #ifdef LIVEWIRE
1093 extern LWDBGScript*
1094 jsdlw_GetLWScript(JSDContext* jsdc, JSDScript* jsdscript);
1096 extern char*
1097 jsdlw_BuildAppRelativeFilename(LWDBGApp* app, const char* filename);
1099 extern JSDSourceText*
1100 jsdlw_PreLoadSource(JSDContext* jsdc, LWDBGApp* app,
1101 const char* filename, JSBool clear);
1103 extern JSDSourceText*
1104 jsdlw_ForceLoadSource(JSDContext* jsdc, JSDSourceText* jsdsrc);
1106 extern JSBool
1107 jsdlw_UserCodeAtPC(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
1109 extern JSBool
1110 jsdlw_RawToProcessedLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1111 uintN lineIn, uintN* lineOut);
1113 extern JSBool
1114 jsdlw_ProcessedToRawLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1115 uintN lineIn, uintN* lineOut);
1118 #if 0
1119 /* our hook proc for LiveWire app start/stop */
1120 extern void JS_DLL_CALLBACK
1121 jsdlw_AppHookProc(LWDBGApp* app,
1122 JSBool created,
1123 void *callerdata);
1124 #endif
1127 #endif
1128 /***************************************************************************/
1130 JS_END_EXTERN_C
1132 #endif /* jsd_h___ */