| 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 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Get the Debug object exposed from the debug context global object. | 58 // Get the Debug object exposed from the debug context global object. |
| 59 Debug = debug.Debug | 59 Debug = debug.Debug |
| 60 | 60 |
| 61 // This is the number of comment lines above the first test function. | 61 // This is the number of comment lines above the first test function. |
| 62 var comment_lines = 28; | 62 var comment_lines = 28; |
| 63 | 63 |
| 64 // This is the last position in the entire file (note: this equals | 64 // This is the last position in the entire file (note: this equals |
| 65 // file size of <debug-sourceinfo.js> - 1, since starting at 0). | 65 // file size of <debug-sourceinfo.js> - 1, since starting at 0). |
| 66 var last_position = 13890; | 66 var last_position = 11337; |
| 67 // This is the last line of entire file (note: starting at 0). | 67 // This is the last line of entire file (note: starting at 0). |
| 68 var last_line = 350; | 68 var last_line = 265; |
| 69 // This is the last column of last line (note: starting at 0 and +1, due | 69 // This is the last column of last line (note: starting at 0 and +1, due |
| 70 // to trailing <LF>). | 70 // to trailing <LF>). |
| 71 var last_column = 1; | 71 var last_column = 1; |
| 72 | 72 |
| 73 // This magic number is the length or the first line comment (actually number | 73 // This magic number is the length or the first line comment (actually number |
| 74 // of characters before 'function a(...'. | 74 // of characters before 'function a(...'. |
| 75 var comment_line_length = 1633; | 75 var comment_line_length = 1633; |
| 76 var start_a = 9 + comment_line_length; | 76 var start_a = 9 + comment_line_length; |
| 77 var start_b = 35 + comment_line_length; | 77 var start_b = 35 + comment_line_length; |
| 78 var start_c = 66 + comment_line_length; | 78 var start_c = 66 + comment_line_length; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 // Make sure invalid inputs work properly. | 251 // Make sure invalid inputs work properly. |
| 252 assertEquals(0, script.locationFromPosition(-1).line); | 252 assertEquals(0, script.locationFromPosition(-1).line); |
| 253 assertEquals(null, script.locationFromPosition(last_position + 1)); | 253 assertEquals(null, script.locationFromPosition(last_position + 1)); |
| 254 | 254 |
| 255 // Test last position. | 255 // Test last position. |
| 256 assertEquals(last_position, script.locationFromPosition(last_position).position)
; | 256 assertEquals(last_position, script.locationFromPosition(last_position).position)
; |
| 257 assertEquals(last_line, script.locationFromPosition(last_position).line); | 257 assertEquals(last_line, script.locationFromPosition(last_position).line); |
| 258 assertEquals(last_column, script.locationFromPosition(last_position).column); | 258 assertEquals(last_column, script.locationFromPosition(last_position).column); |
| 259 | 259 |
| 260 // Test source line and restriction. All the following tests start from line 1 | 260 // Test that script.sourceLine(line) works. |
| 261 // column 2 in function b, which is the call to c. | |
| 262 // c(true); | |
| 263 // ^ | |
| 264 | |
| 265 var location; | 261 var location; |
| 266 | 262 |
| 267 location = script.locationFromLine(1, 0, start_b); | |
| 268 assertEquals(' c(true);', location.sourceText()); | |
| 269 | |
| 270 result = ['c', ' c', ' c(', ' c(', ' c(t'] | |
| 271 for (var i = 1; i <= 5; i++) { | |
| 272 location = script.locationFromLine(1, 2, start_b); | |
| 273 location.restrict(i); | |
| 274 assertEquals(result[i - 1], location.sourceText()); | |
| 275 } | |
| 276 | |
| 277 location = script.locationFromLine(1, 2, start_b); | |
| 278 location.restrict(1, 0); | |
| 279 assertEquals('c', location.sourceText()); | |
| 280 | |
| 281 location = script.locationFromLine(1, 2, start_b); | |
| 282 location.restrict(2, 0); | |
| 283 assertEquals('c(', location.sourceText()); | |
| 284 | |
| 285 location = script.locationFromLine(1, 2, start_b); | |
| 286 location.restrict(2, 1); | |
| 287 assertEquals(' c', location.sourceText()); | |
| 288 | |
| 289 location = script.locationFromLine(1, 2, start_b); | |
| 290 location.restrict(2, 2); | |
| 291 assertEquals(' c', location.sourceText()); | |
| 292 | |
| 293 location = script.locationFromLine(1, 2, start_b); | |
| 294 location.restrict(2, 3); | |
| 295 assertEquals(' c', location.sourceText()); | |
| 296 | |
| 297 location = script.locationFromLine(1, 2, start_b); | |
| 298 location.restrict(3, 1); | |
| 299 assertEquals(' c(', location.sourceText()); | |
| 300 | |
| 301 location = script.locationFromLine(1, 2, start_b); | |
| 302 location.restrict(5, 0); | |
| 303 assertEquals('c(tru', location.sourceText()); | |
| 304 | |
| 305 location = script.locationFromLine(1, 2, start_b); | |
| 306 location.restrict(5, 2); | |
| 307 assertEquals(' c(t', location.sourceText()); | |
| 308 | |
| 309 location = script.locationFromLine(1, 2, start_b); | |
| 310 location.restrict(5, 4); | |
| 311 assertEquals(' c(t', location.sourceText()); | |
| 312 | |
| 313 // All the following tests start from line 1 column 10 in function b, which is | |
| 314 // the final character. | |
| 315 // c(true); | |
| 316 // ^ | |
| 317 | |
| 318 location = script.locationFromLine(1, 10, start_b); | |
| 319 location.restrict(5, 0); | |
| 320 assertEquals('rue);', location.sourceText()); | |
| 321 | |
| 322 location = script.locationFromLine(1, 10, start_b); | |
| 323 location.restrict(7, 0); | |
| 324 assertEquals('(true);', location.sourceText()); | |
| 325 | |
| 326 // All the following tests start from line 1 column 0 in function b, which is | |
| 327 // the first character. | |
| 328 // c(true); | |
| 329 //^ | |
| 330 | |
| 331 location = script.locationFromLine(1, 0, start_b); | |
| 332 location.restrict(5, 0); | |
| 333 assertEquals(' c(t', location.sourceText()); | |
| 334 | |
| 335 location = script.locationFromLine(1, 0, start_b); | |
| 336 location.restrict(5, 4); | |
| 337 assertEquals(' c(t', location.sourceText()); | |
| 338 | |
| 339 location = script.locationFromLine(1, 0, start_b); | |
| 340 location.restrict(7, 0); | |
| 341 assertEquals(' c(tru', location.sourceText()); | |
| 342 | |
| 343 location = script.locationFromLine(1, 0, start_b); | |
| 344 location.restrict(7, 6); | |
| 345 assertEquals(' c(tru', location.sourceText()); | |
| 346 | |
| 347 // Test that script.sourceLine(line) works. | |
| 348 for (line = 0; line < num_lines_d; line++) { | 263 for (line = 0; line < num_lines_d; line++) { |
| 349 var line_content_regexp = new RegExp(" x = " + (line + 1)); | 264 var line_content_regexp = new RegExp(" x = " + (line + 1)); |
| 350 assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); | 265 assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); |
| 351 } | 266 } |
| OLD | NEW |