Reserve standard class properties in global objects (bug 561923 part 1, r=brendan).
[mozilla-central.git] / js / jsd / jsd.h
blobc07112dbdce9cbe8d2f6856eb20a63c7a9126409
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 differently
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_DebuggerPause(JSDContext* jsdc, JSBool forceAllHooksOff);
353 extern void
354 jsd_DebuggerUnpause(JSDContext* jsdc);
356 extern void
357 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user);
359 extern JSDContext*
360 jsd_JSDContextForJSContext(JSContext* context);
362 extern void*
363 jsd_SetContextPrivate(JSDContext* jsdc, void *data);
365 extern void*
366 jsd_GetContextPrivate(JSDContext* jsdc);
368 extern void
369 jsd_ClearAllProfileData(JSDContext* jsdc);
371 extern JSBool
372 jsd_SetErrorReporter(JSDContext* jsdc,
373 JSD_ErrorReporter reporter,
374 void* callerdata);
376 extern JSBool
377 jsd_GetErrorReporter(JSDContext* jsdc,
378 JSD_ErrorReporter* reporter,
379 void** callerdata);
381 static JSBool
382 jsd_DebugErrorHook(JSContext *cx, const char *message,
383 JSErrorReport *report, void *closure);
385 /***************************************************************************/
386 /* Script functions */
388 extern JSBool
389 jsd_InitScriptManager(JSDContext *jsdc);
391 extern void
392 jsd_DestroyScriptManager(JSDContext* jsdc);
394 extern JSDScript*
395 jsd_FindJSDScript(JSDContext* jsdc,
396 JSScript *script);
398 extern JSDScript*
399 jsd_FindOrCreateJSDScript(JSDContext *jsdc,
400 JSContext *cx,
401 JSScript *script,
402 JSStackFrame *fp);
404 extern JSDProfileData*
405 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
407 extern uint32
408 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
410 extern void
411 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags);
413 extern uintN
414 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
416 extern uintN
417 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
419 extern jsdouble
420 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
422 extern jsdouble
423 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
425 extern jsdouble
426 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
428 extern jsdouble
429 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
431 extern jsdouble
432 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
434 extern jsdouble
435 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
437 extern void
438 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
440 extern JSScript *
441 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script);
443 extern JSFunction *
444 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script);
446 extern JSDScript*
447 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
449 extern void *
450 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data);
452 extern void *
453 jsd_GetScriptPrivate (JSDScript *jsdscript);
455 extern JSBool
456 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
458 extern const char*
459 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
461 extern const char*
462 jsd_GetScriptFunctionName(JSDContext* jsdc, JSDScript *jsdscript);
464 extern uintN
465 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
467 extern uintN
468 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
470 extern JSBool
471 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
473 extern JSBool
474 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
476 extern jsuword
477 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line);
479 extern uintN
480 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
482 extern void
483 jsd_NewScriptHookProc(
484 JSContext *cx,
485 const char *filename, /* URL this script loads from */
486 uintN lineno, /* line where this script starts */
487 JSScript *script,
488 JSFunction *fun,
489 void* callerdata);
491 extern void
492 jsd_DestroyScriptHookProc(
493 JSContext *cx,
494 JSScript *script,
495 void* callerdata);
497 /* Script execution hook functions */
499 extern JSBool
500 jsd_SetExecutionHook(JSDContext* jsdc,
501 JSDScript* jsdscript,
502 jsuword pc,
503 JSD_ExecutionHookProc hook,
504 void* callerdata);
506 extern JSBool
507 jsd_ClearExecutionHook(JSDContext* jsdc,
508 JSDScript* jsdscript,
509 jsuword pc);
511 extern JSBool
512 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
514 extern JSBool
515 jsd_ClearAllExecutionHooks(JSDContext* jsdc);
517 extern void
518 jsd_ScriptCreated(JSDContext* jsdc,
519 JSContext *cx,
520 const char *filename, /* URL this script loads from */
521 uintN lineno, /* line where this script starts */
522 JSScript *script,
523 JSFunction *fun);
525 extern void
526 jsd_ScriptDestroyed(JSDContext* jsdc,
527 JSContext *cx,
528 JSScript *script);
530 /***************************************************************************/
531 /* Source Text functions */
533 extern JSDSourceText*
534 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
536 extern JSDSourceText*
537 jsd_FindSourceForURL(JSDContext* jsdc, const char* url);
539 extern const char*
540 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
542 extern JSBool
543 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
544 const char** ppBuf, intN* pLen);
546 extern void
547 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
549 extern JSDSourceStatus
550 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
552 extern JSBool
553 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
555 extern void
556 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, JSBool dirty);
558 extern uintN
559 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
561 extern uintN
562 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
564 extern JSDSourceText*
565 jsd_NewSourceText(JSDContext* jsdc, const char* url);
567 extern JSDSourceText*
568 jsd_AppendSourceText(JSDContext* jsdc,
569 JSDSourceText* jsdsrc,
570 const char* text, /* *not* zero terminated */
571 size_t length,
572 JSDSourceStatus status);
574 extern JSDSourceText*
575 jsd_AppendUCSourceText(JSDContext* jsdc,
576 JSDSourceText* jsdsrc,
577 const jschar* text, /* *not* zero terminated */
578 size_t length,
579 JSDSourceStatus status);
581 /* convienence function for adding complete source of url in one call */
582 extern JSBool
583 jsd_AddFullSourceText(JSDContext* jsdc,
584 const char* text, /* *not* zero terminated */
585 size_t length,
586 const char* url);
588 extern void
589 jsd_DestroyAllSources(JSDContext* jsdc);
591 extern const char*
592 jsd_BuildNormalizedURL(const char* url_string);
594 extern void
595 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
597 extern void
598 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
600 /***************************************************************************/
601 /* Interrupt Hook functions */
603 extern JSBool
604 jsd_SetInterruptHook(JSDContext* jsdc,
605 JSD_ExecutionHookProc hook,
606 void* callerdata);
608 extern JSBool
609 jsd_ClearInterruptHook(JSDContext* jsdc);
611 extern JSBool
612 jsd_SetDebugBreakHook(JSDContext* jsdc,
613 JSD_ExecutionHookProc hook,
614 void* callerdata);
616 extern JSBool
617 jsd_ClearDebugBreakHook(JSDContext* jsdc);
619 extern JSBool
620 jsd_SetDebuggerHook(JSDContext* jsdc,
621 JSD_ExecutionHookProc hook,
622 void* callerdata);
624 extern JSBool
625 jsd_ClearDebuggerHook(JSDContext* jsdc);
627 extern JSTrapStatus
628 jsd_CallExecutionHook(JSDContext* jsdc,
629 JSContext* cx,
630 uintN type,
631 JSD_ExecutionHookProc hook,
632 void* hookData,
633 jsval* rval);
635 extern JSBool
636 jsd_CallCallHook (JSDContext* jsdc,
637 JSContext* cx,
638 uintN type,
639 JSD_CallHookProc hook,
640 void* hookData);
642 extern JSBool
643 jsd_SetThrowHook(JSDContext* jsdc,
644 JSD_ExecutionHookProc hook,
645 void* callerdata);
646 extern JSBool
647 jsd_ClearThrowHook(JSDContext* jsdc);
649 extern JSTrapStatus
650 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
651 jsval *rval, void *closure);
653 extern JSTrapStatus
654 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
655 jsval *rval, void *closure);
657 extern JSBool
658 jsd_SetFunctionHook(JSDContext* jsdc,
659 JSD_CallHookProc hook,
660 void* callerdata);
662 extern JSBool
663 jsd_ClearFunctionHook(JSDContext* jsdc);
665 extern JSBool
666 jsd_SetTopLevelHook(JSDContext* jsdc,
667 JSD_CallHookProc hook,
668 void* callerdata);
670 extern JSBool
671 jsd_ClearTopLevelHook(JSDContext* jsdc);
673 /***************************************************************************/
674 /* Stack Frame functions */
676 extern uintN
677 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
679 extern JSDStackFrameInfo*
680 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
682 extern JSContext*
683 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
685 extern JSDStackFrameInfo*
686 jsd_GetCallingStackFrame(JSDContext* jsdc,
687 JSDThreadState* jsdthreadstate,
688 JSDStackFrameInfo* jsdframe);
690 extern JSDScript*
691 jsd_GetScriptForStackFrame(JSDContext* jsdc,
692 JSDThreadState* jsdthreadstate,
693 JSDStackFrameInfo* jsdframe);
695 extern jsuword
696 jsd_GetPCForStackFrame(JSDContext* jsdc,
697 JSDThreadState* jsdthreadstate,
698 JSDStackFrameInfo* jsdframe);
700 extern JSDValue*
701 jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
702 JSDThreadState* jsdthreadstate,
703 JSDStackFrameInfo* jsdframe);
705 extern JSDValue*
706 jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
707 JSDThreadState* jsdthreadstate,
708 JSDStackFrameInfo* jsdframe);
710 extern JSBool
711 jsd_IsStackFrameNative(JSDContext* jsdc,
712 JSDThreadState* jsdthreadstate,
713 JSDStackFrameInfo* jsdframe);
715 extern JSBool
716 jsd_IsStackFrameDebugger(JSDContext* jsdc,
717 JSDThreadState* jsdthreadstate,
718 JSDStackFrameInfo* jsdframe);
720 extern JSBool
721 jsd_IsStackFrameConstructing(JSDContext* jsdc,
722 JSDThreadState* jsdthreadstate,
723 JSDStackFrameInfo* jsdframe);
725 extern JSDValue*
726 jsd_GetThisForStackFrame(JSDContext* jsdc,
727 JSDThreadState* jsdthreadstate,
728 JSDStackFrameInfo* jsdframe);
730 extern const char*
731 jsd_GetNameForStackFrame(JSDContext* jsdc,
732 JSDThreadState* jsdthreadstate,
733 JSDStackFrameInfo* jsdframe);
735 extern JSDThreadState*
736 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx);
738 extern void
739 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
741 extern JSBool
742 jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
743 JSDThreadState* jsdthreadstate,
744 JSDStackFrameInfo* jsdframe,
745 const jschar *bytes, uintN length,
746 const char *filename, uintN lineno,
747 JSBool eatExceptions, jsval *rval);
749 extern JSBool
750 jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
751 JSDThreadState* jsdthreadstate,
752 JSDStackFrameInfo* jsdframe,
753 const char *bytes, uintN length,
754 const char *filename, uintN lineno,
755 JSBool eatExceptions, jsval *rval);
757 extern JSString*
758 jsd_ValToStringInStackFrame(JSDContext* jsdc,
759 JSDThreadState* jsdthreadstate,
760 JSDStackFrameInfo* jsdframe,
761 jsval val);
763 extern JSBool
764 jsd_IsValidThreadState(JSDContext* jsdc,
765 JSDThreadState* jsdthreadstate);
767 extern JSBool
768 jsd_IsValidFrameInThreadState(JSDContext* jsdc,
769 JSDThreadState* jsdthreadstate,
770 JSDStackFrameInfo* jsdframe);
772 extern JSDValue*
773 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
775 extern JSBool
776 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate,
777 JSDValue* jsdval);
779 /***************************************************************************/
780 /* Locking support */
782 /* protos are in js_lock.h for:
783 * jsd_CreateLock
784 * jsd_Lock
785 * jsd_Unlock
786 * jsd_IsLocked
787 * jsd_CurrentThread
790 #ifdef JSD_THREADSAFE
792 /* the system-wide lock */
793 extern void* _jsd_global_lock;
794 #define JSD_LOCK() \
795 JS_BEGIN_MACRO \
796 if(!_jsd_global_lock) \
797 _jsd_global_lock = jsd_CreateLock(); \
798 JS_ASSERT(_jsd_global_lock); \
799 jsd_Lock(_jsd_global_lock); \
800 JS_END_MACRO
802 #define JSD_UNLOCK() \
803 JS_BEGIN_MACRO \
804 JS_ASSERT(_jsd_global_lock); \
805 jsd_Unlock(_jsd_global_lock); \
806 JS_END_MACRO
808 /* locks for the subsystems of a given context */
809 #define JSD_INIT_LOCKS(jsdc) \
810 ( (NULL != (jsdc->scriptsLock = jsd_CreateLock())) && \
811 (NULL != (jsdc->sourceTextLock = jsd_CreateLock())) && \
812 (NULL != (jsdc->atomsLock = jsd_CreateLock())) && \
813 (NULL != (jsdc->objectsLock = jsd_CreateLock())) && \
814 (NULL != (jsdc->threadStatesLock = jsd_CreateLock())) )
816 #define JSD_LOCK_SCRIPTS(jsdc) jsd_Lock(jsdc->scriptsLock)
817 #define JSD_UNLOCK_SCRIPTS(jsdc) jsd_Unlock(jsdc->scriptsLock)
819 #define JSD_LOCK_SOURCE_TEXT(jsdc) jsd_Lock(jsdc->sourceTextLock)
820 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) jsd_Unlock(jsdc->sourceTextLock)
822 #define JSD_LOCK_ATOMS(jsdc) jsd_Lock(jsdc->atomsLock)
823 #define JSD_UNLOCK_ATOMS(jsdc) jsd_Unlock(jsdc->atomsLock)
825 #define JSD_LOCK_OBJECTS(jsdc) jsd_Lock(jsdc->objectsLock)
826 #define JSD_UNLOCK_OBJECTS(jsdc) jsd_Unlock(jsdc->objectsLock)
828 #define JSD_LOCK_THREADSTATES(jsdc) jsd_Lock(jsdc->threadStatesLock)
829 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock)
831 #else /* !JSD_THREADSAFE */
833 #define JSD_LOCK() ((void)0)
834 #define JSD_UNLOCK() ((void)0)
836 #define JSD_INIT_LOCKS(jsdc) 1
838 #define JSD_LOCK_SCRIPTS(jsdc) ((void)0)
839 #define JSD_UNLOCK_SCRIPTS(jsdc) ((void)0)
841 #define JSD_LOCK_SOURCE_TEXT(jsdc) ((void)0)
842 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) ((void)0)
844 #define JSD_LOCK_ATOMS(jsdc) ((void)0)
845 #define JSD_UNLOCK_ATOMS(jsdc) ((void)0)
847 #define JSD_LOCK_OBJECTS(jsdc) ((void)0)
848 #define JSD_UNLOCK_OBJECTS(jsdc) ((void)0)
850 #define JSD_LOCK_THREADSTATES(jsdc) ((void)0)
851 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0)
853 #endif /* JSD_THREADSAFE */
855 /* NOTE: These are intended for ASSERTs. Thus we supply checks for both
856 * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in
857 * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds
858 * without having to special case things in the code.
860 #if defined(JSD_THREADSAFE) && defined(DEBUG)
861 #define JSD_SCRIPTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->scriptsLock))
862 #define JSD_SOURCE_TEXT_LOCKED(jsdc) (jsd_IsLocked(jsdc->sourceTextLock))
863 #define JSD_ATOMS_LOCKED(jsdc) (jsd_IsLocked(jsdc->atomsLock))
864 #define JSD_OBJECTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->objectsLock))
865 #define JSD_THREADSTATES_LOCKED(jsdc) (jsd_IsLocked(jsdc->threadStatesLock))
866 #define JSD_SCRIPTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->scriptsLock))
867 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->sourceTextLock))
868 #define JSD_ATOMS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->atomsLock))
869 #define JSD_OBJECTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->objectsLock))
870 #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock))
871 #else
872 #define JSD_SCRIPTS_LOCKED(jsdc) 1
873 #define JSD_SOURCE_TEXT_LOCKED(jsdc) 1
874 #define JSD_ATOMS_LOCKED(jsdc) 1
875 #define JSD_OBJECTS_LOCKED(jsdc) 1
876 #define JSD_THREADSTATES_LOCKED(jsdc) 1
877 #define JSD_SCRIPTS_UNLOCKED(jsdc) 1
878 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) 1
879 #define JSD_ATOMS_UNLOCKED(jsdc) 1
880 #define JSD_OBJECTS_UNLOCKED(jsdc) 1
881 #define JSD_THREADSTATES_UNLOCKED(jsdc) 1
882 #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */
884 /***************************************************************************/
885 /* Threading support */
887 #ifdef JSD_THREADSAFE
889 #define JSD_CURRENT_THREAD() jsd_CurrentThread()
891 #else /* !JSD_THREADSAFE */
893 #define JSD_CURRENT_THREAD() ((void*)0)
895 #endif /* JSD_THREADSAFE */
897 /***************************************************************************/
898 /* Dangerous thread support */
900 #ifdef JSD_HAS_DANGEROUS_THREAD
902 #define JSD_IS_DANGEROUS_THREAD(jsdc) \
903 (JSD_CURRENT_THREAD() == jsdc->dangerousThread)
905 #else /* !JSD_HAS_DANGEROUS_THREAD */
907 #define JSD_IS_DANGEROUS_THREAD(jsdc) 0
909 #endif /* JSD_HAS_DANGEROUS_THREAD */
911 /***************************************************************************/
912 /* Value and Property Functions */
914 extern JSDValue*
915 jsd_NewValue(JSDContext* jsdc, jsval val);
917 extern void
918 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval);
920 extern jsval
921 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
923 extern void
924 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
926 /**************************************************/
928 extern JSBool
929 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
931 extern JSBool
932 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
934 extern JSBool
935 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
937 extern JSBool
938 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
940 extern JSBool
941 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
943 extern JSBool
944 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
946 extern JSBool
947 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
949 extern JSBool
950 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
952 extern JSBool
953 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
955 extern JSBool
956 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
958 extern JSBool
959 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
961 /**************************************************/
963 extern JSBool
964 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
966 extern int32
967 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
969 extern jsdouble*
970 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
972 extern JSString*
973 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
975 extern const char*
976 jsd_GetValueFunctionName(JSDContext* jsdc, JSDValue* jsdval);
978 /**************************************************/
980 extern uintN
981 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
983 extern JSDProperty*
984 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
986 extern JSDProperty*
987 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
989 extern JSDValue*
990 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
992 extern JSDValue*
993 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
995 extern JSDValue*
996 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
998 extern const char*
999 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
1001 extern JSDScript*
1002 jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval);
1004 /**************************************************/
1006 extern void
1007 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
1009 extern JSDValue*
1010 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
1012 extern JSDValue*
1013 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
1015 extern JSDValue*
1016 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
1018 extern uintN
1019 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
1021 extern uintN
1022 jsd_GetPropertyVarArgSlot(JSDContext* jsdc, JSDProperty* jsdprop);
1024 /**************************************************/
1025 /* Stepping Functions */
1027 extern void *
1028 jsd_FunctionCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1029 JSBool *ok, void *closure);
1031 extern void *
1032 jsd_TopLevelCallHook(JSContext *cx, JSStackFrame *fp, JSBool before,
1033 JSBool *ok, void *closure);
1035 /**************************************************/
1036 /* Object Functions */
1038 extern JSBool
1039 jsd_InitObjectManager(JSDContext* jsdc);
1041 extern void
1042 jsd_DestroyObjectManager(JSDContext* jsdc);
1044 extern void
1045 jsd_DestroyObjects(JSDContext* jsdc);
1047 extern void
1048 jsd_ObjectHook(JSContext *cx, JSObject *obj, JSBool isNew, void *closure);
1050 extern void
1051 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
1052 JSStackFrame *fp);
1054 extern JSDObject*
1055 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
1057 extern JSObject*
1058 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
1060 extern const char*
1061 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
1063 extern uintN
1064 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1066 extern const char*
1067 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
1069 extern uintN
1070 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1072 extern const char*
1073 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
1075 extern JSDObject*
1076 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
1078 extern JSDObject*
1079 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
1082 * returns new refcounted JSDValue
1084 extern JSDValue*
1085 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
1087 /**************************************************/
1088 /* Atom Functions */
1090 extern JSBool
1091 jsd_CreateAtomTable(JSDContext* jsdc);
1093 extern void
1094 jsd_DestroyAtomTable(JSDContext* jsdc);
1096 extern JSDAtom*
1097 jsd_AddAtom(JSDContext* jsdc, const char* str);
1099 extern JSDAtom*
1100 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom);
1102 extern void
1103 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom);
1105 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str))
1107 /***************************************************************************/
1108 /* Livewire specific API */
1109 #ifdef LIVEWIRE
1111 extern LWDBGScript*
1112 jsdlw_GetLWScript(JSDContext* jsdc, JSDScript* jsdscript);
1114 extern char*
1115 jsdlw_BuildAppRelativeFilename(LWDBGApp* app, const char* filename);
1117 extern JSDSourceText*
1118 jsdlw_PreLoadSource(JSDContext* jsdc, LWDBGApp* app,
1119 const char* filename, JSBool clear);
1121 extern JSDSourceText*
1122 jsdlw_ForceLoadSource(JSDContext* jsdc, JSDSourceText* jsdsrc);
1124 extern JSBool
1125 jsdlw_UserCodeAtPC(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc);
1127 extern JSBool
1128 jsdlw_RawToProcessedLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1129 uintN lineIn, uintN* lineOut);
1131 extern JSBool
1132 jsdlw_ProcessedToRawLineNumber(JSDContext* jsdc, JSDScript* jsdscript,
1133 uintN lineIn, uintN* lineOut);
1136 #if 0
1137 /* our hook proc for LiveWire app start/stop */
1138 extern void
1139 jsdlw_AppHookProc(LWDBGApp* app,
1140 JSBool created,
1141 void *callerdata);
1142 #endif
1145 #endif
1146 /***************************************************************************/
1148 JS_END_EXTERN_C
1150 #endif /* jsd_h___ */