|
1 /* |
|
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
|
3 * Copyright (C) 2006 David Smith (catfish.man@gmail.com) |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
15 * its contributors may be used to endorse or promote products derived |
|
16 * from this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 */ |
|
29 |
|
30 var inputElement = null; |
|
31 var mainWindow = window.opener; |
|
32 var history = [""]; |
|
33 var historyIndex = 0; |
|
34 |
|
35 function loaded() |
|
36 { |
|
37 inputElement = document.getElementById("input"); |
|
38 inputElement.addEventListener("keydown", inputKeyDown, false); |
|
39 inputElement.addEventListener("keyup", inputKeyUp, false); |
|
40 inputElement.focus(); |
|
41 } |
|
42 |
|
43 function inputKeyDown(event) |
|
44 { |
|
45 if (event.keyCode == 13 && !event.altKey) { |
|
46 if (mainWindow.isPaused && mainWindow.currentStack) { |
|
47 history[history.length - 1] = inputElement.innerText; |
|
48 sendScript(inputElement.innerText); |
|
49 inputElement.innerText = ""; |
|
50 history.push(""); |
|
51 historyIndex = history.length - 1; |
|
52 inputElement.focus(); |
|
53 } else |
|
54 alert("The debugger needs to be paused.\tIn order to evaluate your script input you need to pause the debugger in the context of another script."); |
|
55 event.preventDefault(); |
|
56 } else if (event.keyCode == 38 && !event.altKey && historyIndex > 0) { |
|
57 historyIndex--; |
|
58 inputElement.innerText = history[historyIndex]; |
|
59 inputElement.focus() |
|
60 event.preventDefault(); |
|
61 } else if (event.keyCode == 40 && !event.altKey && historyIndex < (history.length - 1)) { |
|
62 historyIndex++; |
|
63 inputElement.innerText = history[historyIndex]; |
|
64 inputElement.focus() |
|
65 event.preventDefault(); |
|
66 } |
|
67 } |
|
68 |
|
69 function inputKeyUp(event) |
|
70 { |
|
71 if (event.keyCode != 38 && event.keyCode != 40 && event.keyCode != 13) { |
|
72 history[historyIndex] = inputElement.innerText; |
|
73 } |
|
74 } |
|
75 |
|
76 function appendMessage(exp, msg) |
|
77 { |
|
78 var historyDisplay = document.getElementById("history"); |
|
79 var row = document.createElement("div"); |
|
80 row.className = "row"; |
|
81 if (historyDisplay.childNodes.length % 2) |
|
82 row.className += " alt"; |
|
83 |
|
84 if (exp.length > 0) { |
|
85 var expression = document.createElement("div"); |
|
86 expression.className = "expression"; |
|
87 expression.innerText = exp; |
|
88 row.appendChild(expression); |
|
89 } |
|
90 |
|
91 var result = document.createElement("div"); |
|
92 result.className = "result"; |
|
93 result.innerText = msg; |
|
94 |
|
95 row.appendChild(result); |
|
96 |
|
97 historyDisplay.appendChild(row); |
|
98 historyDisplay.scrollTop = historyDisplay.scrollHeight; |
|
99 } |
|
100 |
|
101 function sendScript(script) |
|
102 { |
|
103 appendMessage(script, mainWindow.DebuggerDocument.evaluateScript(script, mainWindow.currentCallFrame.index)); |
|
104 if (script.indexOf("=") >= 0) |
|
105 mainWindow.currentCallFrame.loadVariables(); |
|
106 } |
|
107 |
|
108 function unloading() |
|
109 { |
|
110 mainWindow.consoleWindow = null; |
|
111 } |