India seo web development website designer freelance
How the JavaScript Debugger module works
comes with two JavaScript Debugger modules, one for each supported browser, Netscape Navigator and Microsoft Internet Explorer. To provide support for a different browser, you must create a new module and use dom.instrumentDocument and .startDebugger to debug the document in that browser.
When you call dom.instrumentDocument , the specified module receives callbacks as parses the JavaScript in the document. So, for example, you could create a JavaScript Debugger module that inserts comments or records information about the JavaScript code, instead of inserting debugging enhancements.
When dom.instrumentDocument is called with a specific module, the following steps occur:
- calls getIncludeFiles() in the module. This function returns the list of files that will be referenced from the HTML instrumentation code that is returned from getHeadInstrument() and getBodyInstrument() , which are called in steps 13 and 14. The include files can be any type of file, such as an external JavaScript file, JavaApplet, or ActiveX control. All the files must be in the Configuration/Debugger subfolder with the module. will copy the include files to the directory that contains the file being debugged, and then will delete the include files from that directory when exits.
- Next, the HTML document is scanned for script tags and event handlers. The code inside the script tag, in an external JavaScript file or in an event handler, is called a block.
Note: An external JavaScript file is a file that is specified as the src attribute of a SCRIPT tag.
- parses script tags in the HEAD section first.
- When finds a script tag or event handler, it calls the startBlock() function of the module and passes in the name of the file and the line and character offsets from the beginning of the file.
- begins parsing the JavaScript code in the block.
- When finds a JavaScript statement, such as a variable declaration, it calls getStepInstrument() , passing the line and character offsets and other information. The module returns a string of JavaScript code that is inserted before the statement. You must take care to insert valid JavaScript code. For each call to getStepInstrument() , records the line number as a valid breakpoint line regardless of the instrumentation that returns. So, when the debugger is started with dw.startDebugger() , the breakpoints that are already set by the user will be moved to one of these valid lines.
- When finds a function declaration, it calls getFunctionStartInstrument() to receive the instrumentation to be inserted at the beginning of the function.
Note: This is not considered a valid breakpoint line.
- continues parsing the function, calling getStepInstrument() for each statement in the function.
- When comes to a return statement, or the end of the function, it calls getFunctionEndInstument() to receive the instrumentation to be inserted before the function returns.
Note: This is not considered a valid breakpoint line.
- If encounters a syntax error or warning in the JavaScript block, it calls reportError() or reportWarning() , respectively. After an error is encountered, stops parsing the block. Other blocks continue to be parsed.
- After has parsed all the script blocks in the HEAD section, it calls getHeadInstrument() to get the HTML instrumentation to insert in the HEAD section.
Note: This function should return HTML, not JavaScript. If the module needs to insert JavaScript code in the HEAD , it must enclose it in a SCRIPT tag.
- begins processing the JavaScript blocks ( SCRIPT tags and event handlers) in the BODY section of the document.
- After the last block in the BODY section is processed, calls getBodyInstrument() to get the HTML instrumentation to insert in the BODY section.
Note: This function should return HTML, not JavaScript.
- After calls getBodyInstrument() , there is one final call to startBlock() and getStepInstrument() for an auto-breakpoint. The instrumentation does not correspond to any user-defined SCRIPT tag, but instead, it is inserted in a new SCRIPT tag after the BODY instrumentation. Unlike other calls to getStepInstrument() , this line is not considered a valid line on which the user can set a breakpoint, but instead, it is treated as a special breakpoint where the debugger always stops.
- Finally, calls getOnUnloadInstrument() to get JavaScript instrumentation to be inserted in the onUnload handler of the BODY tag. If the document already has an onUnload handler, this instrumentation is inserted after the user-defined onUnload code.
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117