Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: test/mjsunit/debug-sourceinfo.js

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/debug-setexceptionbreak.js ('k') | test/mjsunit/debug-sourceslice.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 // Flags: --expose-debug-as debug
29 // For this test to work this file MUST have CR LF line endings. 29 // For this test to work this file MUST have CR LF line endings.
30 function a() { b(); }; 30 function a() { b(); }
31 function b() { 31 function b() {
32 c(true); 32 c(true);
33 }; 33 }
34 function c(x) { 34 function c(x) {
35 if (x) { 35 if (x) {
36 return 1; 36 return 1;
37 } else { 37 } else {
38 return 1; 38 return 1;
39 } 39 }
40 }; 40 }
41 function d(x) { 41 function d(x) {
42 x = 1 ; 42 x = 1 ;
43 x = 2 ; 43 x = 2 ;
44 x = 3 ; 44 x = 3 ;
45 x = 4 ; 45 x = 4 ;
46 x = 5 ; 46 x = 5 ;
47 x = 6 ; 47 x = 6 ;
48 x = 7 ; 48 x = 7 ;
49 x = 8 ; 49 x = 8 ;
50 x = 9 ; 50 x = 9 ;
51 x = 10; 51 x = 10;
52 x = 11; 52 x = 11;
53 x = 12; 53 x = 12;
54 x = 13; 54 x = 13;
55 x = 14; 55 x = 14;
56 x = 15; 56 x = 15;
57 } 57 }
58 58
59 // Get the Debug object exposed from the debug context global object. 59 // Get the Debug object exposed from the debug context global object.
60 Debug = debug.Debug 60 Debug = debug.Debug;
61 61
62 // This is the number of comment lines above the first test function. 62 // This is the number of comment lines above the first test function.
63 var comment_lines = 29; 63 var comment_lines = 29;
64 64
65 // This is the last position in the entire file (note: this equals 65 // This is the last position in the entire file (note: this equals
66 // file size of <debug-sourceinfo.js> - 1, since starting at 0). 66 // file size of <debug-sourceinfo.js> - 1, since starting at 0).
67 var last_position = 14312; 67 var last_position = 14311;
68 // This is the last line of entire file (note: starting at 0). 68 // This is the last line of entire file (note: starting at 0).
69 var last_line = 351; 69 var last_line = 351;
70 // This is the last column of last line (note: starting at 0 and +2, due 70 // This is the last column of last line (note: starting at 0 and +2, due
71 // to trailing <CR><LF>). 71 // to trailing <CR><LF>).
72 var last_column = 2; 72 var last_column = 2;
73 73
74 // This magic number is the length or the first line comment (actually number 74 // This magic number is the length or the first line comment (actually number
75 // of characters before 'function a(...'. 75 // of characters before 'function a(...'.
76 var comment_line_length = 1726; 76 var comment_line_length = 1726;
77 var start_a = 10 + comment_line_length; 77 var start_a = 10 + comment_line_length;
78 var start_b = 37 + comment_line_length; 78 var start_b = 36 + comment_line_length;
79 var start_c = 71 + comment_line_length; 79 var start_c = 69 + comment_line_length;
80 var start_d = 163 + comment_line_length; 80 var start_d = 160 + comment_line_length;
81 81
82 // The position of the first line of d(), i.e. "x = 1 ;". 82 // The position of the first line of d(), i.e. "x = 1 ;".
83 var start_code_d = start_d + 7; 83 var start_code_d = start_d + 7;
84 // The line # of the first line of d() (note: starting at 0). 84 // The line # of the first line of d() (note: starting at 0).
85 var start_line_d = 41; 85 var start_line_d = 41;
86 var line_length_d = 11; 86 var line_length_d = 11;
87 var num_lines_d = 15; 87 var num_lines_d = 15;
88 88
89 assertEquals(start_a, Debug.sourcePosition(a)); 89 assertEquals(start_a, Debug.sourcePosition(a));
90 assertEquals(start_b, Debug.sourcePosition(b)); 90 assertEquals(start_b, Debug.sourcePosition(b));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 assertEquals(0, script.locationFromLine(void 0, void 0, start_a).line - comment_ lines); 192 assertEquals(0, script.locationFromLine(void 0, void 0, start_a).line - comment_ lines);
193 assertEquals(10, script.locationFromLine(void 0, void 0, start_a).column); 193 assertEquals(10, script.locationFromLine(void 0, void 0, start_a).column);
194 assertEquals(start_a, script.locationFromLine(0, void 0, start_a).position); 194 assertEquals(start_a, script.locationFromLine(0, void 0, start_a).position);
195 assertEquals(0, script.locationFromLine(0, void 0, start_a).line - comment_lines ); 195 assertEquals(0, script.locationFromLine(0, void 0, start_a).line - comment_lines );
196 assertEquals(10, script.locationFromLine(0, void 0, start_a).column); 196 assertEquals(10, script.locationFromLine(0, void 0, start_a).column);
197 assertEquals(start_a, script.locationFromLine(0, 0, start_a).position); 197 assertEquals(start_a, script.locationFromLine(0, 0, start_a).position);
198 assertEquals(0, script.locationFromLine(0, 0, start_a).line - comment_lines); 198 assertEquals(0, script.locationFromLine(0, 0, start_a).line - comment_lines);
199 assertEquals(10, script.locationFromLine(0, 0, start_a).column); 199 assertEquals(10, script.locationFromLine(0, 0, start_a).column);
200 200
201 // Test second line offset function a(). 201 // Test second line offset function a().
202 assertEquals(start_a + 14, script.locationFromLine(1, 0, start_a).position); 202 assertEquals(start_a + 13, script.locationFromLine(1, 0, start_a).position);
203 assertEquals(1, script.locationFromLine(1, 0, start_a).line - comment_lines); 203 assertEquals(1, script.locationFromLine(1, 0, start_a).line - comment_lines);
204 assertEquals(0, script.locationFromLine(1, 0, start_a).column); 204 assertEquals(0, script.locationFromLine(1, 0, start_a).column);
205 205
206 // Test second line column 2 offset function a(). 206 // Test second line column 2 offset function a().
207 assertEquals(start_a + 14 + 2, script.locationFromLine(1, 2, start_a).position); 207 assertEquals(start_a + 13 + 2, script.locationFromLine(1, 2, start_a).position);
208 assertEquals(1, script.locationFromLine(1, 2, start_a).line - comment_lines); 208 assertEquals(1, script.locationFromLine(1, 2, start_a).line - comment_lines);
209 assertEquals(2, script.locationFromLine(1, 2, start_a).column); 209 assertEquals(2, script.locationFromLine(1, 2, start_a).column);
210 210
211 // Test offset function b(). 211 // Test offset function b().
212 assertEquals(start_b, script.locationFromLine(0, 0, start_b).position); 212 assertEquals(start_b, script.locationFromLine(0, 0, start_b).position);
213 assertEquals(1, script.locationFromLine(0, 0, start_b).line - comment_lines); 213 assertEquals(1, script.locationFromLine(0, 0, start_b).line - comment_lines);
214 assertEquals(13, script.locationFromLine(0, 0, start_b).column); 214 assertEquals(13, script.locationFromLine(0, 0, start_b).column);
215 215
216 // Test second line offset function b(). 216 // Test second line offset function b().
217 assertEquals(start_b + 6, script.locationFromLine(1, 0, start_b).position); 217 assertEquals(start_b + 6, script.locationFromLine(1, 0, start_b).position);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // Test source line and restriction. All the following tests start from line 1 261 // Test source line and restriction. All the following tests start from line 1
262 // column 2 in function b, which is the call to c. 262 // column 2 in function b, which is the call to c.
263 // c(true); 263 // c(true);
264 // ^ 264 // ^
265 265
266 var location; 266 var location;
267 267
268 location = script.locationFromLine(1, 0, start_b); 268 location = script.locationFromLine(1, 0, start_b);
269 assertEquals(' c(true);', location.sourceText()); 269 assertEquals(' c(true);', location.sourceText());
270 270
271 result = ['c', ' c', ' c(', ' c(', ' c(t'] 271 result = ['c', ' c', ' c(', ' c(', ' c(t'];
272 for (var i = 1; i <= 5; i++) { 272 for (var i = 1; i <= 5; i++) {
273 location = script.locationFromLine(1, 2, start_b); 273 location = script.locationFromLine(1, 2, start_b);
274 location.restrict(i); 274 location.restrict(i);
275 assertEquals(result[i - 1], location.sourceText()); 275 assertEquals(result[i - 1], location.sourceText());
276 } 276 }
277 277
278 location = script.locationFromLine(1, 2, start_b); 278 location = script.locationFromLine(1, 2, start_b);
279 location.restrict(1, 0); 279 location.restrict(1, 0);
280 assertEquals('c', location.sourceText()); 280 assertEquals('c', location.sourceText());
281 281
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 location = script.locationFromLine(1, 0, start_b); 344 location = script.locationFromLine(1, 0, start_b);
345 location.restrict(7, 6); 345 location.restrict(7, 6);
346 assertEquals(' c(tru', location.sourceText()); 346 assertEquals(' c(tru', location.sourceText());
347 347
348 // Test that script.sourceLine(line) works. 348 // Test that script.sourceLine(line) works.
349 for (line = 0; line < num_lines_d; line++) { 349 for (line = 0; line < num_lines_d; line++) {
350 var line_content_regexp = new RegExp(" x = " + (line + 1)); 350 var line_content_regexp = new RegExp(" x = " + (line + 1));
351 assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); 351 assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line)));
352 } 352 }
OLDNEW
« no previous file with comments | « test/mjsunit/debug-setexceptionbreak.js ('k') | test/mjsunit/debug-sourceslice.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698