Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Header for JavaScript Debugging support - Internal ONLY declarations
9 */
11 #ifndef jsd_h___
12 #define jsd_h___
14 /*
15 * NOTE: This is a *private* header file and should only be included by
16 * the sources in js/jsd. Defining EXPORT_JSD_API in an outside module
17 * using jsd would be bad.
18 */
19 #define EXPORT_JSD_API 1 /* if used, must be set before include of jsdebug.h */
21 /*
22 * These can be controled by the makefile, but this allows a place to set
23 * the values always used in the mozilla client, but perhaps done differently
24 * in other embeddings.
25 */
26 #ifdef MOZILLA_CLIENT
27 #define JSD_THREADSAFE 1
28 /* define JSD_HAS_DANGEROUS_THREAD 1 */
29 #define JSD_USE_NSPR_LOCKS 1
30 #endif /* MOZILLA_CLIENT */
32 #include "jsapi.h"
33 #include "jshash.h"
34 #include "jsclist.h"
35 #include "jsdebug.h"
36 #include "js/OldDebugAPI.h"
37 #include "jsd_lock.h"
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
43 #define JSD_MAJOR_VERSION 1
44 #define JSD_MINOR_VERSION 1
46 /***************************************************************************/
47 /* handy macros */
48 #undef CHECK_BIT_FLAG
49 #define CHECK_BIT_FLAG(f,b) ((f)&(b))
50 #undef SET_BIT_FLAG
51 #define SET_BIT_FLAG(f,b) ((f)|=(b))
52 #undef CLEAR_BIT_FLAG
53 #define CLEAR_BIT_FLAG(f,b) ((f)&=(~(b)))
55 #define JSD_IS_DEBUG_ENABLED(jsdc,jsdscript) \
56 (!(((jsdc->flags & JSD_DEBUG_WHEN_SET) ? 1 : 0) ^ \
57 ((jsdscript->flags & JSD_SCRIPT_DEBUG_BIT) ? 1 : 0)))
58 #define JSD_IS_PROFILE_ENABLED(jsdc,jsdscript) \
59 ((jsdc->flags & JSD_COLLECT_PROFILE_DATA) && \
60 (!(((jsdc->flags & JSD_PROFILE_WHEN_SET) ? 1 : 0) ^ \
61 ((jsdscript->flags & JSD_SCRIPT_PROFILE_BIT) ? 1 : 0))))
64 /***************************************************************************/
65 /* These are not exposed in jsdebug.h - typedef here for consistency */
67 typedef struct JSDExecHook JSDExecHook;
68 typedef struct JSDAtom JSDAtom;
69 typedef struct JSDProfileData JSDProfileData;
70 /***************************************************************************/
71 /* Our structures */
73 /*
74 * XXX What I'm calling a JSDContext is really more of a JSDTaskState.
75 */
77 struct JSDContext
78 {
79 JSCList links; /* we are part of a JSCList */
80 bool inited;
81 void* data;
82 uint32_t flags;
83 JSD_ScriptHookProc scriptHook;
84 void* scriptHookData;
85 JSD_ExecutionHookProc interruptHook;
86 void* interruptHookData;
87 JSRuntime* jsrt;
88 JSD_ErrorReporter errorReporter;
89 void* errorReporterData;
90 JSCList threadsStates;
91 JSD_ExecutionHookProc debugBreakHook;
92 void* debugBreakHookData;
93 JSD_ExecutionHookProc debuggerHook;
94 void* debuggerHookData;
95 JSD_ExecutionHookProc throwHook;
96 void* throwHookData;
97 JSD_CallHookProc functionHook;
98 void* functionHookData;
99 JSD_CallHookProc toplevelHook;
100 void* toplevelHookData;
101 JS::Heap<JSObject*> glob;
102 JSD_UserCallbacks userCallbacks;
103 void* user;
104 JSCList scripts;
105 JSHashTable* scriptsTable;
106 JSCList sources;
107 JSCList removedSources;
108 unsigned sourceAlterCount;
109 JSHashTable* atoms;
110 JSCList objectsList;
111 JSHashTable* objectsTable;
112 JSDProfileData* callingFunctionPData;
113 int64_t lastReturnTime;
114 #ifdef JSD_THREADSAFE
115 JSDStaticLock* scriptsLock;
116 JSDStaticLock* sourceTextLock;
117 JSDStaticLock* objectsLock;
118 JSDStaticLock* atomsLock;
119 JSDStaticLock* threadStatesLock;
120 #endif /* JSD_THREADSAFE */
121 #ifdef JSD_HAS_DANGEROUS_THREAD
122 void* dangerousThread;
123 #endif /* JSD_HAS_DANGEROUS_THREAD */
125 };
127 struct JSDScript
128 {
129 JSCList links; /* we are part of a JSCList */
130 JSDContext* jsdc; /* JSDContext for this jsdscript */
131 JSScript* script; /* script we are wrapping */
132 unsigned lineBase; /* we cache this */
133 unsigned lineExtent; /* we cache this */
134 JSCList hooks; /* JSCList of JSDExecHooks for this script */
135 char* url;
136 uint32_t flags;
137 void* data;
139 JSDProfileData *profileData;
140 };
142 struct JSDProfileData
143 {
144 JSDProfileData* caller;
145 int64_t lastCallStart;
146 int64_t runningTime;
147 unsigned callCount;
148 unsigned recurseDepth;
149 unsigned maxRecurseDepth;
150 double minExecutionTime;
151 double maxExecutionTime;
152 double totalExecutionTime;
153 double minOwnExecutionTime;
154 double maxOwnExecutionTime;
155 double totalOwnExecutionTime;
156 };
158 struct JSDSourceText
159 {
160 JSCList links; /* we are part of a JSCList */
161 char* url;
162 char* text;
163 unsigned textLength;
164 unsigned textSpace;
165 bool dirty;
166 JSDSourceStatus status;
167 unsigned alterCount;
168 bool doingEval;
169 };
171 struct JSDExecHook
172 {
173 JSCList links; /* we are part of a JSCList */
174 JSDScript* jsdscript;
175 uintptr_t pc;
176 JSD_ExecutionHookProc hook;
177 void* callerdata;
178 };
180 #define TS_HAS_DISABLED_FRAME 0x01
182 struct JSDThreadState
183 {
184 JSCList links; /* we are part of a JSCList */
185 JSContext* context;
186 void* thread;
187 JSCList stack;
188 unsigned stackDepth;
189 unsigned flags;
190 };
192 struct JSDStackFrameInfo
193 {
194 JSCList links; /* we are part of a JSCList */
195 JSDThreadState* jsdthreadstate;
196 JSDScript* jsdscript;
197 uintptr_t pc;
198 bool isConstructing;
199 JSAbstractFramePtr frame;
200 };
202 #define GOT_PROTO ((short) (1 << 0))
203 #define GOT_PROPS ((short) (1 << 1))
204 #define GOT_PARENT ((short) (1 << 2))
205 #define GOT_CTOR ((short) (1 << 3))
207 struct JSDValue
208 {
209 JS::Heap<JS::Value> val;
210 int nref;
211 JSCList props;
212 JS::Heap<JSString*> string;
213 JS::Heap<JSString*> funName;
214 const char* className;
215 JSDValue* proto;
216 JSDValue* parent;
217 JSDValue* ctor;
218 unsigned flags;
219 };
221 struct JSDProperty
222 {
223 JSCList links; /* we are part of a JSCList */
224 int nref;
225 JSDValue* val;
226 JSDValue* name;
227 JSDValue* alias;
228 unsigned flags;
229 };
231 struct JSDAtom
232 {
233 char* str; /* must be first element in struct for compare */
234 int refcount;
235 };
237 struct JSDObject
238 {
239 JSCList links; /* we are part of a JSCList */
240 JSObject* obj;
241 JSDAtom* newURL;
242 unsigned newLineno;
243 JSDAtom* ctorURL;
244 unsigned ctorLineno;
245 JSDAtom* ctorName;
246 };
248 /***************************************************************************/
249 /* Code validation support */
251 #ifdef DEBUG
252 extern void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc);
253 extern void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript);
254 extern void JSD_ASSERT_VALID_SOURCE_TEXT(JSDSourceText* jsdsrc);
255 extern void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate);
256 extern void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe);
257 extern void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook);
258 extern void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval);
259 extern void JSD_ASSERT_VALID_PROPERTY(JSDProperty* jsdprop);
260 extern void JSD_ASSERT_VALID_OBJECT(JSDObject* jsdobj);
261 #else
262 #define JSD_ASSERT_VALID_CONTEXT(x) ((void)0)
263 #define JSD_ASSERT_VALID_SCRIPT(x) ((void)0)
264 #define JSD_ASSERT_VALID_SOURCE_TEXT(x) ((void)0)
265 #define JSD_ASSERT_VALID_THREAD_STATE(x)((void)0)
266 #define JSD_ASSERT_VALID_STACK_FRAME(x) ((void)0)
267 #define JSD_ASSERT_VALID_EXEC_HOOK(x) ((void)0)
268 #define JSD_ASSERT_VALID_VALUE(x) ((void)0)
269 #define JSD_ASSERT_VALID_PROPERTY(x) ((void)0)
270 #define JSD_ASSERT_VALID_OBJECT(x) ((void)0)
271 #endif
273 /***************************************************************************/
274 /* higher level functions */
276 extern JSDContext*
277 jsd_DebuggerOnForUser(JSRuntime* jsrt,
278 JSD_UserCallbacks* callbacks,
279 void* user,
280 JSObject* scopeobj);
282 extern JSDContext*
283 jsd_DebuggerOn(void);
285 extern void
286 jsd_DebuggerOff(JSDContext* jsdc);
288 extern void
289 jsd_DebuggerPause(JSDContext* jsdc, bool forceAllHooksOff);
291 extern void
292 jsd_DebuggerUnpause(JSDContext* jsdc);
294 extern void
295 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user);
297 extern JSDContext*
298 jsd_JSDContextForJSContext(JSContext* context);
300 extern void*
301 jsd_SetContextPrivate(JSDContext* jsdc, void *data);
303 extern void*
304 jsd_GetContextPrivate(JSDContext* jsdc);
306 extern void
307 jsd_ClearAllProfileData(JSDContext* jsdc);
309 extern bool
310 jsd_SetErrorReporter(JSDContext* jsdc,
311 JSD_ErrorReporter reporter,
312 void* callerdata);
314 extern bool
315 jsd_GetErrorReporter(JSDContext* jsdc,
316 JSD_ErrorReporter* reporter,
317 void** callerdata);
319 /***************************************************************************/
320 /* Script functions */
322 extern bool
323 jsd_InitScriptManager(JSDContext *jsdc);
325 extern void
326 jsd_DestroyScriptManager(JSDContext* jsdc);
328 extern JSDScript*
329 jsd_FindJSDScript(JSDContext* jsdc,
330 JSScript *script);
332 extern JSDScript*
333 jsd_FindOrCreateJSDScript(JSDContext *jsdc,
334 JSContext *cx,
335 JSScript *script,
336 JSAbstractFramePtr frame);
338 extern JSDProfileData*
339 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
341 extern uint32_t
342 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
344 extern void
345 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32_t flags);
347 extern unsigned
348 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
350 extern unsigned
351 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
353 extern double
354 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
356 extern double
357 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
359 extern double
360 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
362 extern double
363 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
365 extern double
366 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
368 extern double
369 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
371 extern void
372 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
374 extern JSScript *
375 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script);
377 extern JSFunction *
378 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script);
380 extern JSDScript*
381 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
383 extern void *
384 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data);
386 extern void *
387 jsd_GetScriptPrivate (JSDScript *jsdscript);
389 extern bool
390 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
392 extern const char*
393 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
395 extern JSString*
396 jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript);
398 extern unsigned
399 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
401 extern unsigned
402 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
404 extern bool
405 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
407 extern bool
408 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
410 extern uintptr_t
411 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line);
413 extern unsigned
414 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc);
416 extern bool
417 jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
418 unsigned startLine, unsigned maxLines,
419 unsigned* count, unsigned** lines, uintptr_t** pcs);
421 extern void
422 jsd_NewScriptHookProc(
423 JSContext *cx,
424 const char *filename, /* URL this script loads from */
425 unsigned lineno, /* line where this script starts */
426 JSScript *script,
427 JSFunction *fun,
428 void* callerdata);
430 extern void
431 jsd_DestroyScriptHookProc(
432 JSFreeOp *fop,
433 JSScript *script,
434 void* callerdata);
436 /* Script execution hook functions */
438 extern bool
439 jsd_SetExecutionHook(JSDContext* jsdc,
440 JSDScript* jsdscript,
441 uintptr_t pc,
442 JSD_ExecutionHookProc hook,
443 void* callerdata);
445 extern bool
446 jsd_ClearExecutionHook(JSDContext* jsdc,
447 JSDScript* jsdscript,
448 uintptr_t pc);
450 extern bool
451 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
453 extern bool
454 jsd_ClearAllExecutionHooks(JSDContext* jsdc);
456 extern void
457 jsd_ScriptCreated(JSDContext* jsdc,
458 JSContext *cx,
459 const char *filename, /* URL this script loads from */
460 unsigned lineno, /* line where this script starts */
461 JSScript *script,
462 JSFunction *fun);
464 extern void
465 jsd_ScriptDestroyed(JSDContext* jsdc,
466 JSFreeOp *fop,
467 JSScript *script);
469 /***************************************************************************/
470 /* Source Text functions */
472 extern JSDSourceText*
473 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
475 extern JSDSourceText*
476 jsd_FindSourceForURL(JSDContext* jsdc, const char* url);
478 extern const char*
479 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
481 extern bool
482 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
483 const char** ppBuf, int* pLen);
485 extern void
486 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
488 extern JSDSourceStatus
489 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
491 extern bool
492 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
494 extern void
495 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, bool dirty);
497 extern unsigned
498 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
500 extern unsigned
501 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
503 extern JSDSourceText*
504 jsd_NewSourceText(JSDContext* jsdc, const char* url);
506 extern JSDSourceText*
507 jsd_AppendSourceText(JSDContext* jsdc,
508 JSDSourceText* jsdsrc,
509 const char* text, /* *not* zero terminated */
510 size_t length,
511 JSDSourceStatus status);
513 extern JSDSourceText*
514 jsd_AppendUCSourceText(JSDContext* jsdc,
515 JSDSourceText* jsdsrc,
516 const jschar* text, /* *not* zero terminated */
517 size_t length,
518 JSDSourceStatus status);
520 /* convienence function for adding complete source of url in one call */
521 extern bool
522 jsd_AddFullSourceText(JSDContext* jsdc,
523 const char* text, /* *not* zero terminated */
524 size_t length,
525 const char* url);
527 extern void
528 jsd_DestroyAllSources(JSDContext* jsdc);
530 extern char*
531 jsd_BuildNormalizedURL(const char* url_string);
533 extern void
534 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url);
536 extern void
537 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url);
539 /***************************************************************************/
540 /* Interrupt Hook functions */
542 extern bool
543 jsd_SetInterruptHook(JSDContext* jsdc,
544 JSD_ExecutionHookProc hook,
545 void* callerdata);
547 extern bool
548 jsd_ClearInterruptHook(JSDContext* jsdc);
550 extern bool
551 jsd_EnableSingleStepInterrupts(JSDContext* jsdc,
552 JSDScript* jsdscript,
553 bool enable);
555 extern bool
556 jsd_SetDebugBreakHook(JSDContext* jsdc,
557 JSD_ExecutionHookProc hook,
558 void* callerdata);
560 extern bool
561 jsd_ClearDebugBreakHook(JSDContext* jsdc);
563 extern bool
564 jsd_SetDebuggerHook(JSDContext* jsdc,
565 JSD_ExecutionHookProc hook,
566 void* callerdata);
568 extern bool
569 jsd_ClearDebuggerHook(JSDContext* jsdc);
571 extern JSTrapStatus
572 jsd_CallExecutionHook(JSDContext* jsdc,
573 JSContext* cx,
574 unsigned type,
575 JSD_ExecutionHookProc hook,
576 void* hookData,
577 jsval* rval);
579 extern bool
580 jsd_CallCallHook (JSDContext* jsdc,
581 JSContext* cx,
582 unsigned type,
583 JSD_CallHookProc hook,
584 void* hookData);
586 extern bool
587 jsd_SetThrowHook(JSDContext* jsdc,
588 JSD_ExecutionHookProc hook,
589 void* callerdata);
590 extern bool
591 jsd_ClearThrowHook(JSDContext* jsdc);
593 extern JSTrapStatus
594 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
595 jsval *rval, void *closure);
597 extern JSTrapStatus
598 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc,
599 jsval *rval, void *closure);
601 extern bool
602 jsd_SetFunctionHook(JSDContext* jsdc,
603 JSD_CallHookProc hook,
604 void* callerdata);
606 extern bool
607 jsd_ClearFunctionHook(JSDContext* jsdc);
609 extern bool
610 jsd_SetTopLevelHook(JSDContext* jsdc,
611 JSD_CallHookProc hook,
612 void* callerdata);
614 extern bool
615 jsd_ClearTopLevelHook(JSDContext* jsdc);
617 /***************************************************************************/
618 /* Stack Frame functions */
620 extern unsigned
621 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
623 extern JSDStackFrameInfo*
624 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
626 extern JSContext*
627 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
629 extern JSDStackFrameInfo*
630 jsd_GetCallingStackFrame(JSDContext* jsdc,
631 JSDThreadState* jsdthreadstate,
632 JSDStackFrameInfo* jsdframe);
634 extern JSDScript*
635 jsd_GetScriptForStackFrame(JSDContext* jsdc,
636 JSDThreadState* jsdthreadstate,
637 JSDStackFrameInfo* jsdframe);
639 extern uintptr_t
640 jsd_GetPCForStackFrame(JSDContext* jsdc,
641 JSDThreadState* jsdthreadstate,
642 JSDStackFrameInfo* jsdframe);
644 extern JSDValue*
645 jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
646 JSDThreadState* jsdthreadstate,
647 JSDStackFrameInfo* jsdframe);
649 extern JSDValue*
650 jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
651 JSDThreadState* jsdthreadstate,
652 JSDStackFrameInfo* jsdframe);
654 extern bool
655 jsd_IsStackFrameDebugger(JSDContext* jsdc,
656 JSDThreadState* jsdthreadstate,
657 JSDStackFrameInfo* jsdframe);
659 extern bool
660 jsd_IsStackFrameConstructing(JSDContext* jsdc,
661 JSDThreadState* jsdthreadstate,
662 JSDStackFrameInfo* jsdframe);
664 extern JSDValue*
665 jsd_GetThisForStackFrame(JSDContext* jsdc,
666 JSDThreadState* jsdthreadstate,
667 JSDStackFrameInfo* jsdframe);
669 extern JSString*
670 jsd_GetIdForStackFrame(JSDContext* jsdc,
671 JSDThreadState* jsdthreadstate,
672 JSDStackFrameInfo* jsdframe);
674 extern JSDThreadState*
675 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx);
677 extern void
678 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
680 extern bool
681 jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
682 JSDThreadState* jsdthreadstate,
683 JSDStackFrameInfo* jsdframe,
684 const jschar *bytes, unsigned length,
685 const char *filename, unsigned lineno,
686 bool eatExceptions, JS::MutableHandleValue rval);
688 extern bool
689 jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
690 JSDThreadState* jsdthreadstate,
691 JSDStackFrameInfo* jsdframe,
692 const char *bytes, unsigned length,
693 const char *filename, unsigned lineno,
694 bool eatExceptions, JS::MutableHandleValue rval);
696 extern JSString*
697 jsd_ValToStringInStackFrame(JSDContext* jsdc,
698 JSDThreadState* jsdthreadstate,
699 JSDStackFrameInfo* jsdframe,
700 jsval val);
702 extern bool
703 jsd_IsValidThreadState(JSDContext* jsdc,
704 JSDThreadState* jsdthreadstate);
706 extern bool
707 jsd_IsValidFrameInThreadState(JSDContext* jsdc,
708 JSDThreadState* jsdthreadstate,
709 JSDStackFrameInfo* jsdframe);
711 extern JSDValue*
712 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
714 extern bool
715 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate,
716 JSDValue* jsdval);
718 /***************************************************************************/
719 /* Locking support */
721 /* protos are in js_lock.h for:
722 * jsd_CreateLock
723 * jsd_Lock
724 * jsd_Unlock
725 * jsd_IsLocked
726 * jsd_CurrentThread
727 */
729 #ifdef JSD_THREADSAFE
731 /* the system-wide lock */
732 extern JSDStaticLock* _jsd_global_lock;
733 #define JSD_LOCK() \
734 JS_BEGIN_MACRO \
735 if(!_jsd_global_lock) \
736 _jsd_global_lock = jsd_CreateLock(); \
737 MOZ_ASSERT(_jsd_global_lock); \
738 jsd_Lock(_jsd_global_lock); \
739 JS_END_MACRO
741 #define JSD_UNLOCK() \
742 JS_BEGIN_MACRO \
743 MOZ_ASSERT(_jsd_global_lock); \
744 jsd_Unlock(_jsd_global_lock); \
745 JS_END_MACRO
747 /* locks for the subsystems of a given context */
748 #define JSD_INIT_LOCKS(jsdc) \
749 ( (nullptr != (jsdc->scriptsLock = jsd_CreateLock())) && \
750 (nullptr != (jsdc->sourceTextLock = jsd_CreateLock())) && \
751 (nullptr != (jsdc->atomsLock = jsd_CreateLock())) && \
752 (nullptr != (jsdc->objectsLock = jsd_CreateLock())) && \
753 (nullptr != (jsdc->threadStatesLock = jsd_CreateLock())) )
755 #define JSD_LOCK_SCRIPTS(jsdc) jsd_Lock(jsdc->scriptsLock)
756 #define JSD_UNLOCK_SCRIPTS(jsdc) jsd_Unlock(jsdc->scriptsLock)
758 #define JSD_LOCK_SOURCE_TEXT(jsdc) jsd_Lock(jsdc->sourceTextLock)
759 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) jsd_Unlock(jsdc->sourceTextLock)
761 #define JSD_LOCK_ATOMS(jsdc) jsd_Lock(jsdc->atomsLock)
762 #define JSD_UNLOCK_ATOMS(jsdc) jsd_Unlock(jsdc->atomsLock)
764 #define JSD_LOCK_OBJECTS(jsdc) jsd_Lock(jsdc->objectsLock)
765 #define JSD_UNLOCK_OBJECTS(jsdc) jsd_Unlock(jsdc->objectsLock)
767 #define JSD_LOCK_THREADSTATES(jsdc) jsd_Lock(jsdc->threadStatesLock)
768 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock)
770 #else /* !JSD_THREADSAFE */
772 #define JSD_LOCK() ((void)0)
773 #define JSD_UNLOCK() ((void)0)
775 #define JSD_INIT_LOCKS(jsdc) 1
777 #define JSD_LOCK_SCRIPTS(jsdc) ((void)0)
778 #define JSD_UNLOCK_SCRIPTS(jsdc) ((void)0)
780 #define JSD_LOCK_SOURCE_TEXT(jsdc) ((void)0)
781 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) ((void)0)
783 #define JSD_LOCK_ATOMS(jsdc) ((void)0)
784 #define JSD_UNLOCK_ATOMS(jsdc) ((void)0)
786 #define JSD_LOCK_OBJECTS(jsdc) ((void)0)
787 #define JSD_UNLOCK_OBJECTS(jsdc) ((void)0)
789 #define JSD_LOCK_THREADSTATES(jsdc) ((void)0)
790 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0)
792 #endif /* JSD_THREADSAFE */
794 /* NOTE: These are intended for ASSERTs. Thus we supply checks for both
795 * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in
796 * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds
797 * without having to special case things in the code.
798 */
799 #if defined(JSD_THREADSAFE) && defined(DEBUG)
800 #define JSD_SCRIPTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->scriptsLock))
801 #define JSD_SOURCE_TEXT_LOCKED(jsdc) (jsd_IsLocked(jsdc->sourceTextLock))
802 #define JSD_ATOMS_LOCKED(jsdc) (jsd_IsLocked(jsdc->atomsLock))
803 #define JSD_OBJECTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->objectsLock))
804 #define JSD_THREADSTATES_LOCKED(jsdc) (jsd_IsLocked(jsdc->threadStatesLock))
805 #define JSD_SCRIPTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->scriptsLock))
806 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->sourceTextLock))
807 #define JSD_ATOMS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->atomsLock))
808 #define JSD_OBJECTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->objectsLock))
809 #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock))
810 #else
811 #define JSD_SCRIPTS_LOCKED(jsdc) 1
812 #define JSD_SOURCE_TEXT_LOCKED(jsdc) 1
813 #define JSD_ATOMS_LOCKED(jsdc) 1
814 #define JSD_OBJECTS_LOCKED(jsdc) 1
815 #define JSD_THREADSTATES_LOCKED(jsdc) 1
816 #define JSD_SCRIPTS_UNLOCKED(jsdc) 1
817 #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) 1
818 #define JSD_ATOMS_UNLOCKED(jsdc) 1
819 #define JSD_OBJECTS_UNLOCKED(jsdc) 1
820 #define JSD_THREADSTATES_UNLOCKED(jsdc) 1
821 #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */
823 /***************************************************************************/
824 /* Threading support */
826 #ifdef JSD_THREADSAFE
828 #define JSD_CURRENT_THREAD() jsd_CurrentThread()
830 #else /* !JSD_THREADSAFE */
832 #define JSD_CURRENT_THREAD() ((void*)0)
834 #endif /* JSD_THREADSAFE */
836 /***************************************************************************/
837 /* Dangerous thread support */
839 #ifdef JSD_HAS_DANGEROUS_THREAD
841 #define JSD_IS_DANGEROUS_THREAD(jsdc) \
842 (JSD_CURRENT_THREAD() == jsdc->dangerousThread)
844 #else /* !JSD_HAS_DANGEROUS_THREAD */
846 #define JSD_IS_DANGEROUS_THREAD(jsdc) 0
848 #endif /* JSD_HAS_DANGEROUS_THREAD */
850 /***************************************************************************/
851 /* Value and Property Functions */
853 extern JSDValue*
854 jsd_NewValue(JSDContext* jsdc, jsval val);
856 extern void
857 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval);
859 extern jsval
860 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
862 extern void
863 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
865 /**************************************************/
867 extern bool
868 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
870 extern bool
871 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
873 extern bool
874 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
876 extern bool
877 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
879 extern bool
880 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
882 extern bool
883 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
885 extern bool
886 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
888 extern bool
889 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
891 extern bool
892 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
894 extern bool
895 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
897 extern bool
898 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
900 /**************************************************/
902 extern bool
903 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
905 extern int32_t
906 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
908 extern double
909 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
911 extern JSString*
912 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
914 extern JSString*
915 jsd_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval);
917 extern JSFunction*
918 jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
920 /**************************************************/
922 extern unsigned
923 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
925 extern JSDProperty*
926 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
928 extern JSDProperty*
929 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
931 extern JSDValue*
932 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
934 extern JSDValue*
935 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
937 extern JSDValue*
938 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
940 extern const char*
941 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
943 extern JSDScript*
944 jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval);
946 /**************************************************/
948 extern void
949 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
951 extern JSDValue*
952 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
954 extern JSDValue*
955 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
957 extern JSDValue*
958 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
960 extern unsigned
961 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
963 /**************************************************/
964 /* Stepping Functions */
966 extern void *
967 jsd_FunctionCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing,
968 bool before, bool *ok, void *closure);
970 extern void *
971 jsd_TopLevelCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing,
972 bool before, bool *ok, void *closure);
974 /**************************************************/
975 /* Object Functions */
977 extern bool
978 jsd_InitObjectManager(JSDContext* jsdc);
980 extern void
981 jsd_DestroyObjectManager(JSDContext* jsdc);
983 extern void
984 jsd_DestroyObjects(JSDContext* jsdc);
986 extern void
987 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
988 JSAbstractFramePtr frame);
990 extern JSDObject*
991 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
993 extern JSObject*
994 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
996 extern const char*
997 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
999 extern unsigned
1000 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1002 extern const char*
1003 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
1005 extern unsigned
1006 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
1008 extern const char*
1009 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
1011 extern JSDObject*
1012 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
1014 extern JSDObject*
1015 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
1017 /*
1018 * returns new refcounted JSDValue
1019 */
1020 extern JSDValue*
1021 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
1023 /**************************************************/
1024 /* Atom Functions */
1026 extern bool
1027 jsd_CreateAtomTable(JSDContext* jsdc);
1029 extern void
1030 jsd_DestroyAtomTable(JSDContext* jsdc);
1032 extern JSDAtom*
1033 jsd_AddAtom(JSDContext* jsdc, const char* str);
1035 extern JSDAtom*
1036 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom);
1038 extern void
1039 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom);
1041 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str))
1043 struct AutoSaveExceptionState {
1044 AutoSaveExceptionState(JSContext *cx) : mCx(cx) {
1045 mState = JS_SaveExceptionState(cx);
1046 }
1047 ~AutoSaveExceptionState() {
1048 JS_RestoreExceptionState(mCx, mState);
1049 }
1050 JSContext *mCx;
1051 JSExceptionState *mState;
1052 };
1054 #endif /* jsd_h___ */