
CHAPTER 2: The ExtendScript Toolkit Debugging in the Toolkit 31
Setting breakpoints
When debugging a script, it is often helpful to make it stop at certain lines so that you can inspect the state
of the environment, whether function calls are nested properly, or whether all variables contain the
expected data.
X To stop execution of a script at a given line, click to the left of the line number to set a breakpoint. A
red dot indicates the breakpoint.
X Click a second time to temporarily disable the breakpoint; the icon changes color.
X Click a third time to delete the breakpoint. The icon is removed.
Some breakpoints need to be conditional. For example, if you set a breakpoint in a loop that is executed
several thousand times, you would not want to have the program stop each time through the loop, but
only on each 1000th iteration.
You can attach a condition to a breakpoint, in the form of a JavaScript expression. Every time execution
reaches the breakpoint, it runs the JavaScript expression. If the expression evaluates to a nonzero number
or true, execution stops.
To set a conditional breakpoint in a loop, for example, the conditional expression could be
"i >= 1000",
which means that the program execution halts if the value of the iteration variable
i is equal to or greater
than 1000.
T
IP: It is often useful to check the boundary conditions for loops; to do this, you can set the condition for a
breakpoint within a loop to trigger on the first and last iterations.
You can set breakpoints on lines that do not contain any code, such as comment lines. When the Toolkit
runs the program, it automatically moves such a breakpoint down to the next line that actually contains
code.
The Breakpoints panel
The Breakpoints panel displays all breakpoints set in the current document window. You can use the
panel’s flyout menu to add, change, or remove a breakpoint.
You can edit a breakpoint by double-clicking it, or by selecting it and choosing Add or Modify from the
panel menu. A dialog allows you to change the line number, the breakpoint’s enabled state, and the
Komentarze do niniejszej Instrukcji