19258b6bc66e09368ada54001f619d53b4fc976d5ager@chromium.org// Copyright 2008 the V8 project authors. All rights reserved. 29a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Redistribution and use in source and binary forms, with or without 39a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// modification, are permitted provided that the following conditions are 49a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// met: 59a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// 69a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Redistributions of source code must retain the above copyright 79a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// notice, this list of conditions and the following disclaimer. 89a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Redistributions in binary form must reproduce the above 99a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// copyright notice, this list of conditions and the following 109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// disclaimer in the documentation and/or other materials provided 119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// with the distribution. 129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// * Neither the name of Google Inc. nor the names of its 139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// contributors may be used to endorse or promote products derived 149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// from this software without specific prior written permission. 159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// 169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Flags: --expose-debug-as debug 299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// For this test to work this file MUST have CR LF line endings. 309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfunction a() { b(); }; 319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfunction b() { 329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com c(true); 339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}; 349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com function c(x) { 359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com if (x) { 369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com return 1; 379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } else { 389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com return 1; 399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com }; 41eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgfunction d(x) { 42eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 1 ; 43eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 2 ; 44eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 3 ; 45eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 4 ; 46eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 5 ; 47eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 6 ; 48eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 7 ; 49eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 8 ; 50eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 9 ; 51eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 10; 52eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 11; 53eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 12; 54eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 13; 55eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 14; 56eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org x = 15; 57eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org} 589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Get the Debug object exposed from the debug context global object. 609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comDebug = debug.Debug 619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// This is the number of comment lines above the first test function. 639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar comment_lines = 29; 649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 65eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// This is the last position in the entire file (note: this equals 66eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// file size of <debug-sourceinfo.js> - 1, since starting at 0). 673e87580939cb78c5802369f723680d4a16cc2902ager@chromium.orgvar last_position = 14312; 68eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// This is the last line of entire file (note: starting at 0). 693e87580939cb78c5802369f723680d4a16cc2902ager@chromium.orgvar last_line = 351; 70eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// This is the last column of last line (note: starting at 0 and +2, due 71eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// to trailing <CR><LF>). 723e87580939cb78c5802369f723680d4a16cc2902ager@chromium.orgvar last_column = 2; 73eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// This magic number is the length or the first line comment (actually number 759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// of characters before 'function a(...'. 769258b6bc66e09368ada54001f619d53b4fc976d5ager@chromium.orgvar comment_line_length = 1726; 779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar start_a = 10 + comment_line_length; 789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar start_b = 37 + comment_line_length; 799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar start_c = 71 + comment_line_length; 80eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar start_d = 163 + comment_line_length; 81eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 82eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// The position of the first line of d(), i.e. "x = 1 ;". 83eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar start_code_d = start_d + 7; 84eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// The line # of the first line of d() (note: starting at 0). 85eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar start_line_d = 41; 86eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar line_length_d = 11; 87eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar num_lines_d = 15; 889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a, Debug.sourcePosition(a)); 909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b, Debug.sourcePosition(b)); 919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_c, Debug.sourcePosition(c)); 92eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(start_d, Debug.sourcePosition(d)); 939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar script = Debug.findScript(a); 959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertTrue(script.data === Debug.findScript(b).data); 969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertTrue(script.data === Debug.findScript(c).data); 97eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertTrue(script.data === Debug.findScript(d).data); 989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertTrue(script.source === Debug.findScript(b).source); 999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertTrue(script.source === Debug.findScript(c).source); 100eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertTrue(script.source === Debug.findScript(d).source); 1019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 1029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test that when running through source positions the position, line and 1039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// column progresses as expected. 1049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar position; 1059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar line; 1069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar column; 1079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfor (var p = 0; p < 100; p++) { 1089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com var location = script.locationFromPosition(p); 1099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com if (p > 0) { 1109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(position + 1, location.position); 1119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com if (line == location.line) { 1129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(column + 1, location.column); 1139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } else { 1149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(line + 1, location.line); 1159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(0, location.column); 1169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 1179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } else { 1189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(0, location.position); 1199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(0, location.line); 1209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(0, location.column); 1219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com } 1229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 1239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com // Remember the location. 1249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com position = location.position; 1259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com line = location.line; 1269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com column = location.column; 1279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com} 1289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 129eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Every line of d() is the same length. Verify we can loop through all 130eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// positions and find the right line # for each. 131eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvar p = start_code_d; 132eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgfor (line = 0; line < num_lines_d; line++) { 133eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org for (column = 0; column < line_length_d; column++) { 134eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org var location = script.locationFromPosition(p); 135eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org assertEquals(p, location.position); 136eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org assertEquals(start_line_d + line, location.line); 137eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org assertEquals(column, location.column); 138eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org p++; 139eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org } 140eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org} 141eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 1429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test first position. 1439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromPosition(0).position); 1449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromPosition(0).line); 1459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromPosition(0).column); 1469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 1479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test second position. 1489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromPosition(1).position); 1499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromPosition(1).line); 1509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromPosition(1).column); 1519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 152eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first position in function a(). 1539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a, script.locationFromPosition(start_a).position); 1549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromPosition(start_a).line - comment_lines); 1559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(10, script.locationFromPosition(start_a).column); 1569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 157eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first position in function b(). 1589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b, script.locationFromPosition(start_b).position); 1599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromPosition(start_b).line - comment_lines); 1609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(13, script.locationFromPosition(start_b).column); 1619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 162eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first position in function c(). 1639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_c, script.locationFromPosition(start_c).position); 1649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(4, script.locationFromPosition(start_c).line - comment_lines); 1659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(12, script.locationFromPosition(start_c).column); 1669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 167eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first position in function d(). 168eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(start_d, script.locationFromPosition(start_d).position); 169eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(11, script.locationFromPosition(start_d).line - comment_lines); 170eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(10, script.locationFromPosition(start_d).column); 171eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 1729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test first line. 1739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine().position); 1749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine().line); 1759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine().column); 1769a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0).position); 1779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0).line); 1789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0).column); 1799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 180eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first line column 1. 1819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(0, 1).position); 1829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0, 1).line); 1839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(0, 1).column); 1849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 185eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test first line offset 1. 1869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(0, 0, 1).position); 1879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0, 0, 1).line); 1889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(0, 0, 1).column); 1899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 190eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test offset function a(). 1919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a, script.locationFromLine(void 0, void 0, start_a).position); 1929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(void 0, void 0, start_a).line - comment_lines); 1939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(10, script.locationFromLine(void 0, void 0, start_a).column); 1949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a, script.locationFromLine(0, void 0, start_a).position); 1959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0, void 0, start_a).line - comment_lines); 1969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(10, script.locationFromLine(0, void 0, start_a).column); 1979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a, script.locationFromLine(0, 0, start_a).position); 1989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(0, 0, start_a).line - comment_lines); 1999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(10, script.locationFromLine(0, 0, start_a).column); 2009a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 201eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test second line offset function a(). 2029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a + 14, script.locationFromLine(1, 0, start_a).position); 2039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(1, 0, start_a).line - comment_lines); 2049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(1, 0, start_a).column); 2059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 206eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test second line column 2 offset function a(). 2079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_a + 14 + 2, script.locationFromLine(1, 2, start_a).position); 2089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(1, 2, start_a).line - comment_lines); 2099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(2, script.locationFromLine(1, 2, start_a).column); 2109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 211eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test offset function b(). 2129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b, script.locationFromLine(0, 0, start_b).position); 2139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(1, script.locationFromLine(0, 0, start_b).line - comment_lines); 2149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(13, script.locationFromLine(0, 0, start_b).column); 2159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 216eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test second line offset function b(). 2179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b + 6, script.locationFromLine(1, 0, start_b).position); 2189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(2, script.locationFromLine(1, 0, start_b).line - comment_lines); 2199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(1, 0, start_b).column); 2209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 221eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test second line column 11 offset function b(). 2229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b + 6 + 11, script.locationFromLine(1, 11, start_b).position); 2239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(2, script.locationFromLine(1, 11, start_b).line - comment_lines); 2249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(11, script.locationFromLine(1, 11, start_b).column); 2259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test second line column 12 offset function b. Second line in b is 11 long 2279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// using column 12 wraps to next line. 2289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(start_b + 6 + 12, script.locationFromLine(1, 12, start_b).position); 2299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(3, script.locationFromLine(1, 12, start_b).line - comment_lines); 2309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(0, script.locationFromLine(1, 12, start_b).column); 2319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test the Debug.findSourcePosition which wraps SourceManager. 2337be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(0 + start_a, Debug.findFunctionSourceLocation(a, 0, 0).position); 2347be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(0 + start_b, Debug.findFunctionSourceLocation(b, 0, 0).position); 2357be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(6 + start_b, Debug.findFunctionSourceLocation(b, 1, 0).position); 2367be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(8 + start_b, Debug.findFunctionSourceLocation(b, 1, 2).position); 2377be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(18 + start_b, Debug.findFunctionSourceLocation(b, 2, 0).position); 2387be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(0 + start_c, Debug.findFunctionSourceLocation(c, 0, 0).position); 2397be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(7 + start_c, Debug.findFunctionSourceLocation(c, 1, 0).position); 2407be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(21 + start_c, Debug.findFunctionSourceLocation(c, 2, 0).position); 2417be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(38 + start_c, Debug.findFunctionSourceLocation(c, 3, 0).position); 2427be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(52 + start_c, Debug.findFunctionSourceLocation(c, 4, 0).position); 2437be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(69 + start_c, Debug.findFunctionSourceLocation(c, 5, 0).position); 2447be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgassertEquals(76 + start_c, Debug.findFunctionSourceLocation(c, 6, 0).position); 245eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(0 + start_d, Debug.findFunctionSourceLocation(d, 0, 0).position); 246eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(7 + start_d, Debug.findFunctionSourceLocation(d, 1, 0).position); 247eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgfor (i = 1; i <= num_lines_d; i++) { 248eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org assertEquals(7 + (i * line_length_d) + start_d, Debug.findFunctionSourceLocation(d, (i + 1), 0).position); 249eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org} 250eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(175 + start_d, Debug.findFunctionSourceLocation(d, 17, 0).position); 251eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 252eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Make sure invalid inputs work properly. 253eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(0, script.locationFromPosition(-1).line); 254eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(null, script.locationFromPosition(last_position + 1)); 255eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org 256eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org// Test last position. 257eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(last_position, script.locationFromPosition(last_position).position); 258eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(last_line, script.locationFromPosition(last_position).line); 259eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgassertEquals(last_column, script.locationFromPosition(last_position).column); 2609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test source line and restriction. All the following tests start from line 1 2629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// column 2 in function b, which is the call to c. 2639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// c(true); 2649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// ^ 2659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvar location; 2679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 0, start_b); 2699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(true);', location.sourceText()); 2709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comresult = ['c', ' c', ' c(', ' c(', ' c(t'] 2729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comfor (var i = 1; i <= 5; i++) { 2739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com location = script.locationFromLine(1, 2, start_b); 2749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com location.restrict(i); 2759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com assertEquals(result[i - 1], location.sourceText()); 2769a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com} 2779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(1, 0); 2809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals('c', location.sourceText()); 2819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(2, 0); 2849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals('c(', location.sourceText()); 2859a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(2, 1); 2889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c', location.sourceText()); 2899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(2, 2); 2929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c', location.sourceText()); 2939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(2, 3); 2969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c', location.sourceText()); 2979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 2989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 2999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(3, 1); 3009a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(', location.sourceText()); 3019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 3039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 0); 3049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals('c(tru', location.sourceText()); 3059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 3079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 2); 3089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(t', location.sourceText()); 3099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 2, start_b); 3119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 4); 3129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(t', location.sourceText()); 3139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// All the following tests start from line 1 column 10 in function b, which is 3159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// the final character. 3169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// c(true); 3179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// ^ 3189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 10, start_b); 3209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 0); 3219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals('rue);', location.sourceText()); 3229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 10, start_b); 3249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(7, 0); 3259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals('(true);', location.sourceText()); 3269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// All the following tests start from line 1 column 0 in function b, which is 3289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// the first character. 3299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// c(true); 3309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//^ 3319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 0, start_b); 3339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 0); 3349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(t', location.sourceText()); 3359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 0, start_b); 3379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(5, 4); 3389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(t', location.sourceText()); 3399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 0, start_b); 3419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(7, 0); 3429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(tru', location.sourceText()); 3439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com 3449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation = script.locationFromLine(1, 0, start_b); 3459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comlocation.restrict(7, 6); 3469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comassertEquals(' c(tru', location.sourceText()); 3473e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org 3483e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org// Test that script.sourceLine(line) works. 3493e87580939cb78c5802369f723680d4a16cc2902ager@chromium.orgfor (line = 0; line < num_lines_d; line++) { 3503e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org var line_content_regexp = new RegExp(" x = " + (line + 1)); 3513e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); 3523e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org} 353