Adobe 23101335 Scripting Guide - Page 29

Script Breakpoints Window, toSource, debugger, parseBox, function getRatio docRef

Page 29 highlights

Scripting basics 2 Testing and troubleshooting Script Breakpoints Display (no keyboard shortcut) Clicking this button displays the Script Breakpoints Window shown in Figure 2.2. Using the JavaScript Command Line Entry Field You can use the Script Debugger window's command line entry field to enter and execute Javascript code interactively within a specified stack scope. Commands entered in this field execute with a timeout of one second. Command line entry field. Enter in this field a JavaScript statement to execute within the stack scope of the line highlighted in the Stack Trace view. When you've finished entering the JavaScript expression, you can execute it by clicking the command line entry button or pressing the Enter key. Command line entry button. Click this button or press Enter to execute the JavaScript code in the command line entry field. Photoshop executes the contents of the command line entry field within the stack scope of the line highlighted in the Stack Trace view. The command line entry field accepts any JavaScript code, making it very convenient to use for inspecting or changing the contents of variables. NOTE: To list the contents of an object as if it were JavaScript source code, enter the object.toSource() command. Setting Breakpoints In the Script Debugger Window When the Photoshop Script Debugger window is active, you can double-click a line in the source view to set or clear a breakpoint at that line. Alternatively, you can click the BP button to display the Script Breakpoints window and set or clear breakpoints in this window. Setting Breakpoints in JavaScript Code Adding the debugger statement to a script sets an unconditional breakpoint. For example, the following code causes Photoshop to halt and display the script debug window as soon as it enters the parseBox function. function getRatio( docRef ) { debugger; var theRatio = ( docRef.height ) / ( docRef.width ); return theRatio; } alert( getRatio( activeDocument ) ); Photoshop 7.0 Scripting Guide 29

  • 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

Photoshop 7.0 Scripting Guide
29
Scripting basics
Testing and troubleshooting
2
Script Breakpoints Display
(no keyboard shortcut)
Clicking this button displays the
Script Breakpoints Window
shown in
Figure 2.2
.
Using the JavaScript Command Line Entry Field
You can use the Script Debugger window’s command line entry field to enter and execute
Javascript code interactively within a specified stack scope. Commands entered in this field
execute with a timeout of one second.
Command line entry field
. Enter in this field a JavaScript statement to execute
within the stack scope of the line highlighted in the
Stack Trace
view. When
you’ve finished entering the JavaScript expression, you can execute it by
clicking the command line entry button or pressing the
Enter
key.
Command line entry button.
Click this button or press
Enter
to execute the JavaScript
code in the command line entry field. Photoshop executes the contents of the command
line entry field within the stack scope of the line highlighted in the
Stack Trace
view.
The command line entry field accepts any JavaScript code, making it very convenient to use
for inspecting or changing the contents of variables.
N
OTE
:
To list the contents of an
object
as if it were JavaScript source code, enter the
object
.
toSource()
command.
Setting Breakpoints In the Script Debugger Window
When the Photoshop Script Debugger window is active, you can double-click a line in the
source view to set or clear a breakpoint at that line. Alternatively, you can click the BP button
to display the Script Breakpoints window and set or clear breakpoints in this window.
Setting Breakpoints in JavaScript Code
Adding the
debugger
statement to a script sets an unconditional breakpoint. For example, the
following code causes Photoshop to halt and display the script debug window as soon as it
enters the
parseBox
function.
function getRatio( docRef )
{
debugger;
var theRatio = ( docRef.height ) / ( docRef.width );
return theRatio;
}
alert( getRatio( activeDocument ) );