summaryrefslogtreecommitdiff
blob: 3dcc41f369d27f31c7f59dec337ed2e85b3dbd15 (plain)
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
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/CompilationUnit.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/CompilationUnit.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/CompilationUnit.java	2002-11-12 23:28:54.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/CompilationUnit.java	2004-07-07 21:12:16.131818792 -0600
@@ -74,7 +74,7 @@
  * of script is sliced into compilation units.
  * For instance, the script text may contain a function
  * declaration and an expression to eval. The compilation
- * will result in two compilation units: the function and 
+ * will result in two compilation units: the function and
  * the expression. Each compilation unit will correspond
  * to a range of the lines of the original script compiled.
  * All line numbers are global to the document the compiled
@@ -82,89 +82,95 @@
  * It is on compilation units that breakpoints can be set
  * or removed, more exactly on the DebuggableScript attached
  * to them. See Rhino for more details.
- * 
+ *
  * @author: Olivier Gruber.
- */ 
+ */
 public class CompilationUnit {
 
-	FnOrScript m_fnOrScript;
-	int m_firstLine;
-	int m_lineCount;
-	String m_fnName;
-	DebuggableScript m_dbgScript;
-	int m_validBrkptLines[];
-
-	/**
-	 * CompilationUnit constructor comment.
-	 */
-	public CompilationUnit(FnOrScript fnOrScript, DebuggableScript dbgScript) {
-
-		int lastLine, lineno;
-
-		m_fnOrScript = fnOrScript;
-		m_dbgScript = dbgScript;
-
-		try {
-			m_validBrkptLines = dbgScript.getLineNumbers();
-			m_firstLine = 99999;
-			lastLine = 0;
-			for (int l = 0; l < m_validBrkptLines.length; l++) {
-				lineno = m_validBrkptLines[l];
-				if (m_firstLine > lineno)
-					m_firstLine = lineno;
-				if (lastLine < lineno)
-					lastLine = lineno;
-			}
-			m_lineCount = lastLine - m_firstLine + 1;
-		} catch (Throwable t) {
-			DebugLog.stderrPrintln("\nWarning: can't get valid line numbers for breakpoints.", DebugLog.BSF_LOG_L2);
-			m_validBrkptLines = null;
-		}
-
-		Scriptable scriptable = dbgScript.getScriptable();
-		if (scriptable instanceof NativeFunction) {
-			NativeFunction f = (NativeFunction) scriptable;
-			String name = f.getFunctionName();
-			if (name.length() > 0 && !name.equals("anonymous")) {
-				m_fnName = name;
-			}
-		}
-	}
-	//----------------------------------------------------------
-	boolean contains(int lineno) {
-		return (m_firstLine <= lineno && lineno < m_firstLine + m_lineCount);
-	}
-	/**
-	 * Returns true if the compilation unit contains
-	 * the breakpoint. 
-	 * Notice only breakpoint defined at a line number
-	 * are supported here.
-	 */
-	boolean contains(BreakPoint bp) {
-		try {
-			return contains(bp.getLineNo());
-		} catch (BSFException ex) {
-			return false;
-		}
-	}
-	/**
-	 * Propagates (i.e. set) this breakpoint to the underlying Rhino
-	 * engine if Rhino has provided us with the valid lines
-	 * information. Otherwise, Rhino crashes with a NullPointerException.
-	 */
-	void propagate(int lineno) {
-		if (m_validBrkptLines != null) {
-			m_dbgScript.placeBreakpoint(lineno);
-		}
-	}
-	/**
-	 * Unpropagates (i.e. unset) this breakpoint to the underlying Rhino
-	 * engine if Rhino has provided us with the valid lines
-	 * information. Otherwise, Rhino crashes with a NullPointerException.
-	 */
-	void unpropagate(int lineno) {
-		if (m_validBrkptLines != null) {
-			m_dbgScript.removeBreakpoint(lineno);
-		}
-	}
+    FnOrScript m_fnOrScript;
+    int m_firstLine;
+    int m_lineCount;
+    String m_fnName;
+    DebuggableScript m_dbgScript;
+    boolean[] m_breakpoints;
+
+    /**
+     * CompilationUnit constructor comment.
+     */
+    public CompilationUnit(FnOrScript fnOrScript, DebuggableScript dbgScript) {
+
+        m_fnOrScript = fnOrScript;
+        m_dbgScript = dbgScript;
+
+        int[] lines = dbgScript.getLineNumbers();
+        if (lines.length != 0) {
+            int lastLine;
+            m_firstLine = lines[0];
+            lastLine = m_firstLine;
+            for (int i = 1; i != lines.length; ++i) {
+                int lineno = lines[i];
+                if (m_firstLine > lineno) {
+                    m_firstLine = lineno;
+                } else if (lastLine < lineno) {
+                    lastLine = lineno;
+                }
+            }
+            m_lineCount = lastLine - m_firstLine + 1;
+            m_breakpoints = new boolean[m_lineCount];
+        }
+
+        String name = dbgScript.getFunctionName();
+        if (name != null && name.length() != 0 && !name.equals("anonymous")) {
+            m_fnName = name;
+        }
+    }
+    //----------------------------------------------------------
+    boolean contains(int lineno) {
+        return (m_firstLine <= lineno && lineno < m_firstLine + m_lineCount);
+    }
+    /**
+     * Returns true if the compilation unit contains
+     * the breakpoint.
+     * Notice only breakpoint defined at a line number
+     * are supported here.
+     */
+    boolean contains(BreakPoint bp) {
+        try {
+            return contains(bp.getLineNo());
+        } catch (BSFException ex) {
+            return false;
+        }
+    }
+    /**
+     * Set a breakpoint at the given line if Rhino has provided us with the
+     * valid lines information.
+     */
+    void propagate(int lineno) {
+        if (m_breakpoints != null) {
+            int i = lineno - m_firstLine;
+            if (0 <= i && i < m_lineCount) {
+                m_breakpoints[i] = true;
+            }
+        }
+    }
+    /**
+     * Clear a breakpoint at the given line if Rhino has provided us with the
+     * valid lines information.
+     */
+    void unpropagate(int lineno) {
+        if (m_breakpoints != null) {
+            int i = lineno - m_firstLine;
+            if (0 <= i && i < m_lineCount) {
+                m_breakpoints[i] = false;
+            }
+        }
+    }
+
+    boolean hasBreakpoint(int lineno) {
+        if (m_breakpoints != null) {
+            int i = lineno - m_firstLine;
+            return 0 <= i && i < m_lineCount && m_breakpoints[i];
+        }
+        return false;
+    }
 }
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/FnOrScript.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/FnOrScript.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/FnOrScript.java	2002-11-12 23:28:54.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/FnOrScript.java	2004-07-07 21:12:16.132818640 -0600
@@ -71,25 +71,25 @@
  * This class represents a function or script, that is,
  * a piece of a document that is provided to the JavaScript
  * engine for evaluation, execution, or simply compilation.
- * 
+ *
  * A FnOrScript represents a range of lines or characters
- * in its document. For now, Rhino only supports ranges 
+ * in its document. For now, Rhino only supports ranges
  * of lines, really, but the code for offsets is there anyway.
  *
  * Warning: Offsets have never been quite tested yet...
- * 
+ *
  * A FnOrScript has compilation units. When Rhino compiles
  * a function or a script, even in interpreted mode where the
  * compilation is done to JavaScript bytecode, it calls back
- * its debugger with different compilation units; see 
+ * its debugger with different compilation units; see
  * Debugger::handleCompilationDone method on the RhinoEngineDebugger
  * class.
  *
  * A FnOrScript also keeps track of the known breakpoints
  * in its range of lines or characters. It makes sure
- * that they are propagated to the underlying Rhino 
+ * that they are propagated to the underlying Rhino
  * engine (i.e. set) as well as unpropagated (i.e. unset).
- *  
+ *
  * @author: Olivier Gruber
  */
 public class FnOrScript {
@@ -103,9 +103,11 @@
 
     protected StringBuffer m_text;
 
-    protected Vector m_units; // of CompilationUnit.
     protected Script m_script;
 
+    private Vector m_units; // of CompilationUnit.
+    private Hashtable m_functionToUnit;
+
     protected Hashtable m_functionMap;
 
     public FnOrScript(DocumentCell cell) {
@@ -116,8 +118,9 @@
         m_lineCount = 0;
         m_breakpoints = new Vector();
         m_text = new StringBuffer();
-	
+
         m_units = new Vector();
+        m_functionToUnit = new Hashtable();
         m_functionMap = new Hashtable();
     }
 
@@ -131,7 +134,7 @@
 
         m_breakpoints.addElement(bp);
 
-        // now, look for a unit containing it and 
+        // now, look for a unit containing it and
         // if one is found, set the breakpoint unit
         // and propagate...
         Enumeration e;
@@ -147,7 +150,7 @@
         }
         return bp;
     }
-	
+
     private BreakPoint _removeBreakpoint(int brkptId) {
         Enumeration e;
         BreakPoint bp;
@@ -173,13 +176,13 @@
             bp = (BreakPoint) e.nextElement();
             if (bpid == bp.getId()) {
                 m_breakpoints.removeElement(bp);
-                bp.unpropagate();	
+                bp.unpropagate();
                 return bp;
             }
         }
         return null;
     }
-	
+
     boolean contains(BreakPoint bp) throws BSFException {
         if (m_lineDefined) {
             int line = bp.getLineNo();
@@ -194,7 +197,7 @@
     // This protected method works as a factory
     // for language-specific breakpoints.
     // The default behavior is to use the provided
-    // generic breakpoint. 
+    // generic breakpoint.
     // See javascript for an example of language-specific
     // breakpoints.
 
@@ -360,17 +363,18 @@
 
     public void addCompilationUnit(Context cx,
                                    DebuggableScript dbgScript,
-                                   StringBuffer source) {
+                                   String source) {
 
         CompilationUnit unit;
 
         unit = new CompilationUnit(this, dbgScript);
         m_units.addElement(unit);
+        m_functionToUnit.put(dbgScript, unit);
         if (unit.m_fnName != null) {
             m_functionMap.put(unit.m_fnName, unit);
         }
 
-        // Associate breakpoints to this unit if 
+        // Associate breakpoints to this unit if
         // the unit contains them...
         Enumeration e;
         BreakPoint bp;
@@ -383,13 +387,17 @@
         propagateAll();
     }
 
+    CompilationUnit getCompilationUnit(DebuggableScript dbgScript) {
+        return (CompilationUnit)m_functionToUnit.get(dbgScript);
+    }
+
     public void compile(Context cx, Scriptable global)
         throws BSFException, IOException {
 
         Enumeration e;
         Reader reader = new StringReader(m_text.toString());
         m_script =
-            cx.compileReader(global, reader, m_cell.getName(), 
+            cx.compileReader(global, reader, m_cell.getName(),
                              m_startLine, null);
         if (m_script == null)
             throw new BSFException("Compilation of the script "
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JavaScriptEngine.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JavaScriptEngine.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JavaScriptEngine.java	2002-11-12 23:28:54.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JavaScriptEngine.java	2004-07-07 21:12:16.133818488 -0600
@@ -104,7 +104,7 @@
     public void disconnectedDebuggerNotify() {
         m_rhinoDbg.disconnectedDebuggerNotify();
     }
-	
+
     BSFDebugManagerImpl getDebugManager() {
         return dbgmgr;
     }
@@ -114,7 +114,7 @@
         m_rhinoDbg.placeBreakpointAtLine(brkptid, docname, lineno);
     }
 
-    public void placeBreakpointAtOffset(int brkptid, String docname, 
+    public void placeBreakpointAtOffset(int brkptid, String docname,
                                         int offset) throws BSFException {
         m_rhinoDbg.placeBreakpointAtOffset(brkptid, docname, offset);
     }
@@ -140,7 +140,6 @@
     public Object call(Object object, String method, Object[] args)
         throws BSFException {
         Object theReturnValue = null;
-        DebuggableEngine engine;
         Context cx;
         try {
 
@@ -160,13 +159,12 @@
 
                 cx.setOptimizationLevel(-1);
 
-                engine = cx.getDebuggableEngine();
-                engine.setDebugger(m_rhinoDbg);
+                cx.setDebugger(m_rhinoDbg, new RhinoContextProxy(m_rhinoDbg));
 
-                theReturnValue = ScriptRuntime.call(cx, fun, global, args, 
+                theReturnValue = ScriptRuntime.call(cx, fun, global, args,
                                                     null);
 
-            } 
+            }
             else {
                 cx.setOptimizationLevel(-1);
 
@@ -175,10 +173,9 @@
 
                 cx.setOptimizationLevel(0);
 
-                engine = cx.getDebuggableEngine();
-                engine.setDebugger(null);
+                cx.setDebugger(null, null);
 
-                theReturnValue = ScriptRuntime.call(cx, fun, global, args, 
+                theReturnValue = ScriptRuntime.call(cx, fun, global, args,
                                                     null);
             }
             if (theReturnValue instanceof Wrapper) {
@@ -193,9 +190,15 @@
     }
 
     public void declareBean(BSFDeclaredBean bean) throws BSFException {
-        // Must wrap non-scriptable objects before presenting to Rhino
-        Scriptable wrapped = Context.toObject(bean.bean, global);
-        global.put(bean.name, global, wrapped);
+        if ((bean.bean instanceof Number) ||
+            (bean.bean instanceof String) ||
+            (bean.bean instanceof Boolean)) {
+            global.put(bean.name, global, bean.bean);
+        } else {
+            // Must wrap non-scriptable objects before presenting to Rhino
+            Scriptable wrapped = Context.toObject(bean.bean, global);
+            global.put(bean.name, global, wrapped);
+        }
     }
 
     /**
@@ -210,7 +213,6 @@
         DocumentCell cell;
         FnOrScript fnOrScript;
         Script script;
-        DebuggableEngine engine;
         Context cx;
 
         try {
@@ -231,13 +233,7 @@
 
                 cx.setOptimizationLevel(-1);
 
-                engine = cx.getDebuggableEngine();
-                engine.setDebugger(m_rhinoDbg);
-
-                // Muck w/ this iff someone else hasn't already got it true
-                if (!engine.getBreakNextLine()) {
-                    engine.setBreakNextLine(cell.getEntryExit());
-                }
+                cx.setDebugger(m_rhinoDbg, new RhinoContextProxy(m_rhinoDbg));
 
                 fnOrScript.compile(cx, global);
                 m_rhinoDbg.setCompilingFnOrScript(null);
@@ -245,7 +241,7 @@
 
                 if (script != null) retval = script.exec(cx, global);
                 else retval = null;
-            } 
+            }
             else {
                 cx.setOptimizationLevel(-1);
 
@@ -254,11 +250,10 @@
 
                 cx.setOptimizationLevel(0);
 
-                engine = cx.getDebuggableEngine();
-                engine.setDebugger(null);
+                cx.setDebugger(null, null);
 
                 retval = cx.evaluateString(global, scriptText,
-                                           source, lineNo, 
+                                           source, lineNo,
                                            null);
             }
 
@@ -296,14 +291,14 @@
                 // Display its stack trace as a diagnostic
                 target = (Throwable) value;
             }
-        } 
-        else if (t instanceof EvaluatorException || 
+        }
+        else if (t instanceof EvaluatorException ||
                  t instanceof SecurityException) {
             message = t.getLocalizedMessage();
-        } 
+        }
         else if (t instanceof RuntimeException) {
             message = "Internal Error: " + t.toString();
-        } 
+        }
         else if (t instanceof StackOverflowError) {
             message = "Stack Overflow";
         }
@@ -313,7 +308,7 @@
         }
 
         //REMIND: can we recover the line number here?  I think
-        // Rhino does this by looking up the stack for bytecode 
+        // Rhino does this by looking up the stack for bytecode
         // see Context.getSourcePositionFromStack()
         // but I don't think this would work in interpreted mode
 
@@ -323,7 +318,7 @@
             // corrected the situation by aborting the loop and
             // a long stacktrace would end up on the user's console
             throw (Error) t;
-        } 
+        }
         else {
             throw new BSFException(BSFException.REASON_OTHER_ERROR,
                                    "JavaScript Error: " + message,
@@ -333,7 +328,7 @@
 
     /**
      * initialize the engine. put the manager into the context -> manager
-     * map hashtable too. 
+     * map hashtable too.
      */
     public void initialize(BSFManager mgr, String lang, Vector declaredBeans)
         throws BSFException {
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JsContextStub.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JsContextStub.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JsContextStub.java	2002-11-12 23:28:54.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JsContextStub.java	2004-07-07 21:12:16.135818184 -0600
@@ -68,235 +68,267 @@
 * @author: Administrator
 */
 
-public class JsContextStub 
+public class JsContextStub
 extends org.apache.bsf.debug.util.Skeleton
    implements JsContext {
 
-	RhinoContextProxy m_rcp;
-	RhinoEngineDebugger m_rhinoDbg;
-	DebugFrame m_frame;
-	int m_frameno;
-	boolean m_atBreakpoint;
-	boolean m_invalid;
-
-	/**
-	 * JsContextStub constructor comment.
-	 */
-	public JsContextStub(RhinoContextProxy rcp, DebugFrame frame, int frameno)
-	throws RemoteException {
-			super(org.apache.bsf.debug.util.DebugConstants.JS_CONTEXT_TID);
-		
-		m_rhinoDbg = rcp.getRhinoEngineDebugger();
-		m_rcp = rcp;
-		m_frame = frame;
-		m_frameno = frameno;
-		m_invalid = false;
-		m_atBreakpoint = true;
-	}
-	//--------------------------------------------------
-	void atBreakpoint(boolean atbrkpt) {
-		m_atBreakpoint = atbrkpt;
-	}
-	public JsObject bind(String id) throws RemoteException {
-		try {
-			Context.enter();
-			Scriptable obj = m_frame.getVariableObject();
-			Object prop;
-			while (obj != null) {
-				Scriptable m = obj;
-				do {
-					if (m.has(id, obj))
-						return m_rhinoDbg.marshallScriptable(obj);
-					m = m.getPrototype();
-				} while (m != null);
-				obj = obj.getParentScope();
-			}
-			throw new JsdiException("Name not in scope.");
-		} finally {
-			Context.exit();
-		}
-	}
-	//--------------------------------------------------
-	public JsCode getCode() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get the code.");
-
-		try {
-			Context.enter();
-			return null;
-		} finally {
-			Context.exit();
-		}
-	}
-	public int getDepth() {
-		return m_frameno;
-	}
-	//--------------------------------------------------
-	public JsEngine getEngine() {
-		RhinoEngineDebugger redbg;
-		redbg = m_rcp.getRhinoEngineDebugger();
-		return (JsEngine) redbg.getDebugInterface(); 
-		
-	}
-	//--------------------------------------------------
-	public int getLineNumber() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			return m_frame.getLineNumber();
-		} finally {
-			Context.exit();
-		}
-	}
-	//------------------------------------------------------  
-	public JsObject getScope() throws RemoteException {
-
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			Scriptable varobj = m_frame.getVariableObject();
-			JsObject scope = m_rhinoDbg.marshallScriptable(varobj);
-			return scope;
-		} finally {
-			Context.exit();
-		}
-	}
-	//------------------------------------------------------  
-	public String getSourceName() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			return m_frame.getSourceName();
-		} finally {
-			Context.exit();
-		}
-	}
-	//------------------------------------------------------  
-	public JsObject getThis() throws RemoteException {
-
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			JsObject thisobj = null;
-			Scriptable obj = null;
-			NativeCall call = null;
-			Scriptable varobj = m_frame.getVariableObject();
-			if (varobj instanceof NativeCall) {
-				call = (NativeCall) varobj;
-				obj = call.getThisObj();
-				thisobj = m_rhinoDbg.marshallScriptable(varobj);
-			}
-			return thisobj;
-		} finally {
-			Context.exit();
-		}
-	}
-	//--------------------------------------------------
-	void invalidate() {
-		m_invalid = true;
-	}
-	//------------------------------------------------------  
-	public boolean isEvalContext() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			return false;
-		} finally {
-			Context.exit();
-		}
-	}
-	//------------------------------------------------------  
-	public boolean isFunctionContext() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-
-		try {
-			Context.enter();
-			return false;
-		} finally {
-			Context.exit();
-		}
-	}
-	//------------------------------------------------------  
-	public boolean isScriptContext() {
-		if (m_invalid)
-			throw new JsdiException("This context no longer exists.");
-		if (!m_atBreakpoint)
-			throw new JsdiException("Resumed context, can't get line number.");
-		try {
-			Context.enter();
-			return true;
-		} finally {
-			Context.exit();
-		}
-	}
-	public Object lookupName(String name) {
-
-		try {
-			Context.enter();
-			Scriptable obj = m_frame.getVariableObject();
-			Object prop;
-			while (obj != null) {
-				Scriptable m = obj;
-				do {
-					Object result = m.get(name, obj);
-					if (result != Scriptable.NOT_FOUND)
-						return result;
-					m = m.getPrototype();
-				} while (m != null);
-				obj = obj.getParentScope();
-			}
-			throw new JsdiException("Name is not in scope.");
-		} finally {
-			Context.exit();
-		}
-	}
-	/**
-	 * Looks up a name in the scope chain and returns its value.
-	 */
-	public Object lookupName(Scriptable scopeChain, String id) {
-
-		try {
-			Context.enter();
-			Scriptable obj = scopeChain;
-			Object prop;
-			while (obj != null) {
-				Scriptable m = obj;
-				do {
-					Object result = m.get(id, obj);
-					if (result != Scriptable.NOT_FOUND)
-						return result;
-					m = m.getPrototype();
-				} while (m != null);
-				obj = obj.getParentScope();
-			}
-			return null;
-		} finally {
-			Context.exit();
-		}
-	}
+    RhinoContextProxy m_rcp;
+    RhinoEngineDebugger m_rhinoDbg;
+    int m_frameno;
+    int m_lineno;
+    boolean m_atBreakpoint;
+    boolean m_invalid;
+
+    CompilationUnit m_unit;
+    Scriptable m_variableObject;
+    Scriptable m_thisObj;
+
+    /**
+     * JsContextStub constructor comment.
+     */
+    JsContextStub(RhinoContextProxy rcp, CompilationUnit unit)
+    throws RemoteException {
+        super(org.apache.bsf.debug.util.DebugConstants.JS_CONTEXT_TID);
+
+        m_rhinoDbg = rcp.getRhinoEngineDebugger();
+        m_rcp = rcp;
+        m_unit = unit;
+        m_invalid = false;
+        m_atBreakpoint = true;
+    }
+
+    DebugFrame getRhinoDebugFrame() {
+        return new RhinoDebugFrame(this);
+    }
+
+    //--------------------------------------------------
+    void atBreakpoint(boolean atbrkpt) {
+        m_atBreakpoint = atbrkpt;
+    }
+    public JsObject bind(String id) throws RemoteException {
+        try {
+            Context.enter();
+            Scriptable obj = m_variableObject;
+            Object prop;
+            while (obj != null) {
+                Scriptable m = obj;
+                do {
+                    if (m.has(id, obj))
+                        return m_rhinoDbg.marshallScriptable(obj);
+                    m = m.getPrototype();
+                } while (m != null);
+                obj = obj.getParentScope();
+            }
+            throw new JsdiException("Name not in scope.");
+        } finally {
+            Context.exit();
+        }
+    }
+    //--------------------------------------------------
+    public JsCode getCode() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get the code.");
+
+        try {
+            Context.enter();
+            return null;
+        } finally {
+            Context.exit();
+        }
+    }
+    public int getDepth() {
+        return m_frameno;
+    }
+    //--------------------------------------------------
+    public JsEngine getEngine() {
+        RhinoEngineDebugger redbg;
+        redbg = m_rcp.getRhinoEngineDebugger();
+        return (JsEngine) redbg.getDebugInterface();
+
+    }
+    //--------------------------------------------------
+    public int getLineNumber() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        return m_lineno;
+    }
+    //------------------------------------------------------
+    public JsObject getScope() throws RemoteException {
+
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        try {
+            Context.enter();
+            JsObject scope = m_rhinoDbg.marshallScriptable(m_variableObject);
+            return scope;
+        } finally {
+            Context.exit();
+        }
+    }
+    //------------------------------------------------------
+    public String getSourceName() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        return m_unit.m_dbgScript.getSourceName();
+    }
+    //------------------------------------------------------
+    public JsObject getThis() throws RemoteException {
+
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        try {
+            Context.enter();
+            JsObject thisobj = null;
+            Scriptable obj = null;
+            NativeCall call = null;
+            Scriptable varobj = m_variableObject;
+            if (varobj instanceof NativeCall) {
+                call = (NativeCall) varobj;
+                obj = call.getThisObj();
+                thisobj = m_rhinoDbg.marshallScriptable(varobj);
+            }
+            return thisobj;
+        } finally {
+            Context.exit();
+        }
+    }
+    //--------------------------------------------------
+    void invalidate() {
+        m_invalid = true;
+    }
+    //------------------------------------------------------
+    public boolean isEvalContext() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        try {
+            Context.enter();
+            return false;
+        } finally {
+            Context.exit();
+        }
+    }
+    //------------------------------------------------------
+    public boolean isFunctionContext() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+
+        try {
+            Context.enter();
+            return false;
+        } finally {
+            Context.exit();
+        }
+    }
+    //------------------------------------------------------
+    public boolean isScriptContext() {
+        if (m_invalid)
+            throw new JsdiException("This context no longer exists.");
+        if (!m_atBreakpoint)
+            throw new JsdiException("Resumed context, can't get line number.");
+        try {
+            Context.enter();
+            return true;
+        } finally {
+            Context.exit();
+        }
+    }
+    public Object lookupName(String name) {
+
+        try {
+            Context.enter();
+            Scriptable obj = m_variableObject;
+            Object prop;
+            while (obj != null) {
+                Scriptable m = obj;
+                do {
+                    Object result = m.get(name, obj);
+                    if (result != Scriptable.NOT_FOUND)
+                        return result;
+                    m = m.getPrototype();
+                } while (m != null);
+                obj = obj.getParentScope();
+            }
+            throw new JsdiException("Name is not in scope.");
+        } finally {
+            Context.exit();
+        }
+    }
+    /**
+     * Looks up a name in the scope chain and returns its value.
+     */
+    public Object lookupName(Scriptable scopeChain, String id) {
+
+        try {
+            Context.enter();
+            Scriptable obj = scopeChain;
+            Object prop;
+            while (obj != null) {
+                Scriptable m = obj;
+                do {
+                    Object result = m.get(id, obj);
+                    if (result != Scriptable.NOT_FOUND)
+                        return result;
+                    m = m.getPrototype();
+                } while (m != null);
+                obj = obj.getParentScope();
+            }
+            return null;
+        } finally {
+            Context.exit();
+        }
+    }
+}
+
+class RhinoDebugFrame implements DebugFrame {
+
+    JsContextStub m_stub;
+
+    RhinoDebugFrame(JsContextStub stub) {
+        m_stub = stub;
+    }
+
+    public void onEnter(Context cx, Scriptable activation,
+                        Scriptable thisObj, Object[] args)
+    {
+        m_stub.m_variableObject = activation;
+        m_stub.m_thisObj = thisObj;
+        m_stub.m_frameno = m_stub.m_rcp.m_frameStack.size();
+        m_stub.m_rcp.m_frameStack.push(m_stub);
+    }
+
+    public void onExit(Context cx, boolean byThrow, Object resultOrException)
+    {
+        m_stub.m_rcp.m_frameStack.pop();
+        m_stub.invalidate();
+    }
+
+    public void onExceptionThrown(Context cx, Throwable ex) {
+        m_stub.m_rcp.m_reDbg.handleExceptionThrown(cx, m_stub.m_rcp, ex);
+    }
+
+    public void onLineChange(Context cx, int lineNumber) {
+        m_stub.m_lineno = lineNumber;
+        if (m_stub.m_unit.hasBreakpoint(lineNumber)) {
+            m_stub.m_rcp.m_reDbg.handleBreakpointHit(cx, m_stub.m_rcp);
+        }
+    }
 }
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JsEngineStub.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JsEngineStub.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/JsEngineStub.java	2002-11-12 23:28:54.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/JsEngineStub.java	2004-07-07 21:12:16.135818184 -0600
@@ -62,38 +62,37 @@
 import org.apache.bsf.debug.jsdi.*;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Script;
-import org.mozilla.javascript.debug.DebuggableEngine;
 
 /**
  * Insert the type's description here.
  * Creation date: (9/6/2001 1:21:46 PM)
  * @author: Administrator
  */
-public class JsEngineStub 
+public class JsEngineStub
     extends org.apache.bsf.debug.util.Skeleton
     implements JsEngine {
 
     RhinoEngineDebugger m_rhinoDbg;
     boolean m_inCallback;
     boolean m_resumeExecution;
-    Object  m_lock;	
-	
+    Object  m_lock;
+
     /**
      * JsEngineStub constructor comment.
      */
-    public JsEngineStub(RhinoEngineDebugger rhinoDbg) 
+    public JsEngineStub(RhinoEngineDebugger rhinoDbg)
         throws RemoteException {
         super(org.apache.bsf.debug.util.DebugConstants.JS_ENGINE_TID);
         m_rhinoDbg = rhinoDbg;
         m_lock = new Object();
     }
-	
+
     public boolean isSuspended() throws RemoteException {
         return m_inCallback;
     }
-	
+
     public boolean poll() { return true; }
-	
+
     public Object eval(String docname, String exp, int lineNo)
         throws RemoteException {
 
@@ -125,7 +124,7 @@
         try {
             Context.enter();
             count = m_rhinoDbg.getContextCount();
-            DebugLog.stdoutPrintln("	count = "+count, 
+            DebugLog.stdoutPrintln("    count = "+count,
                                    DebugLog.BSF_LOG_L3);
             return count;
         } finally {
@@ -133,7 +132,7 @@
         }
 
     }
-  
+
     public String getThread() throws RemoteException {
         return m_rhinoDbg.getThread();
     }
@@ -203,7 +202,7 @@
     public void stepIn() throws RemoteException {
         try {
             Context.enter();
-            DebugLog.stdoutPrintln("Step In command on "+this, 
+            DebugLog.stdoutPrintln("Step In command on "+this,
                                    DebugLog.BSF_LOG_L3);
             m_rhinoDbg.stepIn(this);
         } catch (Exception ex) {
@@ -225,7 +224,6 @@
     }
 
     public void stepOver() throws RemoteException {
-        RhinoContextProxy rcp;
         try {
             Context.enter();
             m_rhinoDbg.stepOver(this);
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/RhinoContextProxy.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/RhinoContextProxy.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/RhinoContextProxy.java	2002-11-12 23:28:53.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/RhinoContextProxy.java	2004-07-07 21:12:16.136818032 -0600
@@ -70,133 +70,107 @@
 
 import java.rmi.RemoteException;
 
-public class RhinoContextProxy {
+class RhinoContextProxy {
 
     RhinoEngineDebugger m_reDbg;
-    Context m_context;
-    JsContextStub m_contextStub;
 
-    DebuggableEngine m_engine;
-
-    boolean m_atBreakpoint;
-    int m_frameCount;
-    JsContextStub m_frames[];
+    ObjArray m_frameStack = new ObjArray();
 
     private static final int NO_STEP = 0, STEP_IN = 1, STEP_OVER = 2,
         STEP_OUT = 3, STOP_ENGINE = 4, RUNNING = 5;
 
     private int m_stepCmd, m_stepDepth;
 
-    RhinoContextProxy(RhinoEngineDebugger reDbg, Context cx) {
+    RhinoContextProxy(RhinoEngineDebugger reDbg) {
         m_reDbg = reDbg;
-        m_context = cx;
-        m_engine = cx.getDebuggableEngine();
     }
 
-    public void cancelStepping() {
+    static RhinoContextProxy getCurrent() {
+        Context cx = Context.getCurrentContext();
+        if (cx == null) { return null; }
+        return (RhinoContextProxy)cx.getDebuggerContextData();
+    }
+
+    void cancelStepping() {
         m_stepCmd = NO_STEP;
         m_stepDepth = -1;
-        m_engine.setBreakNextLine(false);
     }
 
-    public JsContextStub getContext(int depth) {
-        return m_frames[depth];
+    int getContextCount() {
+        return m_frameStack.size();
     }
 
-    public int getContextCount() {
-        return m_frameCount;
+    JsContextStub getContextStub(int no) {
+        if (!(0 <= no && no < m_frameStack.size())) { return null; }
+        return (JsContextStub)m_frameStack.get(no);
     }
 
-    public JsContextStub getFrame(int no) {
-        if (no < 0 || no > m_frameCount)
-            return null;
-        if (no == m_frameCount)
-            return m_contextStub;
-        else
-            return m_frames[no];
+    JsContextStub getTopContextStub() {
+        return getContextStub(m_frameStack.size() - 1);
     }
 
-    public int getLineNumber() {
-        DebugFrame frame = m_engine.getFrame(0);
-
-        return frame.getLineNumber();
+    int getLineNumber() {
+        JsContextStub stub = getTopContextStub();
+        return stub.m_lineno;
     }
 
-    public RhinoEngineDebugger getRhinoEngineDebugger() {
+    RhinoEngineDebugger getRhinoEngineDebugger() {
         return m_reDbg;
     }
 
     String getSourceName() {
-        DebugFrame frame = m_engine.getFrame(0);
-
-        return frame.getSourceName();
+        JsContextStub stub = getTopContextStub();
+        return stub.m_unit.m_dbgScript.getSourceName();
     }
 
-
     // We hit a known breakpoint.
     // We need to update the stack.
     // Also, cancel any pending stepping operation.
-    public JsContextStub hitBreakpoint() throws RemoteException {
+    JsContextStub hitBreakpoint() throws RemoteException {
         cancelStepping();
-        updateStack();
-        return m_frames[0];
+        return getTopContextStub();
     }
 
-
-    public JsContextStub exceptionThrown() throws RemoteException {
+    JsContextStub exceptionThrown() throws RemoteException {
         cancelStepping();
-        updateStack();
-        return m_frames[0];
+        return getTopContextStub();
     }
 
-    public void resumed() {
-        JsContextStub stub;
-        DebugFrame frame;
-
-        m_atBreakpoint = false;
-
-        for (int f = 0; f < m_frameCount; f++) {
-            stub = m_frames[f];
-            stub.atBreakpoint(false);
+    void resumed() {
+        for (int f = 0, N = getContextCount(); f != N; ++f) {
+            getContextStub(f).atBreakpoint(false);
         }
     }
 
-    public void run() {
-        m_engine.setBreakNextLine(false);
+    void run() {
         m_stepCmd = RUNNING;
         m_stepDepth = -1;
-
     }
 
-    public void stepIn() {
-        m_engine.setBreakNextLine(true);
+    void stepIn() {
         m_stepCmd = STEP_IN;
-        m_stepDepth = m_frameCount;
+        m_stepDepth = getContextCount();
     }
 
-    public void stepOut() {
-        m_engine.setBreakNextLine(true);
+    void stepOut() {
         m_stepCmd = STEP_OUT;
-        m_stepDepth = m_frameCount;
-
+        m_stepDepth = getContextCount();
     }
 
-    public void stepOver() {
-        m_engine.setBreakNextLine(true);
+    void stepOver() {
         m_stepCmd = STEP_OVER;
-        m_stepDepth = m_frameCount;
+        m_stepDepth = getContextCount();
     }
 
-    public JsContextStub entry_exit_mode() throws RemoteException {
+    JsContextStub entry_exit_mode() throws RemoteException {
         cancelStepping();
-        updateStack();
-        return m_frames[0];
+        return getTopContextStub();
     }
 
-    public JsContextStub stepping() {
+    JsContextStub stepping() {
         // Did we hit a known breakpoint?
 
-        int frameCount = m_engine.getFrameCount();
+        int frameCount = getContextCount();
 
         try {
             switch (m_stepCmd) {
@@ -204,39 +178,31 @@
                 cancelStepping();
                 break;
             case STOP_ENGINE :
-                updateStack();
                 cancelStepping();
-                return m_frames[0];
+                return getTopContextStub();
             case STEP_IN :
-                // OG if ((frameCount == m_stepDepth + 1) || 
+                // OG if ((frameCount == m_stepDepth + 1) ||
                 // (frameCount == m_stepDepth)) {
                 // step if we are in the same frame (nothing to step in... :-)
                 // if we are in a called frame...
                 // but also if we stepped out of the current frame...
-                if ((frameCount >= m_stepDepth) 
-                    || (frameCount < m_stepDepth)) {
-                    updateStack();
                     cancelStepping();
-                    return m_frames[0];
-                }
-                break;
+                    return getTopContextStub();
             case STEP_OVER :
                 // OG if (frameCount == m_stepDepth) {
                 // step if we are in the same frame or above...
-                // this basically avoids any children frame but 
+                // this basically avoids any children frame but
                 // covers the return of the current frame.
                 if (frameCount <= m_stepDepth) {
-                    updateStack();
                     cancelStepping();
-                    return m_frames[0];
+                    return getTopContextStub();
                 }
                 break;
             case STEP_OUT :
                 // OG if (frameCount == m_stepDepth - 1) {
                 if (frameCount < m_stepDepth) {
-                    updateStack();
                     cancelStepping();
-                    return m_frames[0];
+                    return getTopContextStub();
                 }
                 break;
             default :
@@ -249,55 +215,8 @@
         return null;
     }
 
-    public void stopEngine() {
-        m_engine.setBreakNextLine(true);
+    void stopEngine() {
         m_stepCmd = STOP_ENGINE;
         m_stepDepth = -1;
     }
-
-    public void updateStack() throws RemoteException {
-        JsContextStub frames[];
-        JsContextStub stub;
-        DebugFrame frame;
-        int nf, of, frameCount;
-
-        m_atBreakpoint = true;
-
-        frameCount = m_engine.getFrameCount();
-        frames = new JsContextStub[frameCount];
-
-        // scan the stacks from the outer frame down
-        // to the inner one of the shortest of the old
-        // and the new known stack.
-        // The goal is to recognize the DebugFrame objects
-        // that are the sames so that we can reuse the 
-        // stubs for those. 
-        // As soon as a DebugFrame object is found different,
-        // the rest of the stack is different, all the old
-        // stubs can be dropped and invalidated, new ones
-        // must be created.
-
-        for (nf = frameCount - 1, of = m_frameCount - 1;
-             nf >= 0 && of >= 0;
-             nf--, of--) {
-            frame = m_engine.getFrame(nf);
-            if (frame == m_frames[of].m_frame) {
-                frames[nf] = m_frames[of];
-            } else
-                break;
-        }
-        // now drop all old frames that diverged.
-        // Also invalidate the frame stubs so to
-        // tracked that they are no longer valid.
-        for (; of >= 0; of--) {
-            m_reDbg.dropStub(m_frames[of].m_frame);
-            m_frames[of].invalidate();
-        }
-        for (; nf >= 0; nf--) {
-            frame = m_engine.getFrame(nf);
-            frames[nf] = new JsContextStub(this, frame, nf);
-        }
-        m_frames = frames;
-        m_frameCount = frameCount;
-    }
 }
diff -urN bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/RhinoEngineDebugger.java bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/RhinoEngineDebugger.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/RhinoEngineDebugger.java	2002-11-12 23:28:55.000000000 -0700
+++ bsf-2.3.0.patched/src/bsf/src/org/apache/bsf/engines/javascript/RhinoEngineDebugger.java	2004-07-07 21:12:16.138817728 -0600
@@ -74,24 +74,23 @@
 import org.apache.bsf.debug.*;
 import org.apache.bsf.debug.jsdi.*;
 
-public class RhinoEngineDebugger implements Debugger {
+class RhinoEngineDebugger implements Debugger {
 
     /** The global script object, where all embedded functions are defined,
      * as well as the standard ECMA "core" objects.
-     */	
+     */
     private Scriptable global;
     private JsObject globalstub;
 
-    private RhinoContextProxy m_rcp;
     private Scriptable undefined;
     private JsObject undefinedStub;
 
-    /** 
+    /**
      *  Hashtable allowing to find the stub for an object in the JavaScript
      *  environment if one exists.
      *  Typically: Scriptable, Function, Script, etc.
      *  This is not used for Context and DebugFrame.
-     *  They typically contains JsObject associated to 
+     *  They typically contains JsObject associated to
      *  org.mozilla.javascript.ScriptableObject
      */
     private Hashtable stubs;
@@ -102,16 +101,13 @@
     private FnOrScript m_compilingFnOrScript;
     private JavaScriptEngine m_eng;
 
-    private Thread m_thread;
-
     private Hashtable m_documents;
 
     BSFDebugManagerImpl dbgmgr;
 
-    public RhinoEngineDebugger(JavaScriptEngine eng) 
+    RhinoEngineDebugger(JavaScriptEngine eng)
         throws RemoteException {
         super();
-        m_thread = Thread.currentThread();
         m_eng = eng;
         dbgmgr = eng.getDebugManager();
 
@@ -127,45 +123,37 @@
     /**
      * Called when our debugger has been disconnected.
      */
-    public void disconnectedDebuggerNotify() {
+    void disconnectedDebuggerNotify() {
         m_callbacks = null;
     }
 
-    void addStub(Context cx, RhinoContextProxy jscx) {
-        stubs.put(cx, jscx);
-    }
-
-    void addStub(DebugFrame frame, JsContextStub stub) {
-        stubs.put(frame, stub);
-    }
-
     void addStub(Scriptable sobj, JsObject jsobj) {
         stubs.put(sobj, jsobj);
     }
 
-    void dropStub(Object key) {
+    void dropStub(Scriptable key) {
         stubs.remove(key);
     }
 
-    public synchronized DocumentCell getDocumentCell(String name) {
+    synchronized DocumentCell getDocumentCell(String name) {
         return (DocumentCell) m_documents.get(name);
     }
 
     // Called upon creation of a BSFManager.
-    public synchronized DocumentCell loadDocumentNotify(String name) {
+    synchronized DocumentCell loadDocumentNotify(String name) {
         DocumentCell cell;
 
         cell = (DocumentCell) m_documents.get(name);
         if (cell == null) {
             cell = new DocumentCell(this, name);
             m_documents.put(name, cell);
-            if (dbgmgr!=null) 
+            if (dbgmgr!=null)
                 dbgmgr.loadDocumentNotify(m_eng, name);
         }
         return cell;
     }
 
-    public synchronized void placeBreakpointAtLine(int brkptid,
+    synchronized void placeBreakpointAtLine(int brkptid,
                                                    String docname,
                                                    int lineno) {
 
@@ -174,7 +162,7 @@
         cell.addBreakpointAtLine(brkptid, lineno);
     }
 
-    public synchronized void placeBreakpointAtOffset(int brkptid,
+    synchronized void placeBreakpointAtOffset(int brkptid,
                                                      String docname,
                                                      int offset) {
 
@@ -183,7 +171,7 @@
         cell.addBreakpointAtOffset(brkptid, offset);
     }
 
-    public void removeBreakpoint(String docname, int brkptid)
+    void removeBreakpoint(String docname, int brkptid)
         throws BSFException {
 
         DocumentCell cell;
@@ -191,7 +179,7 @@
         cell.removeBreakpoint(brkptid);
     }
 
-    public void setEntryExit(String docname, boolean on)
+    void setEntryExit(String docname, boolean on)
         throws BSFException {
 
         DocumentCell cell;
@@ -199,7 +187,7 @@
         cell.setEntryExit(on);
     }
 
-    public Object eval(String docname, String fnOrScript, int lineno)
+    Object eval(String docname, String fnOrScript, int lineno)
         throws RemoteException {
         Object retval;
         try {
@@ -210,13 +198,15 @@
         }
     }
 
-    public JsContext getContext(int depth) {
-        if (m_rcp != null) return m_rcp.getContext(depth);
+    JsContext getContext(int depth) {
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        if (rcp != null) return rcp.getContextStub(depth);
         return null;
     }
 
-    public int getContextCount() {
-        if (m_rcp != null) return m_rcp.getContextCount();
+    int getContextCount() {
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        if (rcp != null) return rcp.getContextCount();
         return -1;
     }
 
@@ -224,24 +214,20 @@
      * Return the current debugger.
      * @return the debugger, or null if none is attached.
      */
-    public JsCallbacks getDebugger() {
+    JsCallbacks getDebugger() {
         return m_callbacks;
     }
 
-    public Object getDebugInterface() {
+    Object getDebugInterface() {
         return engineStub;
     }
 
-    public JsObject getGlobalObject() {
+    JsObject getGlobalObject() {
         return globalstub;
     }
 
-    public RhinoContextProxy getRhinoContextProxy() {
-        return m_rcp;
-    }
-
     RhinoContextProxy getStub(Context cx) {
-        return (RhinoContextProxy) stubs.get(cx);
+        return (RhinoContextProxy)cx.getDebuggerContextData();
     }
 
     JsContextStub getStub(DebugFrame frame) {
@@ -252,19 +238,20 @@
         return (JsObject) stubs.get(sobj);
     }
 
-    public JsObject getUndefinedValue() {
+    JsObject getUndefinedValue() {
         return undefinedStub;
     }
 
-    public String getThread() {
+    String getThread() {
+        Context cx = Context.getCurrentContext();
         String resultstr = "";
 
-        if (m_thread != null) {
+        if (cx != null) {
             try {
                 final String resultstrf = (String)
                 AccessController.doPrivileged(new PrivilegedExceptionAction() {
                         public Object run() throws Exception {
-                            return m_thread.getName();
+                            return Thread.currentThread().getName();
                         }
                     });
             resultstr = resultstrf;
@@ -277,15 +264,17 @@
         return resultstr;
     }
 
-    public String getThreadGroup() {
+    String getThreadGroup() {
+        Context cx = Context.getCurrentContext();
         String resultstr = "";
 
-        if (m_thread != null) {
+        if (cx != null) {
             try {
                 final String resultstrf = (String)
                 AccessController.doPrivileged(new PrivilegedExceptionAction() {
                         public Object run() throws Exception {
-                            return m_thread.getThreadGroup().getName();
+                            return Thread.currentThread().getThreadGroup().
+                                        getName();
                         }
                     });
             resultstr = resultstrf;
@@ -305,7 +294,7 @@
     // to implement STEP_IN, STEP_OUT, and STEP_OVER.
     //---------------------------------------------------------
 
-    public void handleBreakpointHit(Context cx) {
+    void handleBreakpointHit(Context cx, RhinoContextProxy rcp) {
         JsCallbacks debugger;
         BreakPoint bp;
         Enumeration e;
@@ -313,48 +302,41 @@
         boolean breakpointFound=false;
         String name;
         int lineno;
-        boolean suspend=false;
-		
-        m_thread = Thread.currentThread();
-        DebugLog.stdoutPrintln("**** Handling a breakpoint hit...", 
+
+        DebugLog.stdoutPrintln("**** Handling a breakpoint hit...",
                                DebugLog.BSF_LOG_L3);
-        m_rcp = getStub(cx);
-        if (m_rcp == null) {
-            m_rcp = new RhinoContextProxy(this, cx);
-            addStub(cx, m_rcp);
-        }
-        // if we have no callbacks... then just 
+        // if we have no callbacks... then just
         // ignore the breakpoint hit, do a run
         // so that execution resumes...
         if (m_callbacks==null) {
-            DebugLog.stdoutPrintln("	No callbacks, resuming...", DebugLog.BSF_LOG_L3);
-            m_rcp.run();
+            DebugLog.stdoutPrintln("    No callbacks, resuming...", DebugLog.BSF_LOG_L3);
+            rcp.run();
 
         } else {
             // First, check that we didn't hit a known breakpoint.
             // First, search if we have breakpoints for the current documents
 
-            name = m_rcp.getSourceName();
-            lineno = m_rcp.getLineNumber();
+            name = rcp.getSourceName();
+            lineno = rcp.getLineNumber();
 
-            DebugLog.stdoutPrintln("	in "+name+" at "+lineno, DebugLog.BSF_LOG_L3);
+            DebugLog.stdoutPrintln("    in "+name+" at "+lineno, DebugLog.BSF_LOG_L3);
 
             cell = getDocumentCell(name);
-            if (cell != null) 
-                _handleBreakpointHit(cell,lineno);
-        } 
-        m_rcp = null;
+            if (cell != null)
+                _handleBreakpointHit(rcp,cell,lineno);
+        }
     }
 
-    public void _handleBreakpointHit(DocumentCell cell, int lineno) {
-
+    void _handleBreakpointHit(RhinoContextProxy rcp,
+                              DocumentCell cell, int lineno)
+    {
         JsCallbacks debugger;
         BreakPoint bp;
         Enumeration e;
         JsContext stub=null;
         boolean breakpointFound=false;
         boolean suspend=false;
-		
+
         try {
             bp = cell.findBreakpointAtLine(lineno);
         } catch (BSFException bsfex) {
@@ -363,19 +345,19 @@
         if (bp != null) {
             breakpointFound = true;
             try {
-                stub = m_rcp.hitBreakpoint();
-                DebugLog.stdoutPrintln("	breakpoint callback...", DebugLog.BSF_LOG_L3);
-             	m_callbacks.createFuture(m_rcp);
+                stub = rcp.hitBreakpoint();
+                DebugLog.stdoutPrintln("    breakpoint callback...", DebugLog.BSF_LOG_L3);
+                 m_callbacks.createFuture(rcp);
                 m_callbacks.handleBreakpointHit(stub);
                 suspend = true;
             } catch (RemoteException rex) {
-                DebugLog.stderrPrintln("	EXCEPTION OCCURED DURING BREAKPOINT CALLBACK", DebugLog.BSF_LOG_L0);				
+                DebugLog.stderrPrintln("    EXCEPTION OCCURED DURING BREAKPOINT CALLBACK", DebugLog.BSF_LOG_L0);
                 DebugLog.stderrPrintln(rex.getMessage(), DebugLog.BSF_LOG_L0);
                 rex.printStackTrace();
                 suspend = false;
             }
         } else {
-            DebugLog.stdoutPrintln("	didn't find a breakpoint...", DebugLog.BSF_LOG_L3);
+            DebugLog.stdoutPrintln("    didn't find a breakpoint...", DebugLog.BSF_LOG_L3);
             breakpointFound = false;
         }
 
@@ -384,87 +366,107 @@
             // line in the current document, we must be stepping
             // or in entry/exit mode
             try {
-                stub = m_rcp.stepping();
+                stub = rcp.stepping();
                 FnOrScript current = cell.findFnOrScriptContaining(lineno);
                 if (stub != null) {
                     cell.setLastFnOrScript(current);
-                    DebugLog.stdoutPrintln("	stepping-done callback...", 
+                    DebugLog.stdoutPrintln("    stepping-done callback...",
                                            DebugLog.BSF_LOG_L3);
-                	m_callbacks.createFuture(m_rcp);
+                    m_callbacks.createFuture(rcp);
                     m_callbacks.handleSteppingDone(stub);
                     suspend = true;
-                } 
+                }
                 else if (cell.getEntryExit() &&
                          (current != cell.getLastFnOrScript()) &&
-                         (m_rcp.getContextCount() == 0)) {
+                         (rcp.getContextCount() == 0)) {
                     cell.setLastFnOrScript(current);
-                    stub = m_rcp.entry_exit_mode();
-                    DebugLog.stdoutPrintln("    entry/exit mode...", 
+                    stub = rcp.entry_exit_mode();
+                    DebugLog.stdoutPrintln("    entry/exit mode...",
                                            DebugLog.BSF_LOG_L3);
-                	m_callbacks.createFuture(m_rcp);
+                    m_callbacks.createFuture(rcp);
                     m_callbacks.handleSteppingDone(stub);
                     suspend = true;
                 }
                 else {
-                    DebugLog.stdoutPrintln("	No reason to suspend execution.", DebugLog.BSF_LOG_L3);				
+                    DebugLog.stdoutPrintln("    No reason to suspend execution.", DebugLog.BSF_LOG_L3);
                     suspend = false;
                 }
             } catch (RemoteException rex) {
-                DebugLog.stderrPrintln("	EXCEPTION OCCURED DURING STEPPING-DONE CALLBACK", DebugLog.BSF_LOG_L0);				
+                DebugLog.stderrPrintln("    EXCEPTION OCCURED DURING STEPPING-DONE CALLBACK", DebugLog.BSF_LOG_L0);
                 DebugLog.stderrPrintln(rex.getMessage(), DebugLog.BSF_LOG_L0);
                 rex.printStackTrace();
                 suspend = false;
             }
         }
         if (suspend) {
-            // now, suspend this thread... until 
+            // now, suspend this thread... until
             // we restart.
             try {
-                m_callbacks.suspendFuture(m_rcp);
+                m_callbacks.suspendFuture(rcp);
             } catch (Exception ex) {
                 DebugLog.stdoutPrintln("Future creation failed... releasing the engine", DebugLog.BSF_LOG_L3);
-                m_rcp.run();
+                rcp.run();
             }
-        }			
+        }
     }
 
-    public void run(JsEngineStub eng) throws Exception {
+    void run(JsEngineStub eng) throws Exception {
         DebugLog.stdoutPrintln("RhinoEngineDebugger::run()...",
                                DebugLog.BSF_LOG_L3);
-        m_rcp.run(); 
-        m_callbacks.completeFuture(m_rcp);
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        rcp.run();
+        m_callbacks.completeFuture(rcp);
     }
 
-    public void stepIn(JsEngineStub eng) throws Exception {
+    void stepIn(JsEngineStub eng) throws Exception {
         DebugLog.stdoutPrintln("RhinoEngineDebugger::stepIn()...",
                                DebugLog.BSF_LOG_L3);
-        m_rcp.stepIn();
-        m_callbacks.completeFuture(m_rcp);
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        rcp.stepIn();
+        m_callbacks.completeFuture(rcp);
     }
 
-    public void stepOut(JsEngineStub eng) throws Exception {
+    void stepOut(JsEngineStub eng) throws Exception {
         DebugLog.stdoutPrintln("RhinoEngineDebugger::stepOut()...",
                                DebugLog.BSF_LOG_L3);
-        m_rcp.stepOut();
-        m_callbacks.completeFuture(m_rcp);
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        rcp.stepOut();
+        m_callbacks.completeFuture(rcp);
     }
-    public void stepOver(JsEngineStub eng) throws Exception {
+    void stepOver(JsEngineStub eng) throws Exception {
 
         DebugLog.stdoutPrintln("RhinoEngineDebugger::stepOver()...",
                                DebugLog.BSF_LOG_L3);
-        m_rcp.stepOver();
-        m_callbacks.completeFuture(m_rcp);
+        RhinoContextProxy rcp = RhinoContextProxy.getCurrent();
+        rcp.stepOver();
+        m_callbacks.completeFuture(rcp);
     }
-	
+
     public void handleCompilationDone(Context cx,
                                       DebuggableScript fnOrScript,
-                                      StringBuffer source) {
+                                      String source) {
 
-        m_thread = Thread.currentThread();
         m_compilingFnOrScript.addCompilationUnit(cx, fnOrScript, source);
     }
 
-    public void handleExceptionThrown(Context cx, Object exceptionThrown) {
+    public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
+        CompilationUnit unit;
+        unit = m_compilingFnOrScript.getCompilationUnit(fnOrScript);
+        RhinoContextProxy rcp = getStub(cx);
+        try {
+            JsContextStub stub = new JsContextStub(rcp, unit);
+            return stub.getRhinoDebugFrame();
+        } catch (RemoteException rex) {
+            DebugLog.stderrPrintln("    EXCEPTION OCCURED DURING FRAME INITIALIZATION", DebugLog.BSF_LOG_L0);
+            DebugLog.stderrPrintln(rex.getMessage(), DebugLog.BSF_LOG_L0);
+            rex.printStackTrace();
+            return null;
+        }
+    }
+
+    void handleExceptionThrown(Context cx, RhinoContextProxy rcp,
+                               Throwable exceptionThrown)
+    {
         JsContext stub;
         JsCallbacks debugger;
         BreakPoint bp;
@@ -473,53 +475,40 @@
         String name,msg;
         Exception ex;
         int lineno;
-        NativeError error;
-		
-        m_thread = Thread.currentThread();
-        m_rcp = getStub(cx);
-        if (m_rcp == null) {
-            m_rcp = new RhinoContextProxy(this, cx);
-            addStub(cx, m_rcp);
+
+        // if we have no callbacks... then just
+        // ignore the breakpoint hit, do a run
+        // so that execution resumes...
+        if (m_callbacks==null) {
+            rcp.run();
+            return;
         }
-        try {
-            // if we have no callbacks... then just 
-            // ignore the breakpoint hit, do a run
-            // so that execution resumes...
-            if (m_callbacks==null) {
-                m_rcp.run();
-                return;
-            }
 
-            // First, check that we didn't hit a known breakpoint.
-            // First, search if we have breakpoints for the current documents
-            name = m_rcp.getSourceName();
-            lineno = m_rcp.getLineNumber();
-            try {
-                error = (NativeError)exceptionThrown;
-                msg = error.getName() + ": " + error.getMessage();
-            } catch (ClassCastException ccex) {
-                msg = "Unknown JavaScript Exception";
-            }
-            ex = new Exception(msg);
+        // First, check that we didn't hit a known breakpoint.
+        // First, search if we have breakpoints for the current documents
+        name = rcp.getSourceName();
+        lineno = rcp.getLineNumber();
+        if (exceptionThrown instanceof EcmaError) {
+            msg = ((EcmaError)exceptionThrown).getErrorObject().toString();
+        } else {
+            msg = exceptionThrown.toString();
+        }
+        ex = new Exception(msg);
 
-            cell = getDocumentCell(name);
-            if (cell == null) return;
+        cell = getDocumentCell(name);
+        if (cell == null) return;
 
-            try {
-                stub = m_rcp.exceptionThrown();	
-                m_callbacks.createFuture(m_rcp);
-                m_callbacks.handleExceptionThrown(stub,ex);
-				
-                // now, suspend this thread... until 
-                // we restart.
-                m_callbacks.suspendFuture(m_rcp);
-				
-            } catch (Exception ex2) {
-                m_rcp.run();
-				
-            }
-        } finally {
-            m_rcp = null;
+        try {
+            stub = rcp.exceptionThrown();
+            m_callbacks.createFuture(rcp);
+            m_callbacks.handleExceptionThrown(stub,ex);
+
+            // now, suspend this thread... until
+            // we restart.
+            m_callbacks.suspendFuture(rcp);
+
+        } catch (Exception ex2) {
+            rcp.run();
         }
     }
 
@@ -568,10 +557,10 @@
      * The engine will call the attached debugger's handleBreakpointHit
      * method on the next line it executes if isLineStep is true.
      * May be used from another thread to interrupt execution.
-     * 
+     *
      * @param isLineStep if true, break next line
      */
-    public void setBreakNextLine(JsContext context, boolean isLineStep) {
+    void setBreakNextLine(JsContext context, boolean isLineStep) {
     }
 
     void setCompilingFnOrScript(FnOrScript fnOrScript) {
@@ -583,7 +572,7 @@
      * @param debugger the debugger to be used on callbacks from
      * the engine.
      */
-    public void setDebugger(JsCallbacks debugger) {
+    void setDebugger(JsCallbacks debugger) {
         m_callbacks = debugger;
     }
 }