~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/venkman/resources/content/venkman-dev.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Mozilla Public License
 
4
 * Version 1.1 (the "License"); you may not use this file except in
 
5
 * compliance with the License. You may obtain a copy of the License at
 
6
 * http://www.mozilla.org/MPL/ 
 
7
 * 
 
8
 * Software distributed under the License is distributed on an "AS IS" basis,
 
9
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
10
 * for the specific language governing rights and limitations under the
 
11
 * License. 
 
12
 *
 
13
 * The Original Code is The JavaScript Debugger
 
14
 * 
 
15
 * The Initial Developer of the Original Code is
 
16
 * Netscape Communications Corporation
 
17
 * Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation.
 
19
 *
 
20
 * Alternatively, the contents of this file may be used under the
 
21
 * terms of the GNU Public License (the "GPL"), in which case the
 
22
 * provisions of the GPL are applicable instead of those above.
 
23
 * If you wish to allow use of your version of this file only
 
24
 * under the terms of the GPL and not to allow others to use your
 
25
 * version of this file under the MPL, indicate your decision by
 
26
 * deleting the provisions above and replace them with the notice
 
27
 * and other provisions required by the GPL.  If you do not delete
 
28
 * the provisions above, a recipient may use your version of this
 
29
 * file under either the MPL or the GPL.
 
30
 *
 
31
 * Contributor(s):
 
32
 *  Robert Ginda, <rginda@netscape.com>, original author
 
33
 *
 
34
 */
 
35
 
 
36
function initDev()
 
37
{
 
38
    var cmdary =
 
39
        [["dumpcontexts",  cmdDumpContexts,  CMD_CONSOLE | CMD_NO_HELP],
 
40
         ["dumpfilters",   cmdDumpFilters,   CMD_CONSOLE | CMD_NO_HELP],
 
41
         ["dumpprofile",   cmdDumpProfile,   CMD_CONSOLE | CMD_NO_HELP],
 
42
         ["dumptree",      cmdDumpTree,      CMD_CONSOLE | CMD_NO_HELP],
 
43
         ["dumpscripts",   cmdDumpScripts,   CMD_CONSOLE | CMD_NO_HELP],
 
44
         ["reloadui",      cmdReloadUI,      CMD_CONSOLE | CMD_NO_HELP],
 
45
         ["sync-debug",    cmdSyncDebug,     CMD_CONSOLE | CMD_NO_HELP],
 
46
         ["test",          cmdTest,          CMD_CONSOLE | CMD_NO_HELP],
 
47
         ["testargs",      cmdTestArgs,      CMD_CONSOLE | CMD_NO_HELP],
 
48
         ["testargs1",     cmdTestArgs,      CMD_CONSOLE | CMD_NO_HELP],
 
49
         ["testfilters",   cmdTestFilters,   CMD_CONSOLE | CMD_NO_HELP],
 
50
         ["treetest",      cmdTreeTest,      CMD_CONSOLE | CMD_NO_HELP],
 
51
 
 
52
         ["multialias",    "help pref; help props", CMD_CONSOLE | CMD_NO_HELP]];
 
53
         
 
54
    
 
55
    console.commandManager.defineCommands (cmdary);
 
56
 
 
57
    if (!("devState" in console.pluginState))
 
58
    {
 
59
        console.prefManager.addPref ("dbgContexts", false);
 
60
        console.prefManager.addPref ("dbgDispatch", false);
 
61
        console.prefManager.addPref ("dbgRealize", false);
 
62
    }
 
63
    
 
64
    console.pluginState.devState = true;
 
65
    
 
66
    dispatch ("sync-debug");
 
67
    
 
68
    return "Venkman development functions loaded OK.";
 
69
}
 
70
 
 
71
function cmdDumpContexts()
 
72
{
 
73
    console.contexts = new Array();
 
74
    var i = 0;
 
75
    
 
76
    var enumer = {
 
77
        enumerateContext: function _ec (context) {
 
78
                              if (!context.isValid)
 
79
                              {
 
80
                                  dd("enumerate got invalid context");
 
81
                              }
 
82
                              else
 
83
                              {
 
84
                                  var v = context.globalObject.getWrappedValue();
 
85
                                  var title = "<n/a>";
 
86
                                  if (v instanceof Object &&
 
87
                                      "document" in v)
 
88
                                  {
 
89
                                      title = v.document.title;
 
90
                                  }
 
91
                              
 
92
                                  dd ("enumerateContext: Index " + i +
 
93
                                      ", Version " + context.version +
 
94
                                      ", Options " + context.options +
 
95
                                      ", Private " + context.privateData +
 
96
                                      ", Tag " + context.tag +
 
97
                                      ", Title " + title +
 
98
                                      ", Scripts Enabled " +
 
99
                                      context.scriptsEnabled);
 
100
                              }
 
101
                              console.contexts[i++] = context;
 
102
                          }
 
103
    };
 
104
    
 
105
    console.jsds.enumerateContexts(enumer);
 
106
    return true;
 
107
}
 
108
    
 
109
function cmdDumpFilters()
 
110
{
 
111
    console.filters = new Array();
 
112
    var i = 0;
 
113
    
 
114
    var enumer = {
 
115
        enumerateFilter: function enum_f (filter) {
 
116
                             dd (i + ": " + filter.globalObject +
 
117
                                 " '" + filter.urlPattern + "' " + filter.flags);
 
118
                             console.filters[i++] = filter;
 
119
                         }
 
120
    };
 
121
    
 
122
    console.jsds.enumerateFilters (enumer);
 
123
}
 
124
 
 
125
function cmdDumpProfile(e)
 
126
{
 
127
    var list = console.getProfileSummary();
 
128
    for (var i = 0; i < list.length; ++i)
 
129
        dd(list[i].str);
 
130
}
 
131
        
 
132
function cmdDumpTree(e)
 
133
{
 
134
    if (!e.depth)
 
135
        e.depth = 0;
 
136
    dd(e.tree + ":\n" + tov_formatBranch (eval(e.tree), "", e.depth));
 
137
}
 
138
 
 
139
function cmdDumpScripts(e)
 
140
{
 
141
    var nl;
 
142
    
 
143
    if ("frames" in console)
 
144
    {
 
145
        frame = getCurrentFrame();
 
146
        var targetWindow = frame.executionContext.globalObject.getWrappedValue();
 
147
        nl = targetWindow.document.getElementsByTagName("script");
 
148
    }
 
149
    else
 
150
    {
 
151
        nl = document.getElementsByTagName("script");
 
152
    }
 
153
 
 
154
    for (var i = 0; i < nl.length; ++i)
 
155
        dd("src: " + nl.item(i).getAttribute ("src"));
 
156
}
 
157
 
 
158
function cmdReloadUI()
 
159
{
 
160
    if ("frames" in console)
 
161
    {
 
162
        display (MSG_NOTE_NOSTACK, MT_ERROR);
 
163
        return;
 
164
    }
 
165
    
 
166
    var bs = Components.classes["@mozilla.org/intl/stringbundle;1"];
 
167
    bs = bs.createInstance(Components.interfaces.nsIStringBundleService);
 
168
    bs.flushBundles();
 
169
    window.location.href = window.location.href;
 
170
}    
 
171
 
 
172
function cmdSyncDebug()
 
173
{
 
174
    if (eval(console.prefs["dbgContexts"]))
 
175
        console.dbgContexts = true;
 
176
    else
 
177
        delete console.dbgContexts;
 
178
 
 
179
    if (eval(console.prefs["dbgDispatch"]))
 
180
        console.dbgDispatch = true;
 
181
    else
 
182
        delete console.dbgDispatch;
 
183
 
 
184
    if (eval(console.prefs["dbgRealize"]))
 
185
        console.dbgRealize = true;
 
186
    else
 
187
        delete console.dbgRealize;
 
188
}
 
189
 
 
190
function cmdTest(e)
 
191
{
 
192
    function f()
 
193
    {
 
194
        g();
 
195
        h();
 
196
    };
 
197
 
 
198
    function g() {};
 
199
    function h() {};
 
200
    
 
201
    dd("start {");
 
202
    for (var i = 0; i < 50000; ++i)
 
203
        f();
 
204
 
 
205
    dd("} stop");
 
206
}
 
207
 
 
208
function cmdTestArgs (e)
 
209
{
 
210
    display (dumpObjectTree(e));
 
211
}
 
212
 
 
213
function cmdTestFilters ()
 
214
{
 
215
    var filter1 = {
 
216
        globalObject: null,
 
217
        flags: jsdIFilter.FLAG_ENABLED,
 
218
        urlPattern: "1",
 
219
        startLine: 0,
 
220
        endLine: 0
 
221
    };
 
222
    var filter2 = {
 
223
        globalObject: null,
 
224
        flags: jsdIFilter.FLAG_ENABLED,
 
225
        urlPattern: "*2",
 
226
        startLine: 0,
 
227
        endLine: 0
 
228
    };
 
229
    var filter3 = {
 
230
        globalObject: null,
 
231
        flags: jsdIFilter.FLAG_ENABLED,
 
232
        urlPattern: "3*",
 
233
        startLine: 0,
 
234
        endLine: 0
 
235
    };
 
236
    var filter4 = {
 
237
        globalObject: null,
 
238
        flags: jsdIFilter.FLAG_ENABLED,
 
239
        urlPattern: "*4*",
 
240
        startLine: 0,
 
241
        endLine: 0
 
242
    };
 
243
 
 
244
    dd ("append f3 into an empty list.");
 
245
    console.jsds.appendFilter (filter3);
 
246
    console.jsds.GC();
 
247
    dd("insert f1 at the top");
 
248
    console.jsds.insertFilter (filter1, null);
 
249
    console.jsds.GC();
 
250
    dd("insert f2 after f1");
 
251
    console.jsds.insertFilter (filter2, filter1);
 
252
    console.jsds.GC();
 
253
    dd("swap f4 in, f3 out");
 
254
    console.jsds.swapFilters (filter3, filter4);
 
255
    console.jsds.GC();
 
256
    dd("append f3");
 
257
    console.jsds.appendFilter (filter3);
 
258
    console.jsds.GC();
 
259
    dd("swap f4 and f3");
 
260
    console.jsds.swapFilters (filter3, filter4);
 
261
    console.jsds.GC();
 
262
 
 
263
    dumpFilters();
 
264
}
 
265
 
 
266
 
 
267
function cmdTreeTest()
 
268
{
 
269
    var w = openDialog("chrome://venkman/content/tests/tree.xul", "", "");
 
270
}
 
271
 
 
272
initDev();