OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | |
29 function a() { b(); }; | 28 function a() { b(); }; |
30 function b() { | 29 function b() { |
31 c(true); | 30 c(true); |
32 }; | 31 }; |
33 function c(x) { | 32 function c(x) { |
34 if (x) { | 33 if (x) { |
35 return 1; | 34 return 1; |
36 } else { | 35 } else { |
37 return 1; | 36 return 1; |
38 } | 37 } |
39 }; | 38 }; |
40 function d(x) { | 39 function d(x) { |
41 x = 1 ; | 40 x = 1 ; |
42 x = 2 ; | 41 x = 2 ; |
43 x = 3 ; | 42 x = 3 ; |
44 x = 4 ; | 43 x = 4 ; |
45 x = 5 ; | 44 x = 5 ; |
46 x = 6 ; | 45 x = 6 ; |
47 x = 7 ; | 46 x = 7 ; |
48 x = 8 ; | 47 x = 8 ; |
49 x = 9 ; | 48 x = 9 ; |
50 x = 10; | 49 x = 10; |
51 x = 11; | 50 x = 11; |
52 x = 12; | 51 x = 12; |
53 x = 13; | 52 x = 13; |
54 x = 14; | 53 x = 14; |
55 x = 15; | 54 x = 15; |
56 } | 55 } |
57 | 56 |
58 // Get the Debug object exposed from the debug context global object. | |
59 Debug = debug.Debug | 57 Debug = debug.Debug |
60 | 58 |
61 // This is the number of comment lines above the first test function. | 59 // This is the number of comment lines above the first test function. |
62 var comment_lines = 28; | 60 var comment_lines = 27; |
63 | 61 |
64 // This is the last position in the entire file (note: this equals | 62 // This is the last position in the entire file (note: this equals |
65 // file size of <debug-sourceinfo.js> - 1, since starting at 0). | 63 // file size of <debug-sourceinfo.js> - 1, since starting at 0). |
66 var last_position = 8126; | 64 var last_position = 8022; |
67 // This is the last line of entire file (note: starting at 0). | 65 // This is the last line of entire file (note: starting at 0). |
68 var last_line = 200; | 66 var last_line = 198; |
69 // This is the last column of last line (note: starting at 0). | 67 // This is the last column of last line (note: starting at 0). |
70 var last_column = 71; | 68 var last_column = 71; |
71 | 69 |
72 // This magic number is the length or the first line comment (actually number | 70 // This magic number is the length or the first line comment (actually number |
73 // of characters before 'function a(...'. | 71 // of characters before 'function a(...'. |
74 var comment_line_length = 1633; | 72 var comment_line_length = 1599; |
75 var start_a = 9 + comment_line_length; | 73 var start_a = 9 + comment_line_length; |
76 var start_b = 35 + comment_line_length; | 74 var start_b = 35 + comment_line_length; |
77 var start_c = 66 + comment_line_length; | 75 var start_c = 66 + comment_line_length; |
78 var start_d = 151 + comment_line_length; | 76 var start_d = 151 + comment_line_length; |
79 | 77 |
80 // The position of the first line of d(), i.e. "x = 1 ;". | 78 // The position of the first line of d(), i.e. "x = 1 ;". |
81 var start_code_d = start_d + 6; | 79 var start_code_d = start_d + 6; |
82 // The line # of the first line of d() (note: starting at 0). | 80 // The line # of the first line of d() (note: starting at 0). |
83 var start_line_d = 40; | 81 var start_line_d = 39; |
84 var line_length_d = 10; | 82 var line_length_d = 10; |
85 var num_lines_d = 15; | 83 var num_lines_d = 15; |
86 | 84 |
87 assertEquals(start_a, Debug.sourcePosition(a)); | 85 assertEquals(start_a, Debug.sourcePosition(a)); |
88 assertEquals(start_b, Debug.sourcePosition(b)); | 86 assertEquals(start_b, Debug.sourcePosition(b)); |
89 assertEquals(start_c, Debug.sourcePosition(c)); | 87 assertEquals(start_c, Debug.sourcePosition(c)); |
90 assertEquals(start_d, Debug.sourcePosition(d)); | 88 assertEquals(start_d, Debug.sourcePosition(d)); |
91 | 89 |
92 var script = Debug.findScript(a); | 90 var script = Debug.findScript(a); |
93 assertTrue(script.data === Debug.findScript(b).data); | 91 assertTrue(script.data === Debug.findScript(b).data); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 assertEquals(0, script.locationFromPosition(-1).line); | 190 assertEquals(0, script.locationFromPosition(-1).line); |
193 assertEquals(null, script.locationFromPosition(last_position + 2)); | 191 assertEquals(null, script.locationFromPosition(last_position + 2)); |
194 | 192 |
195 // Test last position. | 193 // Test last position. |
196 assertEquals(last_position, script.locationFromPosition(last_position).position)
; | 194 assertEquals(last_position, script.locationFromPosition(last_position).position)
; |
197 assertEquals(last_line, script.locationFromPosition(last_position).line); | 195 assertEquals(last_line, script.locationFromPosition(last_position).line); |
198 assertEquals(last_column, script.locationFromPosition(last_position).column); | 196 assertEquals(last_column, script.locationFromPosition(last_position).column); |
199 assertEquals(last_line + 1, | 197 assertEquals(last_line + 1, |
200 script.locationFromPosition(last_position + 1).line); | 198 script.locationFromPosition(last_position + 1).line); |
201 assertEquals(0, script.locationFromPosition(last_position + 1).column); | 199 assertEquals(0, script.locationFromPosition(last_position + 1).column); |
OLD | NEW |