Import from 1.9a8 tarball
[mozilla-extra.git] / extensions / venkman / resources / content / venkman-commands.js
blob2f38ef573c1c19e5c2d4104b31f024026e13a7b3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is The JavaScript Debugger.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *   Robert Ginda, <rginda@netscape.com>, original author
25  *
26  * Alternatively, the contents of this file may be used under the terms of
27  * either the GNU General Public License Version 2 or later (the "GPL"), or
28  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29  * in which case the provisions of the GPL or the LGPL are applicable instead
30  * of those above. If you wish to allow use of your version of this file only
31  * under the terms of either the GPL or the LGPL, and not to allow others to
32  * use your version of this file under the terms of the MPL, indicate your
33  * decision by deleting the provisions above and replace them with the notice
34  * and other provisions required by the GPL or the LGPL. If you do not delete
35  * the provisions above, a recipient may use your version of this file under
36  * the terms of any one of the MPL, the GPL or the LGPL.
37  *
38  * ***** END LICENSE BLOCK ***** */
40 const CMD_CONSOLE    = 0x01; // command is available via the console
41 const CMD_NEED_STACK = 0x02; // command only works if we're stopped
42 const CMD_NO_STACK   = 0x04; // command only works if we're *not* stopped
43 const CMD_NO_HELP    = 0x08; // don't whine if there is no help for this command
45 function initCommands()
47     console.commandManager = new CommandManager(console.defaultBundle);
48     
49     var cmdary =
50         [/* "real" commands */
51          ["about-mozilla",  cmdAboutMozilla,                                 0],
52          ["break",          cmdBreak,                              CMD_CONSOLE],
53          ["break-props",    cmdBreakProps,                         CMD_CONSOLE],
54          ["change-container", cmdChangeContainer,                  CMD_CONSOLE],
55          ["change-value",   cmdChangeValue,                                  0],
56          ["chrome-filter",  cmdChromeFilter,                       CMD_CONSOLE],
57          ["clear",          cmdClear,                              CMD_CONSOLE],
58          ["clear-all",      cmdClearAll,                           CMD_CONSOLE],
59          ["clear-break",    cmdClearBreak,                                   0],
60          ["clear-fbreak",   cmdClearFBreak,                                  0],
61          ["clear-profile",  cmdClearProfile,                       CMD_CONSOLE],
62          ["clear-session",  cmdHook,                               CMD_CONSOLE],
63          ["clear-script",   cmdClearScript,                                  0],
64          ["clear-instance", cmdClearInstance,                                0],
65          ["close",          cmdClose,                              CMD_CONSOLE],
66          ["cmd-undo",          "cmd-docommand cmd_undo",                     0],
67          ["cmd-redo",          "cmd-docommand cmd_redo",                     0],
68          ["cmd-cut",           "cmd-docommand cmd_cut",                      0],
69          ["cmd-copy",          "cmd-docommand cmd_copy",                     0],
70          ["cmd-paste",         "cmd-docommand cmd_paste",                    0],
71          ["cmd-delete",        "cmd-docommand cmd_delete",                   0],
72          ["cmd-selectall",     "cmd-docommand cmd_selectAll",                0],
73          ["cmd-copy-link-url", "cmd-docommand cmd_copyLink",                 0],
74          ["cmd-mozilla-prefs", "cmd-docommand cmd_mozillaPrefs",             0],
75          ["cmd-prefs",         "cmd-docommand cmd_venkmanPrefs",             0],
76          ["cmd-venkman-prefs", "cmd-docommand cmd_venkmanPrefs",             0],
77          ["cmd-venkman-opts",  "cmd-docommand cmd_venkmanPrefs",             0],
78          ["cmd-docommand",     cmdDoCommand,                                 0],
79          ["commands",       cmdCommands,                           CMD_CONSOLE],
80          ["cont",           cmdCont,              CMD_CONSOLE | CMD_NEED_STACK],
81          ["debug-script",   cmdSetScriptFlag,                                0],
82          ["debug-instance-on",  cmdToggleSomething,                          0],
83          ["debug-instance-off", cmdToggleSomething,                          0],
84          ["debug-instance",     cmdSetScriptFlag,                            0],
85          ["debug-transient",    cmdSetTransientFlag,                         0],
86          ["emode",          cmdEMode,                              CMD_CONSOLE],
87          ["eval",           cmdEval,                               CMD_CONSOLE],
88          ["evald",          cmdEvald,                              CMD_CONSOLE],
89          ["fbreak",         cmdFBreak,                             CMD_CONSOLE],
90          ["set-eval-obj",   cmdSetEvalObj,                                   0],
91          ["set-break",      cmdBreak,                                        0],
92          ["set-fbreak",     cmdFBreak,                                       0],
93          ["fclear",         cmdFClear,                             CMD_CONSOLE],
94          ["fclear-all",     cmdFClearAll,                          CMD_CONSOLE],
95          ["find-bp",        cmdFindBp,                                       0],
96          ["find-creator",   cmdFindCreatorOrCtor,                            0],
97          ["find-ctor",      cmdFindCreatorOrCtor,                            0],
98          ["find-file",      cmdFindFile,                           CMD_CONSOLE],
99          ["find-frame",     cmdFindFrame,                       CMD_NEED_STACK],
100          ["find-sourcetext",      cmdFindSourceText,                         0],
101          ["find-sourcetext-soft", cmdFindSourceText,                         0],
102          ["find-script",          cmdFindScript,                             0],
103          ["find-scriptinstance",  cmdFindScriptInstance,                     0],
104          ["find-url",       cmdFindURL,                            CMD_CONSOLE],
105          ["find-url-soft",  cmdFindURL,                                      0],
106          ["finish",         cmdFinish,            CMD_CONSOLE | CMD_NEED_STACK],
107          ["focus-input",    cmdHook,                                         0],
108          ["frame",          cmdFrame,             CMD_CONSOLE | CMD_NEED_STACK],
109          ["gc",             cmdGC,                                 CMD_CONSOLE],
110          ["help",           cmdHelp,                               CMD_CONSOLE],
111          ["inspect",        cmdInspect,                            CMD_CONSOLE],
112          ["loadd",          cmdLoadd,                              CMD_CONSOLE],
113          ["move-view",      cmdMoveView,                           CMD_CONSOLE],
114          ["mozilla-help",   cmdMozillaHelp,                                  0],
115          ["next",           cmdNext,              CMD_CONSOLE | CMD_NEED_STACK],
116          ["open-dialog",    cmdOpenDialog,                         CMD_CONSOLE],
117          ["open-url",       cmdOpenURL,                                      0],
118          ["pprint",         cmdPPrint,                             CMD_CONSOLE],
119          ["pref",           cmdPref,                               CMD_CONSOLE],
120          ["profile",        cmdProfile,                            CMD_CONSOLE],
121          ["profile-script",       cmdSetScriptFlag,                          0],
122          ["profile-instance",     cmdSetScriptFlag,                          0],
123          ["profile-instance-on",  cmdSetScriptFlag,                          0],
124          ["profile-instance-off", cmdSetScriptFlag,                          0],
125          ["props",          cmdProps,                              CMD_CONSOLE],
126          ["propsd",         cmdProps,                              CMD_CONSOLE],
127          ["quit",           cmdQuit,                               CMD_CONSOLE],
128          ["restore-layout", cmdRestoreLayout,                      CMD_CONSOLE],
129          ["restore-settings", cmdRestoreSettings,                  CMD_CONSOLE],
130          ["release-notes",  cmdReleaseNotes,                                 0],
131          ["run-to",         cmdRunTo,                           CMD_NEED_STACK],
132          ["save-breakpoints", cmdSaveBreakpoints,                  CMD_CONSOLE],
133          ["save-layout",    cmdSaveLayout,                         CMD_CONSOLE],
134          ["save-profile",   cmdSaveProfile,                        CMD_CONSOLE],
135          ["save-settings",  cmdSaveSettings,                       CMD_CONSOLE],
136          ["scan-source",    cmdScanSource,                                   0],
137          ["scope",          cmdScope,             CMD_CONSOLE | CMD_NEED_STACK],
138          ["show-profile",   cmdShowProfile,                        CMD_CONSOLE],
139          ["this-expr",      cmdThisExpr,                           CMD_CONSOLE],
140          ["toggle-float",   cmdToggleFloat,                        CMD_CONSOLE],
141          ["toggle-view",    cmdToggleView,                         CMD_CONSOLE],
142          ["toggle-pref",    cmdTogglePref,                         CMD_CONSOLE],
143          ["startup-init",   cmdStartupInit,                        CMD_CONSOLE],
144          ["step",           cmdStep,              CMD_CONSOLE | CMD_NEED_STACK],
145          ["stop",           cmdStop,                CMD_CONSOLE | CMD_NO_STACK],
146          ["tmode",          cmdTMode,                              CMD_CONSOLE],
147          ["version",        cmdVersion,                            CMD_CONSOLE],
148          ["where",          cmdWhere,             CMD_CONSOLE | CMD_NEED_STACK],
149          
150          /* aliases */
151          ["exit",                     "quit",                                0],
152          ["save-default-layout",      "save-layout default",                 0],
153          ["profile-tb",               "profile toggle",                      0],
154          ["this",                     "props this",                CMD_CONSOLE],
155          ["toggle-chrome",            "chrome-filter toggle",                0],
156          ["toggle-forcescriptload",   "toggle-pref profile.forceScriptLoad", 0],
157          ["toggle-ias",               "startup-init toggle",                 0],
158          ["toggle-pprint",            "pprint toggle",                       0],
159          ["toggle-profile",           "profile toggle",                      0],
160          ["toggle-save-layout",       "toggle-pref saveLayoutOnExit",        0],
161          ["toggle-save-settings",     "toggle-pref saveSettingsOnExit",      0],
162          ["em-cycle",                 "emode cycle",                         0],
163          ["em-ignore",                "emode ignore",                        0],
164          ["em-trace",                 "emode trace",                         0],
165          ["em-break",                 "emode break",                         0],
166          ["tm-cycle",                 "tmode cycle",                         0],
167          ["tm-ignore",                "tmode ignore",                        0],
168          ["tm-trace",                 "tmode trace",                         0],
169          ["tm-break",                 "tmode break",                         0],
171          /* hooks */
172          ["hook-break-set",                                         cmdHook, 0],
173          ["hook-break-clear",                                       cmdHook, 0],
174          ["hook-debug-stop",                                        cmdHook, 0],
175          ["hook-debug-continue",                                    cmdHook, 0],
176          ["hook-display-sourcetext",                                cmdHook, 0],
177          ["hook-display-sourcetext-soft",                           cmdHook, 0],
178          ["hook-eval-done",                                         cmdHook, 0],
179          ["hook-fbreak-clear",                                      cmdHook, 0],
180          ["hook-fbreak-set",                                        cmdHook, 0],
181          ["hook-guess-complete",                                    cmdHook, 0],
182          ["hook-transient-script",                                  cmdHook, 0],
183          ["hook-script-manager-created",                            cmdHook, 0],
184          ["hook-script-manager-destroyed",                          cmdHook, 0],
185          ["hook-script-instance-created",                           cmdHook, 0],
186          ["hook-script-instance-sealed",                            cmdHook, 0],
187          ["hook-script-instance-destroyed",                         cmdHook, 0],
188          ["hook-session-display",                                   cmdHook, 0],
189          ["hook-source-load-complete",                              cmdHook, 0],
190          ["hook-window-closed",                                     cmdHook, 0],
191          ["hook-window-loaded",                                     cmdHook, 0],
192          ["hook-window-opened",                                     cmdHook, 0],
193          ["hook-window-resized",                                    cmdHook, 0],
194          ["hook-window-unloaded",                                   cmdHook, 0],
195          ["hook-venkman-exit",                                      cmdHook, 0],
196          ["hook-venkman-query-exit",                                cmdHook, 0],
197          ["hook-venkman-started",                                   cmdHook, 0]
198         ];
200     cmdary.stringBundle = console.defaultBundle;
201     console.commandManager.defineCommands (cmdary);
203     console.commandManager.argTypes.__aliasTypes__ (["index", "breakpointIndex",
204                                                      "lineNumber"], "int");
205     console.commandManager.argTypes.__aliasTypes__ (["windowFlags",
206                                                      "expression",
207                                                      "prefValue"],
208                                                      "rest");
209     console.commandManager.argTypes.__aliasTypes__ (["deletePref"],
210                                                      "state");
212     console.commandManager.installKeys(console.mainWindow.document,
213                                        console.commandManager.commands);
217  * Used as a callback for CommandRecord.getDocumentation() to format the command
218  * flags for the "Notes:" field.
219  */
220 function formatCommandFlags (f)
222     var ary = new Array();
223     if (f & CMD_CONSOLE)
224         ary.push(MSG_NOTE_CONSOLE);
225     if (f & CMD_NEED_STACK)
226         ary.push(MSG_NOTE_NEEDSTACK);
227     if (f & CMD_NO_STACK)
228         ary.push(MSG_NOTE_NOSTACK);
229     
230     return ary.length ? ary.join ("\n") : MSG_VAL_NA;
233 function getToggle (toggle, currentState)
235     if (toggle == "toggle")
236         toggle = !currentState;
238     return toggle;
241 /*******************************************************************************
242  * Command implementations from here on down...
243  ******************************************************************************/
245 function cmdAboutMozilla ()
247     openTopWin ("about:mozilla");
250 function cmdBreak (e)
252     if (!("isInteractive" in e))
253         e.isInteractive = false;
254     
255     if (!e.urlPattern)
256     {
257         /* if no input data, just list the breakpoints */
258         var i = 0;
259         
260         for (var b in console.breaks)
261         {
262             var brk = console.breaks[b];
263             display (getMsg(MSN_BP_LINE, [++i, brk.url, brk.lineNumber]));
264         }
266         if (i == 0)
267             display (MSG_NO_BREAKS_SET);
269         return;
270     }
272     var found;
273     
274     for (var url in console.scriptManagers)
275     {
276         var manager = console.scriptManagers[url];
278         if (url.search(e.urlPattern) != -1 &&
279             manager.isLineExecutable(e.lineNumber))
280         {
281             found = true;
282             if (manager.hasBreakpoint (e.lineNumber))
283             {
284                 feedback (e, getMsg(MSN_BP_EXISTS, [url, e.lineNumber]));
285             }
286             else
287             {
288                 var props = e.properties;
289                 var fbreak;
290                 if (e.parent)
291                     fbreak = e.parent;
292                 else
293                     fbreak = getFutureBreakpoint(url, e.lineNumber);
294                 if (!fbreak)
295                 {
296                     dispatch ("fbreak", { isInteractive: e.isInteractive,
297                                           urlPattern: url,
298                                           lineNumber: e.lineNumber,
299                                           props: props});
300                     fbreak = getFutureBreakpoint(url, e.lineNumber);
301                     // hard breakpoint properties will be inherited
302                     props = null;
303                 }
305                 console.scriptManagers[url].setBreakpoint (e.lineNumber, fbreak,
306                                                            props);
307                 feedback (e, getMsg(MSN_BP_CREATED, [url, e.lineNumber]));
308             }
309         }
310     }
312     if (!found)
313     {
314         feedback (e, getMsg(MSN_ERR_BP_NOLINE, [e.urlPattern, e.lineNumber]),
315                   MT_ERROR);
316     }
319 function cmdBreakProps (e)
321     if ("propsWindow" in e.breakWrapper)
322     {
323         e.breakWrapper.propsWindow.focus();
324         return;
325     }
326         
327     e.breakWrapper.propsWindow = 
328         openDialog ("chrome://venkman/content/venkman-bpprops.xul", "",
329                     "chrome,extrachrome,menubar,resizable", e.breakWrapper);
332 function cmdChangeContainer(e)
334     if (!(e.viewId in console.views))
335     {
336         display(getMsg(MSN_ERR_NO_SUCH_VIEW, e.viewId), MT_ERROR);
337         return;
338     }
340     var view = console.views[e.viewId];
341     
342     if (!view.currentContent)
343     {
344         display(getMsg(MSN_ERR_INVALID_PARAM, ["<view-id>", e.viewId]),
345                 MT_ERROR);
346         return;
347     }
348     
349     e.newType = e.newType.toLowerCase();
350     
351     if (e.newType.search(/^(horizontal|vertical|tab)$/) != 0)
352     {
353         display(getMsg(MSN_ERR_INVALID_PARAM, ["<new-type>", e.newType]),
354                 MT_ERROR);
355         return;
356     }
358     console.viewManager.changeContainer(view.currentContent.parentNode,
359                                         e.newType);
362 function cmdChangeValue(e)
364     var obj = e.parentValue.getWrappedValue();
365     
366     if (!e.newValue)
367     {
368         var ok;
369         
370         var current = obj[e.propertyName];
371         if (typeof current == "string")
372             current = current.quote();
373         else if (typeof current == "object")
374             current = "";
375         else
376             current = String(current);
378         while (!ok)
379         {
380             
381             var expr = prompt(getMsg(MSN_ENTER_EXPRESSION, e.propertyName),
382                               current);
383             if (expr == null || expr == "")
384                 return;
385             
386             try
387             {
388                 if ("frames" in console)
389                 {
390                     e.newValue = evalInTargetScope(expr, true);
391                     e.newValue = e.newValue.getWrappedValue();
392                 }
393                 else
394                 {
395                     var parent = e.parentValue.jsParent.getWrappedValue();
396                     e.newValue = eval(expr, parent);
397                 }
398                 ok = true;
399             }
400             catch(ex)
401             {
402                 if (ex instanceof jsdIValue)
403                     alert (String(ex.getWrappedValue));
404                 else
405                     alert (String(ex));
407                 current = expr;
408             }
409         }
410     }
412     obj[e.propertyName] = e.newValue;
413     dispatch ("hook-eval-done");
416 function cmdChromeFilter(e)
418     const FLAGS = SCRIPT_NODEBUG | SCRIPT_NOPROFILE;
419     
420     function setFlag (scriptWrapper)
421     {
422         if (!scriptWrapper.jsdScript.isValid)
423             return;
424         
425         if (e.toggle)
426         {
427             scriptWrapper.lastFlags = scriptWrapper.jsdScript.flags;
428             scriptWrapper.jsdScript.flags |= FLAGS;
429         }
430         else
431         {
432             if ("lastFlags" in scriptWrapper)
433             {
434                 scriptWrapper.jsdScript.flags = scriptWrapper.lastFlags;
435                 delete scriptWrapper.lastFlags;
436             }
437             else if (isURLVenkman(scriptWrapper.jsdScript.fileName))
438             {
439                 scriptWrapper.jsdScript.flags |= FLAGS;
440             }
441             else
442             {
443                 scriptWrapper.jsdScript.flags &= ~(FLAGS);
444             }
445         }
447         if (scriptWrapper.jsdScript.flags & SCRIPT_NODEBUG)
448             ++scriptWrapper.scriptInstance.disabledScripts;
449     };
450     
451     var currentState = console.prefs["enableChromeFilter"];
453     if (e.toggle != null)
454     {
455         currentState = console.prefs["enableChromeFilter"];
456         e.toggle = getToggle (e.toggle, currentState);
457         console.prefs["enableChromeFilter"] = e.toggle;
458         
460         if (e.toggle != currentState)
461         {
462             for (var url in console.scriptManagers)
463             {
464                 if (url.search (/^chrome:/) == -1 &&
465                     (!("componentPath" in console) ||
466                      url.indexOf(console.componentPath) == -1))
467                 {
468                     continue;
469                 }
471                 //dd ("setting chrome filter " + e.toggle + " for " + url);
472                 
473                 var mgr = console.scriptManagers[url];
474                 if (e.toggle)
475                 {
476                     mgr.lastDisableTransients = mgr.disableTransients;
477                     mgr.disableTransients = true;
478                 }
479                 else
480                 {
481                     if ("lastDisableTransients" in mgr)
482                     {
483                         mgr.disableTransients = mgr.lastDisableTransients;
484                         delete mgr.lastDisableTransients;
485                     }
486                     else
487                     {
488                         mgr.disableTransients = false;
489                     }
490                 }
491                     
492                 for (var i in mgr.instances)
493                 {
494                     var instance = mgr.instances[i];
495                     instance.disabledScripts = 0;
496                     if (instance.topLevel)
497                         setFlag (instance.topLevel);
498                     
499                     for (var f in instance.functions)
500                         setFlag(instance.functions[f]);
501                 }
502             }
503         }
504     }
506     feedback (e, getMsg(MSN_CHROME_FILTER,
507                         currentState ? MSG_VAL_ON : MSG_VAL_OFF));
510 function cmdClear (e)
512     var found = false;
513     
514     for (var b in console.breaks)
515     {
516         var brk = console.breaks[b];
517         if ((!e.lineNumber || 
518              "lineNumber" in brk && e.lineNumber == brk.lineNumber) &&
519             brk.scriptWrapper.jsdScript.fileName.search(e.urlPattern) != -1)
520         {
521             found = true;
522             brk.scriptWrapper.clearBreakpoint(brk.pc);
523             feedback (e, getMsg(MSN_BP_CLEARED,
524                                 [brk.scriptWrapper.jsdScript.fileName,
525                                  e.lineNumber]));
526         }
527     }
529     if (!found)
530     {
531         feedback (e, getMsg(MSN_ERR_BP_NODICE, [e.urlPattern, e.lineNumber]),
532                   MT_ERROR);
533     }
536 function cmdClearAll (e)
538     if (!("isInteractive" in e))
539         e.isInteractive = false;
540     
541     var breakWrapperList = new Array()
542     for (var i in console.breaks)
543         breakWrapperList.push (console.breaks[i]);
545     if (breakWrapperList.length)
546     {
547         dispatch ("clear-break", { isInteractive: e.isInteractive,
548                                    breakWrapper: breakWrapperList[0],
549                                    breakWrapperList: breakWrapperList });
550     }
553 function cmdClearBreak (e)
555     if (!("isInteractive" in e))
556         e.isInteractive = false;
557     
558     function clear (wrapper)
559     {
560         if (wrapper instanceof BreakInstance)
561         {
562             wrapper.scriptWrapper.clearBreakpoint(wrapper.pc);
563         }
564         else if (wrapper instanceof FutureBreakpoint)
565         {
566             for (var b in wrapper.childrenBP)
567                 clear (wrapper.childrenBP[b]);
568         }
569     };
571     if ("breakWrapperList" in e)
572     {
573         for (var i = 0; i < e.breakWrapperList.length; ++i)
574             clear(e.breakWrapperList[i]);
575     }
576     else
577     {
578         clear (e.breakWrapper);
579     }
582 function cmdClearFBreak (e)
584     if (!("isInteractive" in e))
585         e.isInteractive = false;
586     
587     function clear (wrapper)
588     {
589         if (wrapper instanceof FutureBreakpoint)
590         {
591             var params = {
592                 isInteractive: e.isInteractive,
593                 urlPattern: wrapper.url,
594                 lineNumber: wrapper.lineNumber
595             };
596         
597             dispatch ("fclear", params);
598         }
599         else if (wrapper instanceof BreakInstance && wrapper.parentBP)
600         {
601             clear (wrapper.parentBP);
602         }
603     };
604             
605     if ("breakWrapperList" in e)
606     {
607         for (var i = 0; i < e.breakWrapperList.length; ++i)
608             clear(e.breakWrapperList[i]);
609     }
610     else
611     {
612         clear (e.breakWrapper);
613     }
615     
616 function cmdClearProfile (e)
618     if ("scriptRecList" in e)
619     {
620         for (var i = 0; i < e.scriptRecList.length; ++i)
621             e.scriptRecList[i].script.clearProfileData();
622     }
623     else if ("scriptRec" in e)
624     {
625         e.scriptRec.script.clearProfileData();
626     }
627     else
628     {
629         console.jsds.clearProfileData();
630     }
631     
632     feedback (e, MSG_PROFILE_CLEARED);
635 function cmdClearInstance (e)
637     if ("scriptInstanceList" in e)
638     {
639         for (var i = 0; i < e.scriptInstanceList.length; ++i)
640             cmdClearInstance ({ scriptInstance: e.scriptInstanceList[i] });
641         return true;
642     }
645     if (e.scriptInstance.topLevel)
646         e.scriptInstance.topLevel.clearBreakpoints();
647     
648     for (var w in e.scriptInstance.functions)
649         e.scriptInstance.functions[w].clearBreakpoints();
651     return true;
653     
654 function cmdClearScript (e)
656     var i;
657     
658     if ("scriptWrapperList" in e)
659     {
660         for (i = 0; i < e.scriptWrapperList.length; ++i)
661             cmdClearScript ({scriptWrapper: e.scriptWrapperList[i]});
662         return true;
663     }
665     e.scriptWrapper.clearBreakpoints();
666     
667     return true;
670 function cmdClose(e)
672     if ("sourceWindow" in e)
673         e.sourceWindow.close();
674     else
675         window.close();
678 function cmdCommands (e)
680     display (getMsg(MSN_TIP1_HELP, 
681                     console.prefs["sessionView.requireSlash"] ? "/" : ""));
682     display (MSG_TIP2_HELP);
684     var names = console.commandManager.listNames(e.pattern, CMD_CONSOLE);
685     if (!names.length)
686     {
687         display (getMsg(MSN_NO_CMDMATCH, e.pattern), MT_ERROR);
688         return true;
689     }
691     names = names.join(MSG_COMMASP);
692     
693     if (e.pattern)
694         display (getMsg(MSN_CMDMATCH, [e.pattern, "["  + names + "]"]));
695     else
696         display (getMsg(MSN_CMDMATCH_ALL, "[" + names + "]"));
697     return true;
700 function cmdCont (e)
702     disableDebugCommands();
703     console.jsds.exitNestedEventLoop();
706 function cmdDoCommand(e)
708     if (e.cmdName == "cmd_mozillaPrefs")
709     {
710         goPreferences('navigator', 
711                       'chrome://communicator/content/pref/pref-navigator.xul', 
712                       'navigator');
713     }
714     else
715     {
716         doCommand(e.cmdName);
717     }
720 function cmdEMode (e)
721 {    
722     if (e.mode != null)
723     {
724         e.mode = e.mode.toLowerCase();
726         if (e.mode == "cycle")
727         {
728             switch (console.errorMode)
729             {
730                 case EMODE_IGNORE:
731                     e.mode = "trace";
732                     break;
733                 case EMODE_TRACE:
734                     e.mode = "break";
735                     break;
736                 case EMODE_BREAK:
737                     e.mode = "ignore";
738                     break;
739             }
740         }
742         switch (e.mode)
743         {
744             case "ignore":
745                 console.errorMode = EMODE_IGNORE;
746                 break;
747             case "trace": 
748                 console.errorMode = EMODE_TRACE;
749                 break;
750             case "break":
751                 console.errorMode = EMODE_BREAK;
752                 break;
753             default:
754                 display (getMsg(MSN_ERR_INVALID_PARAM, ["mode", e.mode]),
755                          MT_ERROR);
756                 return false;
757         }
759         console.prefs["lastErrorMode"] = e.mode;
760     }
761     
762     switch (console.errorMode)
763     {
764         case EMODE_IGNORE:
765             feedback (e, MSG_EMODE_IGNORE);
766             break;
767         case EMODE_TRACE:
768             feedback (e, MSG_EMODE_TRACE);
769             break;
770         case EMODE_BREAK:
771             feedback (e, MSG_EMODE_BREAK);
772             break;
773     }
775     return true;
778 function cmdEval (e)
780     var urlFile;
781     var functionName;
782     var rv;
783     
784     if (!("currentEvalObject" in console))
785     {
786         display (MSG_ERR_NO_EVAL_OBJECT, MT_ERROR);
787         return false;
788     }
790     display(getMsg(MSN_EVAL_IN, [leftPadString(console.evalCount, 3, "0"),
791                                  e.expression]),
792             MT_FEVAL_IN);
794     if (console.currentEvalObject instanceof jsdIStackFrame)
795     {
796         rv = evalInTargetScope (e.expression);
797         if (typeof rv != "undefined")
798         {
799             if (rv != null)
800             {
801                 var l = $.length;
802                 $[l] = rv;
803                 
804                 display (getMsg(MSN_FMT_TMP_ASSIGN, [l, formatValue (rv)]),
805                          MT_FEVAL_OUT);
806             }
807             else
808                 dd ("evalInTargetScope returned null");
809         }
810     }
811     else
812     {
813         var parent;
814         var jsdValue = console.jsds.wrapValue (console.currentEvalObject);
815         if (jsdValue.jsParent)
816             parent = jsdValue.jsParent.getWrappedValue();
817         if (!parent)
818             parent = console.currentEvalObject;
819         if ("location" in parent)
820             urlFile = getFileFromPath(parent.location.href);
821         else
822             urlFile = MSG_VAL_UNKNOWN;
824         try
825         {
826             rv = console.doEval.apply(console.currentEvalObject,
827                                       [e.expression, parent]);
828             display (String(rv), MT_FEVAL_OUT);
829         }
830         catch (ex)
831         {
832             display (formatException(ex), MT_ERROR);
833         }
834     }    
835     
836     dispatch ("hook-eval-done");
837     return true;
840 function cmdEvald (e)
842     display (e.expression, MT_EVAL_IN);
843     var rv = evalInDebuggerScope (e.expression);
844     if (typeof rv != "undefined")
845         display (String(rv), MT_EVAL_OUT);
847     dispatch ("hook-eval-done");
848     return true;
851 function cmdFBreak(e)
852 {       
853     if (!e.urlPattern)
854     {
855         /* if no input data, just list the breakpoints */
856         var i = 0;
857         
858         for (var f in console.fbreaks)
859         {
860             var brk = console.fbreaks[f];
861             display (getMsg(MSN_FBP_LINE, [++i, brk.url, brk.lineNumber]));
862         }
864         if (i == 0)
865             display (MSG_NO_FBREAKS_SET);
867         return null;
868     }
869     else
870     {
871         var fbreak = setFutureBreakpoint (e.urlPattern, e.lineNumber, 
872                                           e.properties);
873         if (fbreak)
874         {
875             feedback (e, getMsg(MSN_FBP_CREATED, [e.urlPattern, e.lineNumber]));
876         }
877         else
878         {
879             feedback (e, getMsg(MSN_FBP_EXISTS, [e.urlPattern, e.lineNumber]),
880                       MT_ERROR);
881         }
882         return fbreak;
883     }
886 function cmdFinish (e)
888     if (console.frames.length == 1)
889         return cmdCont();
890     
891     console._stepOverDepth = console.frames.length - 1;
892     setStopState(false);
893     console.jsds.functionHook = console.callHook;
894     disableDebugCommands()
895     console.jsds.exitNestedEventLoop();
896     return true;
899 function cmdFindBp (e)
901     if ("scriptWrapper" in e.breakpoint)
902     {
903         dispatch ("find-script",
904                   { scriptWrapper: e.breakpoint.scriptWrapper, 
905                     targetPc: e.breakpoint.pc });
906     }
907     else
908     {
909         dispatch ("find-url", {url: e.breakpoint.url,
910                                rangeStart: e.breakpoint.lineNumber,
911                                rangeEnd: e.breakpoint.lineNumber});
912     }
915 function cmdFindCreatorOrCtor (e)
917     var objVal = e.jsdValue.objectValue;
918     if (!objVal)
919     {
920         display (MSG_NOT_AN_OBJECT, MT_ERROR);
921         return false;
922     }
924     var name = e.command.name;
925     var url;
926     var line;
927     if (name == "find-creator")
928     {
929         url  = objVal.creatorURL;
930         line = objVal.creatorLine;
931     }
932     else
933     {
934         url  = objVal.constructorURL;
935         line = objVal.constructorLine;
936     }
938     return dispatch ("find-url",
939                      {url: url, rangeStart: line, rangeEnd: line});
942 function cmdFindFile (e)
944     if (!e.fileName || e.fileName == "?")
945     {
946         var rv = pickOpen(MSG_OPEN_FILE, "$all");
947         if (rv.reason == PICK_CANCEL)
948             return null;
949         e.fileName = rv.file;
950     }
951     
952     return dispatch ("find-url", {url: getURLSpecFromFile (e.fileName)});
955 function cmdFindFrame (e)
957     var jsdFrame = console.frames[e.frameIndex];
959     if ("isInteractive" in e && e.isInteractive)
960         displayFrame (jsdFrame, e.frameIndex, true);
962     if (jsdFrame.isNative)
963         return true;
964     
965     var scriptWrapper = console.scriptWrappers[jsdFrame.script.tag]
966     return dispatch ("find-script",
967                      { scriptWrapper: scriptWrapper, targetPc: jsdFrame.pc });
970 function cmdFindScript (e)
972     var jsdScript = e.scriptWrapper.jsdScript;
973     var targetLine = 1;
974     var rv, params;
976     if (console.prefs["prettyprint"] && jsdScript.isValid)
977     {
978         if (e.targetPc != null)
979             targetLine = jsdScript.pcToLine(e.targetPc, PCMAP_PRETTYPRINT);
980         
981         console.currentDetails = e.scriptWrapper;
983         params = {
984             sourceText: e.scriptWrapper.sourceText,
985             rangeStart: null,
986             rangeEnd:   null,
987             targetLine: targetLine,
988             details: e.scriptWrapper
989         };
990         dispatch ("hook-display-sourcetext-soft", params);
991         rv = jsdScript.fileName;
992     }
993     else
994     {
995         if (e.targetPc != null && jsdScript.isValid)
996             targetLine = jsdScript.pcToLine(e.targetPc, PCMAP_SOURCETEXT);
997         else
998             targetLine = jsdScript.baseLineNumber;
1000         params = {
1001             sourceText: e.scriptWrapper.scriptInstance.sourceText,
1002             rangeStart: jsdScript.baseLineNumber,
1003             rangeEnd: jsdScript.baseLineNumber + 
1004                       jsdScript.lineExtent - 1,
1005             targetLine: targetLine,
1006             details: e.scriptWrapper
1007         };
1008         rv = dispatch("find-sourcetext-soft", params);
1009     }
1011     return rv;
1014 function cmdFindScriptInstance (e)
1016     var params = Clone(e);
1017     params.sourceText = e.scriptInstance.sourceText;
1018     dispatch ("find-sourcetext", params);
1021 function cmdFindSourceText (e)
1023     function cb(status)
1024     {
1025         if (status != Components.results.NS_OK)
1026         {
1027             display (getMsg (MSN_ERR_SOURCE_LOAD_FAILED,
1028                              [e.sourceText.url, status], MT_ERROR));
1029             return;
1030         }
1031         
1032         var params = {
1033             sourceText: e.sourceText,
1034             rangeStart: e.rangeStart,
1035             rangeEnd: e.rangeEnd,
1036             targetLine: (e.targetLine != null) ? e.targetLine : e.rangeStart,
1037             details:    e.details
1038         };
1039         
1040         if (e.command.name.indexOf("soft") != -1)
1041             dispatch ("hook-display-sourcetext-soft", params);
1042         else
1043             dispatch ("hook-display-sourcetext", params);
1044     };
1046     console.currentSourceText = e.sourceText;
1047     console.currentDetails = e.details;
1048     
1049     if (!e.sourceText || e.sourceText.isLoaded)
1050         cb(Components.results.NS_OK);
1051     else
1052         e.sourceText.loadSource(cb);
1055 function cmdFindURL (e)
1057     if (!e.url)
1058     {
1059         dispatch ("find-sourcetext", { sourceText: null });
1060         return;
1061     }
1063     var sourceText;
1065     if (e.url.indexOf("x-jsd:") == 0)
1066     {
1067         switch (e.url)
1068         {
1069             case "x-jsd:help":
1070                 sourceText = console.sourceText;
1071                 break;
1072                 
1073             default:
1074                 display (getMsg(MSN_ERR_INVALID_PARAM, ["url", e.url]),
1075                          MT_ERROR);
1076                 return;
1077         }
1078     }
1079     else if (e.url in console.scriptManagers)
1080     {
1081         sourceText = console.scriptManagers[e.url].sourceText;
1082     }
1083     else if (e.url in console.files)
1084     {
1085         sourceText = console.files[e.url];
1086     }
1087     else
1088     {
1089         sourceText = console.files[e.url] = new SourceText (e.url);
1090     }
1092     var params = {
1093         sourceText: sourceText,
1094         rangeStart: e.rangeStart,
1095         rangeEnd: e.rangeEnd,
1096         targetLine: e.targetLine,
1097         details: e.details
1098     };
1100     if (e.command.name.indexOf("soft") == -1)
1101         dispatch ("find-sourcetext", params);
1102     else
1103         dispatch ("find-sourcetext-soft", params);
1106 function cmdFClear (e)
1108     var found = false;
1110     for (var b in console.fbreaks)
1111     {
1112         var brk = console.fbreaks[b];
1113         if (!e.lineNumber || e.lineNumber == brk.lineNumber &&
1114             brk.url.search(e.urlPattern) != -1)
1115         {
1116             found = true;
1117             clearFutureBreakpoint (brk.url, e.lineNumber);
1118             feedback (e, getMsg(MSN_FBP_CLEARED, [brk.url, e.lineNumber]));
1119         }
1120     }
1122     if (!found)
1123     {
1124         feedback (e, getMsg(MSN_ERR_BP_NODICE, [e.urlPattern, e.lineNumber]),
1125                   MT_ERROR);
1126     }
1129 function cmdFClearAll (e)
1131     if (!("isInteractive" in e))
1132         e.isInteractive = false;
1134     var breakWrapperList = new Array();
1135     
1136     for (var i in console.fbreaks)
1137         breakWrapperList.push (console.fbreaks[i]);
1139     if (breakWrapperList.length)
1140     {
1141         dispatch ("clear-fbreak", { isInteractive: e.isInteractive,
1142                                     breakWrapper: breakWrapperList[0],
1143                                     breakWrapperList: breakWrapperList });
1144     }
1147 function cmdFrame (e)
1149     if (e.frameIndex != null)
1150     {
1151         if (e.frameIndex < 0 || e.frameIndex >= console.frames.length)
1152         {
1153             display (getMsg(MSN_ERR_INVALID_PARAM,
1154                             ["frameIndex", e.frameIndex]),
1155                      MT_ERROR);
1156             return false;
1157         }
1158         setCurrentFrameByIndex(e.frameIndex);
1159     }
1160     else
1161     {
1162         e.frameIndex = getCurrentFrameIndex();
1163     }    
1165     if (!("isInteractive" in e))
1166         e.isInteractive = false;
1167     
1168     dispatch ("find-frame", { frameIndex: e.frameIndex,
1169                               isInteractive: e.isInteractive });
1170     return true;
1173 function cmdGC()
1175     console.jsds.GC();    
1178 function cmdHelp (e)
1180     var ary;
1181     if (!e.pattern)
1182     {
1183         openTopWin ("x-jsd:help", "venkman-help");
1184         return true;
1185     }
1186     else
1187     {
1188         ary = console.commandManager.list (e.pattern, CMD_CONSOLE);
1190         if (ary.length == 0)
1191         {
1192             display (getMsg(MSN_ERR_NO_COMMAND, e.pattern), MT_ERROR);
1193             return false;
1194         }
1196         for (var i in ary)
1197         {        
1198             display (getMsg(MSN_FMT_USAGE, [ary[i].name, ary[i].usage]), 
1199                      MT_USAGE);
1200             display (ary[i].help, MT_HELP);
1201         }
1202     }
1204     return true;
1207 function cmdHook(e)
1209     /* empty function used for "hook" commands. */
1212 function cmdInspect(e)
1214     var key, value;
1215     if ("jsdValue" in e)
1216     {
1217         key = e.propertyName;
1218         value = e.jsdValue.getWrappedValue();
1219     }
1220     else if ("expression" in e)
1221     {
1222         key = e.expression;
1223         value = evalInTargetScope(e.expression, true).getWrappedValue();
1224     }
1225     if (!value || !isDOMThing(value))
1226     {
1227         display(getMsg(MSN_ERR_NOT_A_DOM_NODE, key), MT_ERROR);
1228         return;
1229     }
1230     window.openDialog("chrome://inspector/content/", "_blank",
1231                       "chrome,all,dialog=no", value);
1234 function cmdLoadd (e)
1236     var ex;
1237     
1238     if (!("_loader" in console))
1239     {
1240         const LOADER_CTRID = "@mozilla.org/moz/jssubscript-loader;1";
1241         const mozIJSSubScriptLoader = 
1242             Components.interfaces.mozIJSSubScriptLoader;
1244         var cls;
1245         if ((cls = Components.classes[LOADER_CTRID]))
1246             console._loader = cls.getService(mozIJSSubScriptLoader);
1247     }
1248     
1249     var obj = ("scope" in e) ? e.scope : null;
1250     try
1251     {
1252         var rvStr;
1253         var rv = rvStr = console._loader.loadSubScript(e.url, obj);
1254         if (typeof rv == "function")
1255             rvStr = MSG_TYPE_FUNCTION;
1256         feedback(e, getMsg(MSN_SUBSCRIPT_LOADED, [e.url, rvStr]), MT_INFO);
1257         return rv;
1258     }
1259     catch (ex)
1260     {
1261         display (getMsg(MSN_ERR_SCRIPTLOAD, e.url));
1262         display (formatException(ex), MT_ERROR);
1263     }
1264     
1265     return null;
1268 function cmdMoveView (e)
1270     if (!e.viewId || !(e.viewId in console.views))
1271     {
1272         display (getMsg(MSN_ERR_INVALID_PARAM, ["viewId", e.viewId]), MT_ERROR);
1273         return;    
1274     }
1276     var parsedLocation = console.viewManager.parseLocation (e.locationUrl);
1277     if (!parsedLocation)
1278     {
1279         display (getMsg(MSN_ERR_INVALID_PARAM, ["locationURL", e.locationURL]),
1280                  MT_ERROR);
1281         return;    
1282     }
1283     
1284     console.viewManager.moveView (parsedLocation, e.viewId);
1287 function cmdMozillaHelp ()
1289     if (typeof openHelp == "undefined")
1290         toOpenWindowByType('mozilla:help', 'chrome://help/content/help.xul');
1291     else
1292         openHelp();
1295 function cmdNext ()
1297     // we don't setStopState(false) here because if the line we're at
1298     // doesn't call out to a function, /next is the same as /step.
1299     console._stepOverDepth = console.frames.length;
1300     dispatch ("step");
1301     console.jsds.functionHook = console.callHook;
1302     return;
1305 function cmdOpenDialog (e)
1307     if (!e.windowFlags)
1308         e.windowFlags = "chrome,menubar,toolbar,resizable,dialog=no";
1309     
1310     return openDialog (e.url, e.windowName, e.windowFlags);
1313 function cmdOpenURL (e)
1315     var url = prompt (MSG_OPEN_URL, "http://");
1316     if (url && url != "http://")
1317         return dispatch ("find-url", { url: url });
1319     return null;
1320 }    
1322 function cmdPPrint (e)
1324     var state, params;
1325     
1326     if (e.toggle != null)
1327     {
1328         e.toggle = getToggle (e.toggle, console.prefs["prettyprint"]);
1329         console.prefs["prettyprint"] = e.toggle;
1330         
1331         var tb = document.getElementById("maintoolbar:toggle-pprint");
1332         if (e.toggle)
1333         {
1334             tb.setAttribute("state", "true");
1335         }
1336         else
1337         {
1338             tb.removeAttribute("state");
1339         }
1341         if ("currentDetails" in console &&
1342             console.currentDetails instanceof ScriptWrapper)
1343         {
1344             dispatch ("find-script", { scriptWrapper: console.currentDetails });
1345         }
1346     }
1348     feedback (e, getMsg(MSN_FMT_PPRINT, console.prefs["prettyprint"] ?
1349                         MSG_VAL_ON : MSG_VAL_OFF));
1350     
1351     return true;
1354 function cmdPref (e)
1356     if (e.prefName && e.prefName[0] == "-")
1357     {
1358         e.prefName = e.prefName.substr(1);
1359         e.deletePref = true;
1360     }
1361         
1362     if (e.deletePref)
1363     {
1364         try
1365         {
1366             console.prefManager.prefBranch.clearUserPref(e.prefName);
1367             console.prefManager.dirtyPrefs[e.prefName] = true;
1368             console.prefManager.prefService.savePrefFile(null);
1369         }
1370         catch (ex)
1371         {
1372             // ignore exception generated by clear of nonexistant pref
1373             if (!("result" in ex) ||
1374                 ex.result != Components.results.NS_ERROR_UNEXPECTED)
1375             {
1376                 throw ex;
1377             }
1378         }
1380         var prefValue = console.prefs[e.prefName];
1381         feedback (e, getMsg(MSN_FMT_PREFVALUE,
1382                             [e.prefName, console.prefs[e.prefName]]));
1383         return true;
1384     }
1386     if (e.prefValue)
1387     {
1388         var type = typeof console.prefs[e.prefName];
1389         switch (type)
1390         {
1391             case "number":
1392                 e.prefValue = Number(e.prefValue);
1393                 break;
1394             case "boolean":
1395                 e.prefValue = (e.prefValue.toLowerCase() == "true");
1396                 break;
1397             case "string":
1398                 break;
1399             default:
1400                 e.prefValue = String(e.prefValue);
1401                 break;
1402         }
1404         console.prefs[e.prefName] = e.prefValue;
1405         feedback (e, getMsg(MSN_FMT_PREFVALUE, [e.prefName, e.prefValue]));
1406     }
1407     else
1408     {
1409         var ary = console.prefManager.listPrefs(e.prefName);
1410         if (ary.length == 0)
1411         {
1412             display (getMsg(MSN_ERR_UNKNOWN_PREF, [e.prefName]),
1413                      MT_ERROR);
1414             return false;
1415         }
1417         for (var i = 0; i < ary.length; ++i)
1418         {
1419             feedback (e, getMsg(MSN_FMT_PREFVALUE,
1420                                 [ary[i], console.prefs[ary[i]]]));
1421         }
1422     }
1424     return true;
1427 function cmdProfile(e)
1429     var currentState = console.jsds.flags & COLLECT_PROFILE_DATA;
1431     if (e.toggle != null)
1432     {
1433         e.toggle = getToggle (e.toggle, currentState);
1434         setProfileState(e.toggle);
1435     }
1436     else
1437     {
1438         e.toggle = currentState;
1439     }
1440     
1441     feedback (e, getMsg(MSN_PROFILE_STATE,
1442                         [e.toggle ? MSG_VAL_ON : MSG_VAL_OFF]));
1445 function cmdProps (e)
1447     var v;
1448     var debuggerScope = (e.command.name == "propsd");
1450     if (debuggerScope)
1451     {
1452         v = console.jsds.wrapValue(evalInDebuggerScope (e.expression));
1453     }
1454     else
1455     {
1456         if (!("currentEvalObject" in console))
1457         {
1458             display (MSG_ERR_NO_EVAL_OBJECT, MT_ERROR);
1459             return false;
1460         }
1462         if (console.currentEvalObject instanceof jsdIStackFrame)
1463         {
1464             v = evalInTargetScope (e.expression);
1465         }
1466         else
1467         {
1468             v = console.doEval.apply(console.currentEvalObject,
1469                                      [e.expression, parent]);
1470             v = console.jsds.wrapValue(v);
1471         }
1472     }
1473     
1474     if (!(v instanceof jsdIValue) || v.jsType != jsdIValue.TYPE_OBJECT)
1475     {
1476         var str = (v instanceof jsdIValue) ? formatValue(v) : String(v)
1477         display (getMsg(MSN_ERR_INVALID_PARAM, [MSG_VAL_EXPRESSION, str]),
1478                  MT_ERROR);
1479         return false;
1480     }
1481     
1482     display (getMsg(debuggerScope ? MSN_PROPSD_HEADER : MSN_PROPS_HEADER,
1483                     e.expression));
1484     displayProperties(v);
1485     return true;
1488 function cmdQuit()
1490     goQuitApplication();
1493 function cmdRestoreLayout (e)
1494 {   
1495     if (!e.name)
1496     {
1497         var list = console.prefManager.listPrefs("layoutState.");
1498         for (var i = 0; i < list.length; ++i)
1499             list[i] = list[i].substr(12);
1500         list.push("factory");
1501         display (getMsg(MSN_LAYOUT_LIST, list.sort().join(MSG_COMMASP)));
1502         return;
1503     }
1504     
1505     var layout;
1506     e.name = e.name.toLowerCase();
1507     if (e.name == "factory")
1508     {
1509         layout = DEFAULT_VURLS;
1510     }
1511     else
1512     {
1513         var prefName = "layoutState." + e.name;
1514         if (!(prefName in console.prefs))
1515         {
1516             display (getMsg(MSN_ERR_INVALID_PARAM, ["name", e.name]), MT_ERROR);
1517             return;
1518         }
1519         else
1520         {
1521             layout = console.prefs[prefName];
1522             if (layout == "")
1523                 layout = DEFAULT_VURLS;
1524         }
1525     }
1526     
1527     console.viewManager.destroyWindows();
1528     console.viewManager.reconstituteVURLs (layout.split (/\s*;\s*/));
1531 function cmdRestoreSettings(e)
1533     if (!e.settingsFile || e.settingsFile == "?")
1534     {
1535         var rv = pickOpen(MSG_OPEN_FILE, "*.js");
1536         if (rv.reason == PICK_CANCEL)
1537             return;
1538         e.settingsFile = getURLSpecFromFile(rv.file);
1539     }
1540     else if (e.settingsFile.indexOf("file:") != 0)
1541     {
1542         e.settingsFile = getURLSpecFromFile(e.settingsFile);
1543     }
1545     dispatch("loadd", { url: e.settingsFile });
1548 function cmdReleaseNotes (e)
1550     openTopWin(MSG_RELEASE_URL);
1553 function cmdRunTo (e)
1555     if (!e.scriptWrapper.jsdScript.isValid)
1556         return;
1557     
1558     var breakpoint = e.scriptWrapper.setBreakpoint(e.pc);
1559     if (breakpoint)
1560         breakpoint.oneTime = true;
1561     dispatch ("cont");
1564 function cmdSaveBreakpoints(e)
1566     var needClose = false;
1567     var file = e.settingsFile;
1568     
1569     if (!file || file == "?")
1570     {
1571         var rv = pickSaveAs(MSG_SAVE_FILE, "*.js");
1572         if (rv.reason == PICK_CANCEL)
1573             return;
1574         e.settingsFile = file = fopen(rv.file, ">");
1575         needClose = true;
1576     }
1577     else if (typeof file == "string")
1578     {
1579         e.settingsFile = file = fopen(file, ">");
1580         needClose = true;
1581     }
1583     var fbp, bp;
1584     var params;
1586     file.write ("\n//Breakpoint settings start...\n");
1587     
1588     for (i in console.fbreaks)
1589     {
1590         var wroteVar;
1591         
1592         fbp = console.fbreaks[i];
1593         params = {
1594             urlPattern: fbp.url,
1595             lineNumber: fbp.lineNumber,
1596             properties: fbp.getProperties()
1597         };
1599         if (keys(fbp.childrenBP).length)
1600         {
1601             if (!wroteVar)
1602             {
1603                 file.write ("var fbreak;\n\n");
1604                 wroteVar = true;
1605             }
1606             file.write("fbreak = ");
1607         }            
1609         file.write("dispatch('fbreak', " + params.toSource() + ");\n\n");
1611         for (i in fbp.childrenBP)
1612         {
1613             bp = fbp.childrenBP[i];
1614             
1615             file.write("dispatch('break', {" +
1616                        "urlPattern:" + bp.url.quote() + ", " +
1617                        "lineNumber:" + bp.lineNumber + ", " +
1618                        "parent:fbreak, " +
1619                        "properties:" + bp.getProperties().toSource() +
1620                        "});\n");
1621         };
1623         file.write("\n");
1624     }
1625     
1626     for (i in console.breaks)
1627     {
1628         bp = console.breaks[i];
1629         if (!bp.parentBP)
1630         {
1631             params = {
1632                 urlPattern: bp.url,
1633                 lineNumber: bp.lineNumber,
1634                 properties: bp.getProperties()
1635             };
1636             
1637             file.write("dispatch('break', " + params.toSource() + ");\n");
1638         }
1639     }
1640     
1641     file.write (MSG_BREAKPOINTS_RESTORED.quote() + ";\n");
1643     if (needClose)
1644         file.close();
1646     
1647 function cmdSaveLayout(e)
1649     if (!e.name)
1650     {
1651         var list = console.prefManager.listPrefs("layoutState.");
1652         for (var i = 0; i < list.length; ++i)
1653             list[i] = list[i].substr(12);
1654         list.push("factory");
1655         display (getMsg(MSN_LAYOUT_LIST, list.sort().join(MSG_COMMASP)));
1656         return;
1657     }
1658     
1659     e.name = e.name.toLowerCase();
1660     if (e.name == "factory")
1661     {
1662         display (getMsg(MSN_ERR_INVALID_PARAM, ["name", e.name]), MT_ERROR);
1663         return;    
1664     }
1665     
1666     var ary = console.viewManager.getLayoutState ();
1667     var prefName = "layoutState." + e.name;
1668     console.prefManager.addPref(prefName, "");
1669     console.prefs[prefName] = ary.join ("; ");
1672 function cmdSaveProfile (e)
1674     function onComplete (i)
1675     {
1676         var msg = getMsg(MSN_PROFILE_SAVED, getURLSpecFromFile(file.localFile));
1677         display (msg);
1678         console.status = msg;
1679         file.close();
1680     };
1681         
1682     var templatePfx = "profile.template.";
1683     var i;
1684     var ext;
1685     
1686     if (!e.targetFile || e.targetFile == "?")
1687     {
1688         var list = console.prefManager.listPrefs(templatePfx);
1689         var extList = "";
1690         for (i = 0; i < list.length; ++i)
1691         {
1692             ext = list[i].substr(templatePfx.length);
1693             if (list[i].search(/html|htm|xml|txt/i) == -1)
1694                 extList += "*." + ext + " ";
1695         }
1696         var rv = pickSaveAs(MSG_SAVE_PROFILE, "$html $xml $text " + 
1697                             extList + "$all");
1698         if (rv.reason == PICK_CANCEL)
1699             return null;
1700         e.targetFile = rv.file;
1701     }
1702     
1703     var file = fopen (e.targetFile, ">");
1705     var ary = file.localFile.path.match(/\.([^.]+)$/);
1707     if (ary)
1708         ext = ary[1].toLowerCase();
1709     else
1710         ext = "txt";
1712     var rv = writeProfile(e, file, ext, onComplete);
1714     return rv.localFile;
1717 function cmdSaveSettings(e)
1719     if (!e.settingsFile || e.settingsFile == "?")
1720     {
1721         var rv = pickSaveAs(MSG_SAVE_FILE, "*.js");
1722         if (rv.reason == PICK_CANCEL)
1723             return;
1724         e.settingsFile = fopen(rv.file, ">");
1725     }
1726     else if (typeof e.settingsFile == "string")
1727     {
1728         e.settingsFile = fopen(e.settingsFile, ">");
1729     }
1730   
1731     dispatch ("save-breakpoints", { settingsFile: e.settingsFile });
1732     dispatch ("save-watches", { settingsFile: e.settingsFile });
1734     e.settingsFile.write("\n" + MSG_SETTINGS_RESTORED.quote() + ";\n");
1735     
1736     e.settingsFile.close();
1739 function cmdScanSource (e)
1741     e.scriptInstance.scanForMetaComments();
1744 function cmdScope ()
1746     if (getCurrentFrame().scope.propertyCount == 0)
1747         display (getMsg (MSN_NO_PROPERTIES, MSG_VAL_SCOPE));
1748     else
1749         displayProperties (getCurrentFrame().scope);
1750     
1751     return true;
1754 function cmdShowProfile(e)
1756     function onComplete(i)
1757     {
1758         // We need a window since the current browserwindow could be disabled
1759         // by us if a script in it is stopped, so we can't do anything there.
1760         var w = window.open("about:blank");
1761         w.wrappedJSObject.document.open();
1762         w.wrappedJSObject.document.write(fileString.str);
1763         w.wrappedJSObject.document.close();
1764     };
1766     // In order not to create files, we hack in a small wrapper around a big string:
1767     var fileString = {
1768         str: "",
1769         write: function _write(_str) { this.str += _str; }
1770     };
1772     writeProfile(e, fileString, "html", onComplete);
1775 function writeProfile(e, file, type, onComplete)
1777     // Get us a template
1778     if (!type)
1779         type = "txt";
1781     var templatePfx = "profile.template.";
1782     var templateName = templatePfx + type;
1783     var templateFile;
1784     if (templateName in console.prefs)
1785         templateFile = console.prefs[templateName];
1786     else
1787         templateFile = console.prefs[templatePfx + "txt"];
1788     
1789     var reportTemplate = console.profiler.loadTemplate(templateFile);
1791     // Get a list of scripts we profiled.
1792     var scriptInstanceList = new Array();
1793     
1794     if (!("urlList" in e) || e.urlList.length == 0)
1795     {
1796         if ("url" in e && e.url)
1797             e.urlList = [e.url];
1798         else
1799             e.urlList = keys(console.scriptManagers);
1800     }
1801     
1802     e.urlList = e.urlList.sort();
1804     var i, j;
1805     for (i = 0; i < e.urlList.length; ++i)
1806     {
1807         var url = e.urlList[i];
1808         if (!ASSERT(url in console.scriptManagers, "url not loaded"))
1809             continue;
1810         var manager = console.scriptManagers[url];
1811         for (j in manager.instances)
1812             scriptInstanceList.push(manager.instances[j]);
1813     }
1815     var rangeList;
1816     if (("profile.ranges." + type) in console.prefs)
1817         rangeList = console.prefs["profile.ranges." + type].split(",");
1818     else
1819         rangeList = console.prefs["profile.ranges.default"].split(",");
1820     
1821     var profileReport = new ProfileReport(reportTemplate, file, rangeList,
1822                                           scriptInstanceList);
1823     profileReport.onComplete = onComplete;
1824     
1825     console.profiler.generateReport(profileReport);
1827     return file;
1830 function cmdThisExpr(e)
1832     if (e.expression == "debugger")
1833     {
1834         rv = console.jsdConsole;
1835     }
1836     else if (console.currentEvalObject instanceof jsdIStackFrame)
1837     {
1838         rv = evalInTargetScope (e.expression);
1839     }
1840     else
1841     {
1842         rv = console.doEval.apply(console.currentEvalObject,
1843                                   [e.expression, parent]);
1844     }
1846     if (!(rv instanceof jsdIValue))
1847         rv = console.jsds.wrapValue(rv);
1848     
1849     if (rv.jsType != TYPE_OBJECT)
1850     {
1851         display (MSG_ERR_THIS_NOT_OBJECT, MT_ERROR);
1852         return false;
1853     }
1854     
1855     dispatch ("set-eval-obj", { jsdValue: rv });
1856     dispatch ("hook-eval-done");
1857     return true;
1858 }    
1860 function cmdToggleSomething (e)
1862     var ary = e.command.name.match (/(.*)-(on|off|toggle)$/);
1863     if (!ary)
1864         return;
1865     
1866     var newEvent = Clone(e);
1867     
1868     if (ary[2] == "on")
1869         newEvent.toggle = true;
1870     else if (ary[2] == "off")
1871         newEvent.toggle = false;
1872     else
1873         newEvent.toggle = "toggle";
1875     dispatch (ary[1], newEvent);
1878 function cmdSetEvalObj (e)
1880     if (!(e.jsdValue instanceof jsdIStackFrame))
1881     {
1882         e.jsdValue = e.jsdValue.getWrappedValue();
1883     }
1884     
1885     if (e.jsdValue == console.currentEvalObject)
1886     {
1887         var frame = getCurrentFrame();
1888         if (frame)
1889             e.jsdValue = frame;
1890         else
1891             e.jsdValue = console;
1892     }
1893     
1894     console.currentEvalObject = e.jsdValue;
1897 function cmdSetScriptFlag (e)
1899     function setFlag (scriptWrapper)
1900     {
1901         var jsdScript = scriptWrapper.jsdScript;
1902         
1903         if (!jsdScript.isValid)
1904             return;
1905         
1906         if (e.toggle == "toggle")
1907         {
1908             jsdScript.flags ^= flag;
1909             if (flag == SCRIPT_NODEBUG)
1910             {
1911                 if (jsdScript.flags & flag)
1912                     ++scriptWrapper.scriptInstance.disabledScripts;
1913                 else
1914                     --scriptWrapper.scriptInstance.disabledScripts;
1915             }
1916         }
1917         else if (e.toggle)
1918         {
1919             jsdScript.flags |= flag;
1920             if (flag == SCRIPT_NODEBUG)
1921                 ++scriptWrapper.scriptInstance.disabledScripts;
1922         }
1923         else
1924         {
1925             jsdScript.flags &= ~flag;
1926             if (flag == SCRIPT_NODEBUG)
1927                 --scriptWrapper.scriptInstance.disabledScripts;
1928         }
1929     };
1930     
1931     function setFlagInstance (scriptInstance)
1932     {
1933         if (scriptInstance.topLevel)
1934             setFlag (scriptInstance.topLevel);
1935         
1936         for (var f in scriptInstance.functions)
1937             setFlag (scriptInstance.functions[f]);
1938     };
1940     var flag;
1941     var i;
1942     
1943     if (e.command.name.search(/^profile/) == 0)
1944         flag = SCRIPT_NOPROFILE;
1945     else
1946         flag = SCRIPT_NODEBUG;
1947     
1948     if (e.command.name.search (/script$/) != -1)
1949     {
1950         if ("scriptWrapperList" in e)
1951         {
1952             for (i = 0; i < e.scriptWrapperList.length; ++i)
1953                 setFlag(e.scriptWrapperList[i]);
1954         }
1955         else
1956         {
1957             setFlag(e.scriptWrapper);
1958         }
1959     }
1960     else
1961     {
1962         if ("scriptInstanceList" in e)
1963         {
1964             for (i = 0; i < e.scriptInstanceList.length; ++i)
1965                 setFlagInstance(e.scriptInstanceList[i]);
1966         }
1967         else
1968         {
1969             setFlagInstance(e.scriptInstance);
1970         }
1971     }
1974 function cmdSetTransientFlag (e)
1976     function setFlag (url)
1977     {
1978         if (!(url in console.scriptManagers))
1979             return;
1981         var scriptManager = console.scriptManagers[url];
1982         if (e.toggle == "toggle")
1983             scriptManager.disableTransients = !scriptManager.disableTransients;
1984         else
1985             scriptManager.disableTransients = e.toggle;
1986     };
1987     
1988     if ("urlList" in e)
1989     {
1990         for (var i = 0; i < e.urlList.length; ++i)
1991             setFlag (e.urlList[i]);
1992     }
1993     else
1994     {
1995         setFlag (e.url);
1996     }
1999 function cmdStartupInit (e)
2001     dd ("startup-init " + e.toggle);
2002     
2003     if (e.toggle != null)
2004     {
2005         e.toggle = getToggle (e.toggle, console.jsds.initAtStartup);
2006         console.jsds.initAtStartup = e.toggle;
2007     }
2009     display (getMsg(MSN_IASMODE,
2010                     console.jsds.initAtStartup ? MSG_VAL_ON : MSG_VAL_OFF));
2011     return true;
2014 function cmdStep()
2016     setStopState(true);
2017     var topFrame = console.frames[0];
2018     console._stepPast = console.frames.length + topFrame.script.fileName;
2020     if (console.prefs["prettyprint"])
2021     {
2022         console._stepPast +=
2023             topFrame.script.pcToLine(topFrame.pc, PCMAP_PRETTYPRINT);
2024     }
2025     else
2026     {
2027         console._stepPast += topFrame.line;
2028     }
2029     disableDebugCommands()
2030     console.jsds.exitNestedEventLoop();
2031     return true;
2034 function cmdStop (e)
2036     if (console.jsds.interruptHook)
2037         setStopState(false);
2038     else
2039         setStopState(true);
2042 function cmdTMode (e)
2044     if (e.mode != null)
2045     {
2046         e.mode = e.mode.toLowerCase();
2048         if (e.mode == "cycle")
2049         {
2050             switch (console.throwMode)
2051             {
2052                 case TMODE_IGNORE:
2053                     e.mode = "trace";
2054                     break;
2055                 case TMODE_TRACE:
2056                     e.mode = "break";
2057                     break;
2058                 case TMODE_BREAK:
2059                     e.mode = "ignore";
2060                     break;
2061             }
2062         }
2064         switch (e.mode.toLowerCase())
2065         {
2066             case "ignore":
2067                 console.jsds.throwHook = null;
2068                 console.throwMode = TMODE_IGNORE;
2069                 break;
2070             case "trace": 
2071                 console.jsds.throwHook = console.executionHook;
2072                 console.throwMode = TMODE_TRACE;
2073                 break;
2074             case "break":
2075                 console.jsds.throwHook = console.executionHook;
2076                 console.throwMode = TMODE_BREAK;
2077                 break;
2078             default:
2079                 display (getMsg(MSN_ERR_INVALID_PARAM, ["mode", e.mode]),
2080                          MT_ERROR);
2081                 return false;
2082         }
2084         console.prefs["lastThrowMode"] = e.mode;
2085     }
2086     
2087     switch (console.throwMode)
2088     {
2089         case TMODE_IGNORE:
2090             feedback (e, MSG_TMODE_IGNORE);
2091             break;
2092         case TMODE_TRACE:
2093             feedback (e, MSG_TMODE_TRACE);
2094             break;
2095         case TMODE_BREAK:
2096             feedback (e, MSG_TMODE_BREAK);
2097             break;
2098     }
2100     return true;
2103 function cmdToggleFloat (e)
2105     if (!e.viewId in console.views || 
2106         typeof console.views[e.viewId] != "object")
2107     {
2108         display (getMsg(MSN_ERR_NO_SUCH_VIEW, e.viewId), MT_ERROR);
2109         return;
2110     }
2112     var locationUrl;
2113     var view = console.views[e.viewId];
2114     var parsedLocation = 
2115         console.viewManager.computeLocation(view.currentContent);
2117     if (parsedLocation.windowId == VMGR_MAINWINDOW)
2118     {
2119         /* already in the main window, float the view. */
2120         locationUrl = VMGR_VURL_NEW
2121     }
2122     else
2123     {
2124         /* already floated, put it back. */
2125         if ("previousLocation" in view)
2126             locationUrl = view.previousLocation;
2127         else
2128             locationUrl = VMGR_VURL_GUTTER;
2129     }
2131     dispatch ("move-view", { viewId: e.viewId, locationUrl: locationUrl });
2134 function cmdTogglePref (e)
2136     var state = !console.prefs[e.prefName];
2137     console.prefs[e.prefName] = state;
2138     feedback (e, getMsg (MSN_FMT_PREFVALUE, 
2139                          [e.prefName, state ? MSG_VAL_ON : MSG_VAL_OFF]));
2141                      
2142 function cmdToggleView (e)
2144     if (!e.viewId in console.views || typeof console.views[e.viewId] != "object")
2145     {
2146         display (getMsg(MSN_ERR_NO_SUCH_VIEW, e.viewId), MT_ERROR);
2147         return;
2148     }
2149     
2150     var view = console.views[e.viewId];
2151     var url;
2152     
2153     if ("currentContent" in view)
2154     {
2155         url = VMGR_VURL_HIDDEN;
2156     }
2157     else
2158     {
2159         if ("previousLocation" in view)
2160             url = view.previousLocation;
2161         else
2162             url = VMGR_VURL_GUTTER;
2163     }
2164     
2165     console.viewManager.moveViewURL (url, e.viewId);
2166 }    
2168 function cmdVersion ()
2170     display(MSG_HELLO, MT_HELLO);
2171     display(getMsg(MSN_VERSION, __vnk_version + __vnk_versionSuffix), MT_HELLO);
2174 function cmdWhere ()
2176     displayCallStack();
2177     return true;