-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.js
More file actions
854 lines (717 loc) · 22.6 KB
/
debugger.js
File metadata and controls
854 lines (717 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Portions created by the Adobe Systems Incorporated are Copyright (C) 2004
* Adobe Systems Incorporated. All Rights Reserved.
*
* Contributor(s):
* Adobe Systems Incorporated
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var acrobatDebugger = new Debugger();
acrobatDebugger.addAllGlobalsAsDebuggees();
/***************************************************************************/
// The following code "exports" any strings in the list into the current scope.
var msgStrings = new Array(
"IDS_STARTUP_DEBUGGER_MSG",
"IDS_INVALID_BREAKPOINT",
"IDS_EXCEPTION_INLINE",
"IDS_UNABLE_FINDSOURCE",
"IDS_TOP_LEVEL",
"IDS_INVALID_BPLINE",
"IDS_STACK_STRING",
"IDS_CANNOT_EVALWATCH");
for(var n = 0; n < msgStrings.length; n++)
eval(msgStrings[n] + " = " + getString("EScript", msgStrings[n]).toSource());
/************************* Stepping *************************/
// Current Line to track progress while stepping
var currLine = 1;
function onStepHandler() {
// This function can ONLY be called once handler is set in step() method
currentFrameIndex = 0;
buildStack();
var sc = this.script;
var offset = this.offset;
var line = sc.getOffsetLine(offset);
var file = sc.url;
if(line == currLine) {
// Not progressed enough. Return from this call and wait for next one
return undefined;
}
// Haven't returned => progressed
unsuspend();
var bps = sc.getBreakpoints(offset);
if (bps.length > 0) { // Breakpoint exists
resume();
} else {
resumeCode = -1;
openDebugger();
selectLine(file, line, 0);
suspendThread();
}
};
function onPopHandler() {
// This function can ONLY be called once handler is set in step() method
currentFrameIndex = 0;
buildStack();
var sc = this.script;
var offset = this.offset;
var line = sc.getOffsetLine(offset);
var file = sc.url;
currLine = line;
unsuspend();
// Set previous frames's onStep handler
var prevFrame = this.older;
if(prevFrame != null)
prevFrame.onStep = onStepHandler;
};
function onStepInstructionHandler() {
// This function can ONLY be called once handler is set in step() method
currentFrameIndex = 0;
buildStack();
var sc = this.script;
var offset = this.offset;
var line = sc.getOffsetLine(offset);
var file = sc.url;
unsuspend();
resumeCode = -1;
openDebugger();
selectLine(file, line, 0);
suspendThread();
};
function step(type) {
// type 0 => Step byte-code
// type 1 => Step in (step)
// type 2 => Step over (next)
// type 3 => Step out (pop)
if(type == 1) {
// Stepping in :
// So new frame should have the handler set.
// Otherwise not.
acrobatDebugger.onEnterFrame = function (frame) {
frame.onStep = onStepHandler;
}
}
var currentFrame = acrobatDebugger.getNewestFrame();
while(currentFrame.type == "eval") {
currentFrame = currentFrame.older;
}
if(type == 1 || type == 2) {
// Stepping over OR Stepping in :
// Set handler for current plus all parent frames
currentFrame.onStep = onStepHandler;
var parentFrame = currentFrame.older;
while(parentFrame) {
parentFrame.onStep = onStepHandler;
parentFrame = parentFrame.older;
}
}
if(type == 3) {
// Stepping out :
currentFrame.onPop = onPopHandler;
}
if(type == 0) {
acrobatDebugger.onEnterFrame = function (frame) {
frame.onStep = onStepInstructionHandler;
}
currentFrame.onStep = onStepInstructionHandler;
var parentFrame = currentFrame.older;
while(parentFrame) {
parentFrame.onStep = onStepInstructionHandler;
parentFrame = parentFrame.older;
}
}
// Get the current line to track progress
var sc = currentFrame.script;
var offset = currentFrame.offset;
var line = sc.getOffsetLine(offset);
currLine = line;
resume();
}
function disableAllHandlers() {
acrobatDebugger.onEnterFrame = undefined;
var cFrame = acrobatDebugger.getNewestFrame();
while(cFrame != null) {
cFrame.onStep = undefined;
cFrame.onPop = undefined;
cFrame = cFrame.older;
}
}
/************************* Interrupt Handler *************************/
function interruptHandler() {
// Very similar to onStepHandler and used as step handler of interrupt icon
currentFrameIndex = 0;
buildStack();
unsuspend();
var sc = this.script;
var offset = this.offset;
var line = sc.getOffsetLine(offset);
var file = sc.url;
acrobatDebugger.onEnterFrame = undefined;
this.onStep = undefined;
resumeCode = -1;
openDebugger();
selectLine(file, line, 0);
suspendThread();
currLine = line;
};
function unsuspend() {
disableAllHandlers();
clearInterrupt();
}
function suspend() {
disableAllHandlers();
acrobatDebugger.onEnterFrame = function (frame) {
frame.onStep = interruptHandler;
}
var currentFrame = acrobatDebugger.getNewestFrame();
var tFrame = currentFrame;
while(tFrame) {
tFrame.onStep = interruptHandler;
tFrame = tFrame.older;
}
setInterrupt();
}
// We need to maintain a stack instead of scalar for the case of consecutive save calls
var saveHandlerStack = [];
// Calls to saveAllHandlers() and restoreAllHandlers() should be matched 1-1
function saveAllHandlers() {
var saveHandlerObject = { onEnterFrameHandler : undefined, onStepHandler :[], onPopHandler :[],};
saveHandlerObject.onEnterFrameHandler = acrobatDebugger.onEnterFrame;
var cFrame = acrobatDebugger.getNewestFrame();
while(cFrame != null) {
saveHandlerObject.onStepHandler.push(cFrame.onStep);
saveHandlerObject.onPopHandler.push(cFrame.onPop);
cFrame = cFrame.older;
}
saveHandlerStack.push(saveHandlerObject);
}
function restoreAllHandlers() {
var saveHandlerObject = saveHandlerStack.pop();
acrobatDebugger.onEnterFrame = saveHandlerObject.onEnterFrameHandler;
var cFrame = acrobatDebugger.getNewestFrame();
var i = 0;
while(cFrame != null && i < saveHandlerObject.onStepHandler.length) {
cFrame.onStep = saveHandlerObject.onStepHandler[i];
cFrame.onPop = saveHandlerObject.onPopHandler[i];
cFrame = cFrame.older;
i++;
}
saveHandlerStack.pop();
}
/************************* Script & Function Listing *************************/
function scriptExists(fileName) {
if(scriptList[fileName])
return true;
else
return false;
}
function listChildScriptFunctions(script) {
var chScripts = script.getChildScripts();
for( var i=0; i < chScripts.length ; i++) {
var chScript = chScripts[i];
printFunction(chScript.displayName, chScript.startLine);
listChildScriptFunctions(chScript);
}
}
function listScriptFunctions(fileName) {
var script = scriptList[fileName];
if(script) {
var childScripts = script.getChildScripts();
if(childScripts.length > 0) {
if(script.staticLevel == 0) {
printFunction(IDS_TOP_LEVEL, script.startLine);
}
listChildScriptFunctions(script);
}
}
}
/************************* Breakpoints *************************/
function findScriptInSubtreeForLine(script, lineNo) {
var sc = script;
var offsets = sc.getLineOffsets(lineNo);
if(offsets.length >0)
return sc;
var chScripts = sc.getChildScripts();
for(var i=0; i<chScripts.length ; i++) {
var chScript = chScripts[i];
var foundScript = findScriptInSubtreeForLine(chScript, lineNo);
if(foundScript)
return foundScript;
}
return null;
}
acrobatDebugger.onNewScript = function(script) {
// Following check is a safe-guard to guarantee that we update scriptList and bpList and breakpoints only for top-level scripts
if(script.staticLevel == 0 && script.sourceLength == script.source.text.length && script.sourceStart == 0) {
if(scriptList[script.url] != script) {
scriptList[script.url] = script;
}
for(var i=0 ; i < bpList.length ; i++ ) {
if(script.url == bpList[i].fileName) {
var sc = findScriptInSubtreeForLine(script, bpList[i].lineNum);
if(sc != null) {
bpList[i].script = sc;
bpList[i].offsets = sc.getLineOffsets(bpList[i].lineNum);
for(var j=0; j < bpList[i].offsets.length ; j++) {
bpList[i].script.setBreakpoint(bpList[i].offsets[j], bpHandler);
}
} else {
delete bpList[i];
bpList.splice(i, 1);
i--;
saveBreakpoints();
}
}
}
}
}
function updateBreakpointsForScript(fileName) {
for(var i = 0; i < bpList.length; i++) {
if (bpList[i].fileName == fileName) {
updateBreakpoint(true, bpList[i].lineNum, i, fileName, bpList[i].condition);
for(var j=0; j < bpList[i].offsets.length ; j++ ) {
var bps = bpList[i].script.getBreakpoints(bpList[i].offsets[j]);
if(bps.length == 0) // No existing breakpoint, then set
bpList[i].script.setBreakpoint(bpList[i].offsets[j], bpHandler);
}
}
}
}
function canSetBreakpointInInternalScripts(script, lineNo) {
var sc = script;
var offsets = sc.getLineOffsets(lineNo);
if(offsets.length >0)
return true;
var chScripts = sc.getChildScripts();
for(var i=0; i<chScripts.length ; i++) {
var chScript = chScripts[i];
var found = canSetBreakpointInInternalScripts(chScript, lineNo);
if(found)
return true;
}
return false;
}
function canSetBreakpoint(fileName, lineNum) {
if(scriptList[fileName]) {
var sc = scriptList[fileName];
return canSetBreakpointInInternalScripts(sc,lineNum);
}
return false;
}
// File name to Script 1-1 map
// Needed for canSetBreakpoint as we set BP icons before setting BP on actual script
var scriptList = {};
// Data structure to store array of breakpoints
var bpList = [];
function Breakpoint(pddHandle, fileName, lineNum, script, offsets, condition) {
this.pddHandle = pddHandle;
this.fileName = fileName;
this.lineNum = lineNum;
this.script = script;
this.offsets = offsets;
this.condition = condition;
this.isSet = false;
}
function getBPIndex(fileName, lineNum) {
for(var i = 0; i < bpList.length; i++)
if (bpList[i].fileName == fileName && bpList[i].lineNum == lineNum)
return i;
return -1;
}
function pcMapExists(fileName) {
if(scriptList[fileName])
return true;
else
return false;
}
// Breakpoint handler
const bpHandler = {
hit: function(frame)
{
currentFrameIndex = 0;
buildStack();
unsuspend();
var sc = frame.script;
var offset = frame.offset;
var line = sc.getOffsetLine(offset);
var file = sc.url;
//BP Condition
var bpIndex = getBPIndex(file, line);
var conditionVal = debugEval(bpList[bpIndex].condition);
if(conditionVal == false || conditionVal == undefined || conditionVal == null || conditionVal == 0)
return;
resumeCode = -1;
openDebugger();
selectLine(file, line, 0);
suspendThread();
}
};
function setBreakpoint(pddHandle, fileName, lineNum, condition) {
var bpCreate = canSetBreakpoint(fileName, lineNum);
if(bpCreate) { // Line number is valid for breakpoint
var bpIndex = getBPIndex(fileName, lineNum);
if (bpIndex == -1) { // Breakpoint does not exist already
if(scriptList[fileName]) { // Script is in debugger window
var sc = scriptList[fileName];
sc = findScriptInSubtreeForLine(sc, lineNum);
if(sc == null)
return;
var offsets = sc.getLineOffsets(lineNum);
for(var j=0; j<offsets.length ; j++) {
var offset = offsets[j];
sc.setBreakpoint(offset, bpHandler);
}
if(offsets.length > 0) {
var theCondition = (condition == undefined) ? "true" : condition;
bpList[bpList.length] = new Breakpoint(pddHandle, fileName, lineNum, sc, offsets, theCondition);
updateBreakpoint(true, lineNum, bpList.length-1, fileName, theCondition);
saveBreakpoints();
}
}
}
}
}
function clearBreakpoint(fileName, lineNum) {
var bpCreate = canSetBreakpoint(fileName, lineNum);
if(bpCreate) { // Line number is valid for breakpoint
var bpIndex = getBPIndex(fileName, lineNum);
if (bpIndex != -1) { // Breakpoint exists
if(scriptList[fileName]) { // Script is in debugger window
var sc = scriptList[fileName];
sc = findScriptInSubtreeForLine(sc, lineNum);
if(sc == null)
return;
var offsets = sc.getLineOffsets(lineNum);
for(var j=0; j<offsets.length ; j++) {
var offset = offsets[j];
sc.clearAllBreakpoints(offset);
}
if(offsets.length>0) {
delete bpList[bpIndex];
bpList.splice(bpIndex,1);
updateBreakpoint(false, lineNum, bpIndex, fileName, "");
saveBreakpoints();
}
}
}
}
}
function toggleBreakpoint(pddHandle, fileName, lineNum, condition) {
var bpIndex = getBPIndex(fileName, lineNum);
if (bpIndex == -1)
setBreakpoint(pddHandle, fileName, lineNum, condition);
else
clearBreakpoint(fileName, lineNum);
}
// This function gets called at document close
function clearBreakpointsForDoc(pddHandle) {
var fileNames = [];
// Clean-up Breakpoint list
for(var i = 0; i < bpList.length; i++) {
if (bpList[i].pddHandle == pddHandle) {
updateBreakpoint(false, bpList[i].lineNum, i, bpList[i].fileName, bpList[i].condition);
fileNames.push(bpList[i].fileName);
delete bpList[i];
bpList.splice(i, 1);
i--;
saveBreakpoints();
}
}
// Clean-up Script list
for(var fileName in fileNames) {
if(scriptList[fileName]) {
scriptList[fileName] = undefined;
}
}
}
function changeBPCondition(i, newCondition) {
if (i >= 0 && i < bpList.length && newCondition) {
bpList[i].condition = newCondition;
updateBreakpoint(true, bpList[i].lineNum, i, bpList[i].fileName, bpList[i].condition);
saveBreakpoints();
}
}
/******************* Save Breakpoints in Document *******************/
function enumBreakpoints() {
if(bpList.length > 0) {
for(var i = 0; i < bpList.length; i++)
regBreakpoint(i, bpList[i].fileName, bpList[i].lineNum, bpList[i].condition);
} else {
regBreakpoint(-1); // Clear last breakpoint
}
}
function setBreakpoints(pddHandle, bpArray) {
for(var i = 0; i < bpArray.length; i++) {
var fileName = bpArray[i].fileName;
if (fileName.substr(fileName.length - 3) != ".js") {
if(pcMapExists(fileName) == false) {
compileScript(fileName);
}
setBreakpoint(pddHandle, fileName, bpArray[i].lineNum, bpArray[i].condition);
}
}
}
/************************* Inspect State *************************/
// Current frame to show variables and text of that fame.
// User can select from UI. It should be top frame while hitting a breakpoint and stepping.
var currentFrameIndex;
// The stack data structure shown in debugger UI
var jsStack = null;
function selectFrame(frameNum) {
currentFrameIndex = frameNum;
var currFrame = jsStack[currentFrameIndex];
if(currFrame) {
selectLine(currFrame.file, currFrame.lineno, frameNum);
} else {
// No Current frame!!
}
}
function JSDFrame(frame) {
this.frame = frame;
this.file = frame.script.url;
this.lineno = frame.script.getOffsetLine(frame.offset);
}
function buildStack() {
jsStack = [];
var currentFrame = acrobatDebugger.getNewestFrame();
while(currentFrame != null) {
jsStack.push(new JSDFrame(currentFrame));
currentFrame = currentFrame.older;
}
}
function JSDProperty(propValue, readOnly) {
this.value = propValue;
this.type = ( (typeof propValue == "object") ? "o" : "" ) +
( (typeof propValue == "number") ? ( Number.isInteger(propValue) ? "i" : "d") : "" ) +
( (typeof propValue == "string") ? "s" : "" ) +
( (typeof propValue == "boolean") ? "b" : "" ) +
( (typeof propValue == "undefined")? "u" : "" ) +
( readOnly ? "r" : "w" );
if(propValue) {
if(typeof propValue == "object") {
this.valString = propValue.unsafeDereference().toString();
} else {
this.valString = propValue.toString();
}
} else {
this.valString = new String(propValue);
}
// If this is a null value, display empty string instead
if(this.valString == null)
this.valString = "";
}
// Used in listRecursive. To detect change of frame and clearing the inspector window
// The expansion feature requires that we do not clear the window if frame is not changed
var curScriptFrameThis = null;
var curScriptFrameScope = null;
function listRecursive(bThis) {
if (jsStack) {
var currFrame = jsStack[currentFrameIndex].frame;
if(!currFrame.live)
return;
var callObjHandle;
if(bThis) {
callObjHandle = currFrame.this;
if(curScriptFrameThis != currFrame) {
clearInspector();
curScriptFrameThis = currFrame;
}
} else {
callObjHandle = currFrame.environment;
if(curScriptFrameScope != currFrame) {
clearInspector();
curScriptFrameScope = currFrame;
}
}
// We do not want to halt due to any debuggee calls from displayRecursive().
// So saving, disabling and then restoring all execution handlers
saveAllHandlers();
disableAllHandlers();
displayRecursive(callObjHandle,0);
restoreAllHandlers();
} else {
clearInspector();
}
}
function displayRecursive(callObjHandle,tab) {
if(callObjHandle) {
var currFrame = jsStack[currentFrameIndex].frame;
if(callObjHandle instanceof Debugger.Environment) {
var names = callObjHandle.names().sort();
var entryID = 0;
for(var i = 0; i < names.length ; i++) {
var name = names[i];
var prop = callObjHandle.getVariable(name);
var isReadOnly = false; // TODO : check mutability of local variables
if(typeof prop == "object") {
if(prop && prop.callable){
// Do not show functions
continue;
}
var propJSDObj = new JSDProperty(prop, isReadOnly);
var isExpanded = printInspector(tab, entryID, propJSDObj.type, name, propJSDObj.valString);
if( isExpanded && propJSDObj.type[0] == "o") {
displayRecursive(prop, tab+1);
}
} else {
var propJSDObj = new JSDProperty(prop, isReadOnly);
printInspector(tab, entryID, propJSDObj.type, name, propJSDObj.valString);
}
entryID++;
}
}
else if(callObjHandle instanceof Debugger.Object) {
var protoValue = callObjHandle.proto;
if(protoValue) {
var protoJSDObj = new JSDProperty(protoValue, false);
var isExpanded = printInspector(tab, 0, protoJSDObj.type, "[[Prototype]]", protoJSDObj.valString);
if( isExpanded && protoJSDObj.type[0] == "o") {
displayRecursive(protoValue, tab+1);
}
}
var names = callObjHandle.getOwnPropertyNames().sort();
var entryID = 1;
for(var i = 0; i < names.length ; i++) {
var name = names[i];
var pd = callObjHandle.getOwnPropertyDescriptor(name);
var prop = pd.value;
if(typeof prop == "object") {
if(prop && prop.callable){
// Do not show functions
continue;
}
var propJSDObj = new JSDProperty(prop, !pd.writable);
var isExpanded = printInspector(tab, entryID, propJSDObj.type, name, propJSDObj.valString);
if( isExpanded && propJSDObj.type[0] == "o") {
displayRecursive(prop, tab+1);
}
} else {
var propJSDObj = new JSDProperty(prop, !pd.writable);
printInspector(tab, entryID, propJSDObj.type, name, propJSDObj.valString);
}
entryID++;
}
}
}
}
function where() {
if (jsStack) {
for(var i = 0; i < jsStack.length; i++) {
var displayString = IDS_STACK_STRING.replace('%d', jsStack[i].lineno);
var funcName = (jsStack[i].frame.callee) ? jsStack[i].frame.callee.displayName : IDS_TOP_LEVEL;
displayString = displayString.replace('%s', funcName);
printStack(displayString);
}
}
}
/************************* Exception Handling *************************/
const TMODE_IGNORE = 0;
const TMODE_TRACE = 1;
const TMODE_BREAK = 2;
acrobatDebugger.onExceptionUnwind = function (frame, ex) {
var frameUrl = frame.script && frame.script.url;
if (frameUrl === "self-hosted" )
return undefined;
var tMode = getThrowMode();
switch (tMode) {
case TMODE_IGNORE:
return undefined;
case TMODE_TRACE:
case TMODE_BREAK:
var frameName = (frame.callee) ? frame.callee.displayName : IDS_TOP_LEVEL;
var line = frame.script.getOffsetLine(frame.offset);
var displayString = IDS_EXCEPTION_INLINE.replace('%d', line);
displayString = displayString.replace('%s', frameName);
displayString = displayString.replace('%s', frameUrl);
printConsole(displayString);
if(tMode == TMODE_BREAK) {
interruptHandler.call(frame);
}
return undefined;
default:
return false;
}
return undefined;
}
acrobatDebugger.uncaughtExceptionHook = function (ex) {
return undefined;
};
/************************* Miscellaneous *************************/
function enableDebugger() {
acrobatDebugger.enabled = true;
}
function quit(code) {
jsStack = null;
curScriptFrameThis = null;
curScriptFrameScope = null;
clearStack();
clearInspector();
unsuspend();
resume();
if(code == 1) // Terminate
acrobatDebugger.enabled = false;
}
function resume() {
// resumeCode is defined in C++
// resumeCode 0 => Progress execution
// resumeCode -1 => Halt
resumeCode = 0;
}
function debugEval(text) {
if (jsStack) {
var currFrame = jsStack[currentFrameIndex].frame;
var retVal = currFrame.eval(text).return;
if(typeof retVal == "object") {
return retVal.unsafeDereference();
} else {
return retVal;
}
}
return undefined;
}
function watch(i, text) {
if (jsStack && text != "") {
var ret = debugEval(text);
printWatch(i, text, ret.toString());
} else {
printWatch(i, text, IDS_CANNOT_EVALWATCH);
}
}
function changeLocal(varName, value, bThis) {
if (jsStack) {
var ret = debugEval(varName + " = " + value + ";");
listRecursive(bThis);
}
}