|
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/. */ |
|
6 |
|
7 /* |
|
8 * Header for JavaScript Debugging support - Internal ONLY declarations |
|
9 */ |
|
10 |
|
11 #ifndef jsd_h___ |
|
12 #define jsd_h___ |
|
13 |
|
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 */ |
|
20 |
|
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 */ |
|
31 |
|
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" |
|
38 |
|
39 #include <stdio.h> |
|
40 #include <stdlib.h> |
|
41 #include <string.h> |
|
42 |
|
43 #define JSD_MAJOR_VERSION 1 |
|
44 #define JSD_MINOR_VERSION 1 |
|
45 |
|
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))) |
|
54 |
|
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)))) |
|
62 |
|
63 |
|
64 /***************************************************************************/ |
|
65 /* These are not exposed in jsdebug.h - typedef here for consistency */ |
|
66 |
|
67 typedef struct JSDExecHook JSDExecHook; |
|
68 typedef struct JSDAtom JSDAtom; |
|
69 typedef struct JSDProfileData JSDProfileData; |
|
70 /***************************************************************************/ |
|
71 /* Our structures */ |
|
72 |
|
73 /* |
|
74 * XXX What I'm calling a JSDContext is really more of a JSDTaskState. |
|
75 */ |
|
76 |
|
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 */ |
|
124 |
|
125 }; |
|
126 |
|
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; |
|
138 |
|
139 JSDProfileData *profileData; |
|
140 }; |
|
141 |
|
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 }; |
|
157 |
|
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 }; |
|
170 |
|
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 }; |
|
179 |
|
180 #define TS_HAS_DISABLED_FRAME 0x01 |
|
181 |
|
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 }; |
|
191 |
|
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 }; |
|
201 |
|
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)) |
|
206 |
|
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 }; |
|
220 |
|
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 }; |
|
230 |
|
231 struct JSDAtom |
|
232 { |
|
233 char* str; /* must be first element in struct for compare */ |
|
234 int refcount; |
|
235 }; |
|
236 |
|
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 }; |
|
247 |
|
248 /***************************************************************************/ |
|
249 /* Code validation support */ |
|
250 |
|
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 |
|
272 |
|
273 /***************************************************************************/ |
|
274 /* higher level functions */ |
|
275 |
|
276 extern JSDContext* |
|
277 jsd_DebuggerOnForUser(JSRuntime* jsrt, |
|
278 JSD_UserCallbacks* callbacks, |
|
279 void* user, |
|
280 JSObject* scopeobj); |
|
281 |
|
282 extern JSDContext* |
|
283 jsd_DebuggerOn(void); |
|
284 |
|
285 extern void |
|
286 jsd_DebuggerOff(JSDContext* jsdc); |
|
287 |
|
288 extern void |
|
289 jsd_DebuggerPause(JSDContext* jsdc, bool forceAllHooksOff); |
|
290 |
|
291 extern void |
|
292 jsd_DebuggerUnpause(JSDContext* jsdc); |
|
293 |
|
294 extern void |
|
295 jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user); |
|
296 |
|
297 extern JSDContext* |
|
298 jsd_JSDContextForJSContext(JSContext* context); |
|
299 |
|
300 extern void* |
|
301 jsd_SetContextPrivate(JSDContext* jsdc, void *data); |
|
302 |
|
303 extern void* |
|
304 jsd_GetContextPrivate(JSDContext* jsdc); |
|
305 |
|
306 extern void |
|
307 jsd_ClearAllProfileData(JSDContext* jsdc); |
|
308 |
|
309 extern bool |
|
310 jsd_SetErrorReporter(JSDContext* jsdc, |
|
311 JSD_ErrorReporter reporter, |
|
312 void* callerdata); |
|
313 |
|
314 extern bool |
|
315 jsd_GetErrorReporter(JSDContext* jsdc, |
|
316 JSD_ErrorReporter* reporter, |
|
317 void** callerdata); |
|
318 |
|
319 /***************************************************************************/ |
|
320 /* Script functions */ |
|
321 |
|
322 extern bool |
|
323 jsd_InitScriptManager(JSDContext *jsdc); |
|
324 |
|
325 extern void |
|
326 jsd_DestroyScriptManager(JSDContext* jsdc); |
|
327 |
|
328 extern JSDScript* |
|
329 jsd_FindJSDScript(JSDContext* jsdc, |
|
330 JSScript *script); |
|
331 |
|
332 extern JSDScript* |
|
333 jsd_FindOrCreateJSDScript(JSDContext *jsdc, |
|
334 JSContext *cx, |
|
335 JSScript *script, |
|
336 JSAbstractFramePtr frame); |
|
337 |
|
338 extern JSDProfileData* |
|
339 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script); |
|
340 |
|
341 extern uint32_t |
|
342 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script); |
|
343 |
|
344 extern void |
|
345 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32_t flags); |
|
346 |
|
347 extern unsigned |
|
348 jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script); |
|
349 |
|
350 extern unsigned |
|
351 jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script); |
|
352 |
|
353 extern double |
|
354 jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
355 |
|
356 extern double |
|
357 jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
358 |
|
359 extern double |
|
360 jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
361 |
|
362 extern double |
|
363 jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
364 |
|
365 extern double |
|
366 jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
367 |
|
368 extern double |
|
369 jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
|
370 |
|
371 extern void |
|
372 jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script); |
|
373 |
|
374 extern JSScript * |
|
375 jsd_GetJSScript (JSDContext *jsdc, JSDScript *script); |
|
376 |
|
377 extern JSFunction * |
|
378 jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script); |
|
379 |
|
380 extern JSDScript* |
|
381 jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp); |
|
382 |
|
383 extern void * |
|
384 jsd_SetScriptPrivate (JSDScript *jsdscript, void *data); |
|
385 |
|
386 extern void * |
|
387 jsd_GetScriptPrivate (JSDScript *jsdscript); |
|
388 |
|
389 extern bool |
|
390 jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript); |
|
391 |
|
392 extern const char* |
|
393 jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript); |
|
394 |
|
395 extern JSString* |
|
396 jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript); |
|
397 |
|
398 extern unsigned |
|
399 jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript); |
|
400 |
|
401 extern unsigned |
|
402 jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript); |
|
403 |
|
404 extern bool |
|
405 jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata); |
|
406 |
|
407 extern bool |
|
408 jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata); |
|
409 |
|
410 extern uintptr_t |
|
411 jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line); |
|
412 |
|
413 extern unsigned |
|
414 jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc); |
|
415 |
|
416 extern bool |
|
417 jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript, |
|
418 unsigned startLine, unsigned maxLines, |
|
419 unsigned* count, unsigned** lines, uintptr_t** pcs); |
|
420 |
|
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); |
|
429 |
|
430 extern void |
|
431 jsd_DestroyScriptHookProc( |
|
432 JSFreeOp *fop, |
|
433 JSScript *script, |
|
434 void* callerdata); |
|
435 |
|
436 /* Script execution hook functions */ |
|
437 |
|
438 extern bool |
|
439 jsd_SetExecutionHook(JSDContext* jsdc, |
|
440 JSDScript* jsdscript, |
|
441 uintptr_t pc, |
|
442 JSD_ExecutionHookProc hook, |
|
443 void* callerdata); |
|
444 |
|
445 extern bool |
|
446 jsd_ClearExecutionHook(JSDContext* jsdc, |
|
447 JSDScript* jsdscript, |
|
448 uintptr_t pc); |
|
449 |
|
450 extern bool |
|
451 jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript); |
|
452 |
|
453 extern bool |
|
454 jsd_ClearAllExecutionHooks(JSDContext* jsdc); |
|
455 |
|
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); |
|
463 |
|
464 extern void |
|
465 jsd_ScriptDestroyed(JSDContext* jsdc, |
|
466 JSFreeOp *fop, |
|
467 JSScript *script); |
|
468 |
|
469 /***************************************************************************/ |
|
470 /* Source Text functions */ |
|
471 |
|
472 extern JSDSourceText* |
|
473 jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp); |
|
474 |
|
475 extern JSDSourceText* |
|
476 jsd_FindSourceForURL(JSDContext* jsdc, const char* url); |
|
477 |
|
478 extern const char* |
|
479 jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
480 |
|
481 extern bool |
|
482 jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc, |
|
483 const char** ppBuf, int* pLen); |
|
484 |
|
485 extern void |
|
486 jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
487 |
|
488 extern JSDSourceStatus |
|
489 jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
490 |
|
491 extern bool |
|
492 jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
493 |
|
494 extern void |
|
495 jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, bool dirty); |
|
496 |
|
497 extern unsigned |
|
498 jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
499 |
|
500 extern unsigned |
|
501 jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc); |
|
502 |
|
503 extern JSDSourceText* |
|
504 jsd_NewSourceText(JSDContext* jsdc, const char* url); |
|
505 |
|
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); |
|
512 |
|
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); |
|
519 |
|
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); |
|
526 |
|
527 extern void |
|
528 jsd_DestroyAllSources(JSDContext* jsdc); |
|
529 |
|
530 extern char* |
|
531 jsd_BuildNormalizedURL(const char* url_string); |
|
532 |
|
533 extern void |
|
534 jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url); |
|
535 |
|
536 extern void |
|
537 jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url); |
|
538 |
|
539 /***************************************************************************/ |
|
540 /* Interrupt Hook functions */ |
|
541 |
|
542 extern bool |
|
543 jsd_SetInterruptHook(JSDContext* jsdc, |
|
544 JSD_ExecutionHookProc hook, |
|
545 void* callerdata); |
|
546 |
|
547 extern bool |
|
548 jsd_ClearInterruptHook(JSDContext* jsdc); |
|
549 |
|
550 extern bool |
|
551 jsd_EnableSingleStepInterrupts(JSDContext* jsdc, |
|
552 JSDScript* jsdscript, |
|
553 bool enable); |
|
554 |
|
555 extern bool |
|
556 jsd_SetDebugBreakHook(JSDContext* jsdc, |
|
557 JSD_ExecutionHookProc hook, |
|
558 void* callerdata); |
|
559 |
|
560 extern bool |
|
561 jsd_ClearDebugBreakHook(JSDContext* jsdc); |
|
562 |
|
563 extern bool |
|
564 jsd_SetDebuggerHook(JSDContext* jsdc, |
|
565 JSD_ExecutionHookProc hook, |
|
566 void* callerdata); |
|
567 |
|
568 extern bool |
|
569 jsd_ClearDebuggerHook(JSDContext* jsdc); |
|
570 |
|
571 extern JSTrapStatus |
|
572 jsd_CallExecutionHook(JSDContext* jsdc, |
|
573 JSContext* cx, |
|
574 unsigned type, |
|
575 JSD_ExecutionHookProc hook, |
|
576 void* hookData, |
|
577 jsval* rval); |
|
578 |
|
579 extern bool |
|
580 jsd_CallCallHook (JSDContext* jsdc, |
|
581 JSContext* cx, |
|
582 unsigned type, |
|
583 JSD_CallHookProc hook, |
|
584 void* hookData); |
|
585 |
|
586 extern bool |
|
587 jsd_SetThrowHook(JSDContext* jsdc, |
|
588 JSD_ExecutionHookProc hook, |
|
589 void* callerdata); |
|
590 extern bool |
|
591 jsd_ClearThrowHook(JSDContext* jsdc); |
|
592 |
|
593 extern JSTrapStatus |
|
594 jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc, |
|
595 jsval *rval, void *closure); |
|
596 |
|
597 extern JSTrapStatus |
|
598 jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc, |
|
599 jsval *rval, void *closure); |
|
600 |
|
601 extern bool |
|
602 jsd_SetFunctionHook(JSDContext* jsdc, |
|
603 JSD_CallHookProc hook, |
|
604 void* callerdata); |
|
605 |
|
606 extern bool |
|
607 jsd_ClearFunctionHook(JSDContext* jsdc); |
|
608 |
|
609 extern bool |
|
610 jsd_SetTopLevelHook(JSDContext* jsdc, |
|
611 JSD_CallHookProc hook, |
|
612 void* callerdata); |
|
613 |
|
614 extern bool |
|
615 jsd_ClearTopLevelHook(JSDContext* jsdc); |
|
616 |
|
617 /***************************************************************************/ |
|
618 /* Stack Frame functions */ |
|
619 |
|
620 extern unsigned |
|
621 jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
|
622 |
|
623 extern JSDStackFrameInfo* |
|
624 jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
|
625 |
|
626 extern JSContext* |
|
627 jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
|
628 |
|
629 extern JSDStackFrameInfo* |
|
630 jsd_GetCallingStackFrame(JSDContext* jsdc, |
|
631 JSDThreadState* jsdthreadstate, |
|
632 JSDStackFrameInfo* jsdframe); |
|
633 |
|
634 extern JSDScript* |
|
635 jsd_GetScriptForStackFrame(JSDContext* jsdc, |
|
636 JSDThreadState* jsdthreadstate, |
|
637 JSDStackFrameInfo* jsdframe); |
|
638 |
|
639 extern uintptr_t |
|
640 jsd_GetPCForStackFrame(JSDContext* jsdc, |
|
641 JSDThreadState* jsdthreadstate, |
|
642 JSDStackFrameInfo* jsdframe); |
|
643 |
|
644 extern JSDValue* |
|
645 jsd_GetCallObjectForStackFrame(JSDContext* jsdc, |
|
646 JSDThreadState* jsdthreadstate, |
|
647 JSDStackFrameInfo* jsdframe); |
|
648 |
|
649 extern JSDValue* |
|
650 jsd_GetScopeChainForStackFrame(JSDContext* jsdc, |
|
651 JSDThreadState* jsdthreadstate, |
|
652 JSDStackFrameInfo* jsdframe); |
|
653 |
|
654 extern bool |
|
655 jsd_IsStackFrameDebugger(JSDContext* jsdc, |
|
656 JSDThreadState* jsdthreadstate, |
|
657 JSDStackFrameInfo* jsdframe); |
|
658 |
|
659 extern bool |
|
660 jsd_IsStackFrameConstructing(JSDContext* jsdc, |
|
661 JSDThreadState* jsdthreadstate, |
|
662 JSDStackFrameInfo* jsdframe); |
|
663 |
|
664 extern JSDValue* |
|
665 jsd_GetThisForStackFrame(JSDContext* jsdc, |
|
666 JSDThreadState* jsdthreadstate, |
|
667 JSDStackFrameInfo* jsdframe); |
|
668 |
|
669 extern JSString* |
|
670 jsd_GetIdForStackFrame(JSDContext* jsdc, |
|
671 JSDThreadState* jsdthreadstate, |
|
672 JSDStackFrameInfo* jsdframe); |
|
673 |
|
674 extern JSDThreadState* |
|
675 jsd_NewThreadState(JSDContext* jsdc, JSContext *cx); |
|
676 |
|
677 extern void |
|
678 jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
|
679 |
|
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); |
|
687 |
|
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); |
|
695 |
|
696 extern JSString* |
|
697 jsd_ValToStringInStackFrame(JSDContext* jsdc, |
|
698 JSDThreadState* jsdthreadstate, |
|
699 JSDStackFrameInfo* jsdframe, |
|
700 jsval val); |
|
701 |
|
702 extern bool |
|
703 jsd_IsValidThreadState(JSDContext* jsdc, |
|
704 JSDThreadState* jsdthreadstate); |
|
705 |
|
706 extern bool |
|
707 jsd_IsValidFrameInThreadState(JSDContext* jsdc, |
|
708 JSDThreadState* jsdthreadstate, |
|
709 JSDStackFrameInfo* jsdframe); |
|
710 |
|
711 extern JSDValue* |
|
712 jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
|
713 |
|
714 extern bool |
|
715 jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, |
|
716 JSDValue* jsdval); |
|
717 |
|
718 /***************************************************************************/ |
|
719 /* Locking support */ |
|
720 |
|
721 /* protos are in js_lock.h for: |
|
722 * jsd_CreateLock |
|
723 * jsd_Lock |
|
724 * jsd_Unlock |
|
725 * jsd_IsLocked |
|
726 * jsd_CurrentThread |
|
727 */ |
|
728 |
|
729 #ifdef JSD_THREADSAFE |
|
730 |
|
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 |
|
740 |
|
741 #define JSD_UNLOCK() \ |
|
742 JS_BEGIN_MACRO \ |
|
743 MOZ_ASSERT(_jsd_global_lock); \ |
|
744 jsd_Unlock(_jsd_global_lock); \ |
|
745 JS_END_MACRO |
|
746 |
|
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())) ) |
|
754 |
|
755 #define JSD_LOCK_SCRIPTS(jsdc) jsd_Lock(jsdc->scriptsLock) |
|
756 #define JSD_UNLOCK_SCRIPTS(jsdc) jsd_Unlock(jsdc->scriptsLock) |
|
757 |
|
758 #define JSD_LOCK_SOURCE_TEXT(jsdc) jsd_Lock(jsdc->sourceTextLock) |
|
759 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) jsd_Unlock(jsdc->sourceTextLock) |
|
760 |
|
761 #define JSD_LOCK_ATOMS(jsdc) jsd_Lock(jsdc->atomsLock) |
|
762 #define JSD_UNLOCK_ATOMS(jsdc) jsd_Unlock(jsdc->atomsLock) |
|
763 |
|
764 #define JSD_LOCK_OBJECTS(jsdc) jsd_Lock(jsdc->objectsLock) |
|
765 #define JSD_UNLOCK_OBJECTS(jsdc) jsd_Unlock(jsdc->objectsLock) |
|
766 |
|
767 #define JSD_LOCK_THREADSTATES(jsdc) jsd_Lock(jsdc->threadStatesLock) |
|
768 #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock) |
|
769 |
|
770 #else /* !JSD_THREADSAFE */ |
|
771 |
|
772 #define JSD_LOCK() ((void)0) |
|
773 #define JSD_UNLOCK() ((void)0) |
|
774 |
|
775 #define JSD_INIT_LOCKS(jsdc) 1 |
|
776 |
|
777 #define JSD_LOCK_SCRIPTS(jsdc) ((void)0) |
|
778 #define JSD_UNLOCK_SCRIPTS(jsdc) ((void)0) |
|
779 |
|
780 #define JSD_LOCK_SOURCE_TEXT(jsdc) ((void)0) |
|
781 #define JSD_UNLOCK_SOURCE_TEXT(jsdc) ((void)0) |
|
782 |
|
783 #define JSD_LOCK_ATOMS(jsdc) ((void)0) |
|
784 #define JSD_UNLOCK_ATOMS(jsdc) ((void)0) |
|
785 |
|
786 #define JSD_LOCK_OBJECTS(jsdc) ((void)0) |
|
787 #define JSD_UNLOCK_OBJECTS(jsdc) ((void)0) |
|
788 |
|
789 #define JSD_LOCK_THREADSTATES(jsdc) ((void)0) |
|
790 #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0) |
|
791 |
|
792 #endif /* JSD_THREADSAFE */ |
|
793 |
|
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) */ |
|
822 |
|
823 /***************************************************************************/ |
|
824 /* Threading support */ |
|
825 |
|
826 #ifdef JSD_THREADSAFE |
|
827 |
|
828 #define JSD_CURRENT_THREAD() jsd_CurrentThread() |
|
829 |
|
830 #else /* !JSD_THREADSAFE */ |
|
831 |
|
832 #define JSD_CURRENT_THREAD() ((void*)0) |
|
833 |
|
834 #endif /* JSD_THREADSAFE */ |
|
835 |
|
836 /***************************************************************************/ |
|
837 /* Dangerous thread support */ |
|
838 |
|
839 #ifdef JSD_HAS_DANGEROUS_THREAD |
|
840 |
|
841 #define JSD_IS_DANGEROUS_THREAD(jsdc) \ |
|
842 (JSD_CURRENT_THREAD() == jsdc->dangerousThread) |
|
843 |
|
844 #else /* !JSD_HAS_DANGEROUS_THREAD */ |
|
845 |
|
846 #define JSD_IS_DANGEROUS_THREAD(jsdc) 0 |
|
847 |
|
848 #endif /* JSD_HAS_DANGEROUS_THREAD */ |
|
849 |
|
850 /***************************************************************************/ |
|
851 /* Value and Property Functions */ |
|
852 |
|
853 extern JSDValue* |
|
854 jsd_NewValue(JSDContext* jsdc, jsval val); |
|
855 |
|
856 extern void |
|
857 jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval); |
|
858 |
|
859 extern jsval |
|
860 jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval); |
|
861 |
|
862 extern void |
|
863 jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval); |
|
864 |
|
865 /**************************************************/ |
|
866 |
|
867 extern bool |
|
868 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval); |
|
869 |
|
870 extern bool |
|
871 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval); |
|
872 |
|
873 extern bool |
|
874 jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval); |
|
875 |
|
876 extern bool |
|
877 jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval); |
|
878 |
|
879 extern bool |
|
880 jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval); |
|
881 |
|
882 extern bool |
|
883 jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval); |
|
884 |
|
885 extern bool |
|
886 jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval); |
|
887 |
|
888 extern bool |
|
889 jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval); |
|
890 |
|
891 extern bool |
|
892 jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval); |
|
893 |
|
894 extern bool |
|
895 jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval); |
|
896 |
|
897 extern bool |
|
898 jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval); |
|
899 |
|
900 /**************************************************/ |
|
901 |
|
902 extern bool |
|
903 jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval); |
|
904 |
|
905 extern int32_t |
|
906 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval); |
|
907 |
|
908 extern double |
|
909 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval); |
|
910 |
|
911 extern JSString* |
|
912 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval); |
|
913 |
|
914 extern JSString* |
|
915 jsd_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval); |
|
916 |
|
917 extern JSFunction* |
|
918 jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval); |
|
919 |
|
920 /**************************************************/ |
|
921 |
|
922 extern unsigned |
|
923 jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval); |
|
924 |
|
925 extern JSDProperty* |
|
926 jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp); |
|
927 |
|
928 extern JSDProperty* |
|
929 jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name); |
|
930 |
|
931 extern JSDValue* |
|
932 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval); |
|
933 |
|
934 extern JSDValue* |
|
935 jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval); |
|
936 |
|
937 extern JSDValue* |
|
938 jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval); |
|
939 |
|
940 extern const char* |
|
941 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval); |
|
942 |
|
943 extern JSDScript* |
|
944 jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval); |
|
945 |
|
946 /**************************************************/ |
|
947 |
|
948 extern void |
|
949 jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop); |
|
950 |
|
951 extern JSDValue* |
|
952 jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop); |
|
953 |
|
954 extern JSDValue* |
|
955 jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop); |
|
956 |
|
957 extern JSDValue* |
|
958 jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop); |
|
959 |
|
960 extern unsigned |
|
961 jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop); |
|
962 |
|
963 /**************************************************/ |
|
964 /* Stepping Functions */ |
|
965 |
|
966 extern void * |
|
967 jsd_FunctionCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, |
|
968 bool before, bool *ok, void *closure); |
|
969 |
|
970 extern void * |
|
971 jsd_TopLevelCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, |
|
972 bool before, bool *ok, void *closure); |
|
973 |
|
974 /**************************************************/ |
|
975 /* Object Functions */ |
|
976 |
|
977 extern bool |
|
978 jsd_InitObjectManager(JSDContext* jsdc); |
|
979 |
|
980 extern void |
|
981 jsd_DestroyObjectManager(JSDContext* jsdc); |
|
982 |
|
983 extern void |
|
984 jsd_DestroyObjects(JSDContext* jsdc); |
|
985 |
|
986 extern void |
|
987 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj, |
|
988 JSAbstractFramePtr frame); |
|
989 |
|
990 extern JSDObject* |
|
991 jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp); |
|
992 |
|
993 extern JSObject* |
|
994 jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj); |
|
995 |
|
996 extern const char* |
|
997 jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj); |
|
998 |
|
999 extern unsigned |
|
1000 jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj); |
|
1001 |
|
1002 extern const char* |
|
1003 jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj); |
|
1004 |
|
1005 extern unsigned |
|
1006 jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj); |
|
1007 |
|
1008 extern const char* |
|
1009 jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj); |
|
1010 |
|
1011 extern JSDObject* |
|
1012 jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj); |
|
1013 |
|
1014 extern JSDObject* |
|
1015 jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval); |
|
1016 |
|
1017 /* |
|
1018 * returns new refcounted JSDValue |
|
1019 */ |
|
1020 extern JSDValue* |
|
1021 jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj); |
|
1022 |
|
1023 /**************************************************/ |
|
1024 /* Atom Functions */ |
|
1025 |
|
1026 extern bool |
|
1027 jsd_CreateAtomTable(JSDContext* jsdc); |
|
1028 |
|
1029 extern void |
|
1030 jsd_DestroyAtomTable(JSDContext* jsdc); |
|
1031 |
|
1032 extern JSDAtom* |
|
1033 jsd_AddAtom(JSDContext* jsdc, const char* str); |
|
1034 |
|
1035 extern JSDAtom* |
|
1036 jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom); |
|
1037 |
|
1038 extern void |
|
1039 jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom); |
|
1040 |
|
1041 #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str)) |
|
1042 |
|
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 }; |
|
1053 |
|
1054 #endif /* jsd_h___ */ |