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

Side by Side Diff: src/debug/debug.js

Issue 2003303002: Remove inessential functions from the JS Script class (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « no previous file | src/debug/mirrors.js » ('j') | src/runtime/runtime-debug.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function (global, utils) { 5 (function (global, utils) {
6 "use strict"; 6 "use strict";
7 7
8 // ---------------------------------------------------------------------------- 8 // ----------------------------------------------------------------------------
9 // Imports 9 // Imports
10 10
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 354
355 355
356 // Check whether a script matches this script break point. Currently this is 356 // Check whether a script matches this script break point. Currently this is
357 // only based on script name. 357 // only based on script name.
358 ScriptBreakPoint.prototype.matchesScript = function(script) { 358 ScriptBreakPoint.prototype.matchesScript = function(script) {
359 if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { 359 if (this.type_ == Debug.ScriptBreakPointType.ScriptId) {
360 return this.script_id_ == script.id; 360 return this.script_id_ == script.id;
361 } else { 361 } else {
362 // We might want to account columns here as well. 362 // We might want to account columns here as well.
363 if (!(script.line_offset <= this.line_ && 363 if (!(script.line_offset <= this.line_ &&
364 this.line_ < script.line_offset + script.lineCount())) { 364 this.line_ < script.line_offset + %ScriptLineCount(script))) {
365 return false; 365 return false;
366 } 366 }
367 if (this.type_ == Debug.ScriptBreakPointType.ScriptName) { 367 if (this.type_ == Debug.ScriptBreakPointType.ScriptName) {
368 return this.script_name_ == script.nameOrSourceURL(); 368 return this.script_name_ == script.nameOrSourceURL();
369 } else if (this.type_ == Debug.ScriptBreakPointType.ScriptRegExp) { 369 } else if (this.type_ == Debug.ScriptBreakPointType.ScriptRegExp) {
370 return this.script_regexp_object_.test(script.nameOrSourceURL()); 370 return this.script_regexp_object_.test(script.nameOrSourceURL());
371 } else { 371 } else {
372 throw MakeError(kDebugger, "Unexpected breakpoint type " + this.type_); 372 throw MakeError(kDebugger, "Unexpected breakpoint type " + this.type_);
373 } 373 }
374 } 374 }
375 }; 375 };
376 376
377 377
378 // Set the script break point in a script. 378 // Set the script break point in a script.
379 ScriptBreakPoint.prototype.set = function (script) { 379 ScriptBreakPoint.prototype.set = function (script) {
380 var column = this.column(); 380 var column = this.column();
381 var line = this.line(); 381 var line = this.line();
382 // If the column is undefined the break is on the line. To help locate the 382 // If the column is undefined the break is on the line. To help locate the
383 // first piece of breakable code on the line try to find the column on the 383 // first piece of breakable code on the line try to find the column on the
384 // line which contains some source. 384 // line which contains some source.
385 if (IS_UNDEFINED(column)) { 385 if (IS_UNDEFINED(column)) {
386 var source_line = script.sourceLine(this.line()); 386 var source_line = %ScriptSourceLine(script, line || script.line_offset);
387 387
388 // Allocate array for caching the columns where the actual source starts. 388 // Allocate array for caching the columns where the actual source starts.
389 if (!script.sourceColumnStart_) { 389 if (!script.sourceColumnStart_) {
390 script.sourceColumnStart_ = new GlobalArray(script.lineCount()); 390 script.sourceColumnStart_ = new GlobalArray(%ScriptLineCount(script));
391 } 391 }
392 392
393 // Fill cache if needed and get column where the actual source starts. 393 // Fill cache if needed and get column where the actual source starts.
394 if (IS_UNDEFINED(script.sourceColumnStart_[line])) { 394 if (IS_UNDEFINED(script.sourceColumnStart_[line])) {
395 script.sourceColumnStart_[line] = 395 script.sourceColumnStart_[line] =
396 source_line.match(sourceLineBeginningSkip)[0].length; 396 source_line.match(sourceLineBeginningSkip)[0].length;
397 } 397 }
398 column = script.sourceColumnStart_[line]; 398 column = script.sourceColumnStart_[line];
399 } 399 }
400 400
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 529
530 Debug.sourcePosition = function(f) { 530 Debug.sourcePosition = function(f) {
531 if (!IS_FUNCTION(f)) throw MakeTypeError(kDebuggerType); 531 if (!IS_FUNCTION(f)) throw MakeTypeError(kDebuggerType);
532 return %FunctionGetScriptSourcePosition(f); 532 return %FunctionGetScriptSourcePosition(f);
533 }; 533 };
534 534
535 535
536 Debug.findFunctionSourceLocation = function(func, opt_line, opt_column) { 536 Debug.findFunctionSourceLocation = function(func, opt_line, opt_column) {
537 var script = %FunctionGetScript(func); 537 var script = %FunctionGetScript(func);
538 var script_offset = %FunctionGetScriptSourcePosition(func); 538 var script_offset = %FunctionGetScriptSourcePosition(func);
539 return script.locationFromLine(opt_line, opt_column, script_offset); 539
540 // Handle possibly undefined args. ScriptLocationFromLine expects line and
541 // column to include offsets.
542 var line = IS_NULL_OR_UNDEFINED(opt_line) ? script.line_offset : opt_line;
543 var column;
544 if (IS_NULL_OR_UNDEFINED(opt_column)) {
545 column = (line == script.line_offset) ? script.column_offset : 0;
546 } else {
547 column = opt_column;
548 }
549
550 return %ScriptLocationFromLine(script, line, column, script_offset);
Yang 2016/05/24 07:54:31 We could include the undefined handling in %Script
jgruber 2016/05/24 10:52:55 Done.
540 }; 551 };
541 552
542 553
543 // Returns the character position in a script based on a line number and an 554 // Returns the character position in a script based on a line number and an
544 // optional position within that line. 555 // optional position within that line.
545 Debug.findScriptSourcePosition = function(script, opt_line, opt_column) { 556 Debug.findScriptSourcePosition = function(script, opt_line, opt_column) {
546 var location = script.locationFromLine(opt_line, opt_column); 557 // Handle possibly undefined args. ScriptLocationFromLine expects line and
558 // column to include offsets.
559 var line = IS_NULL_OR_UNDEFINED(opt_line) ? script.line_offset : opt_line;
560 var column;
561 if (IS_NULL_OR_UNDEFINED(opt_column)) {
562 column = (line == script.line_offset) ? script.column_offset : 0;
563 } else {
564 column = opt_column;
565 }
566
567 var location = %ScriptLocationFromLine(script, line, column, 0);
547 return location ? location.position : null; 568 return location ? location.position : null;
548 }; 569 };
549 570
550 571
551 Debug.findBreakPoint = function(break_point_number, remove) { 572 Debug.findBreakPoint = function(break_point_number, remove) {
552 var break_point; 573 var break_point;
553 for (var i = 0; i < break_points.length; i++) { 574 for (var i = 0; i < break_points.length; i++) {
554 if (break_points[i].number() == break_point_number) { 575 if (break_points[i].number() == break_point_number) {
555 break_point = break_points[i]; 576 break_point = break_points[i];
556 // Remove the break point from the list if requested. 577 // Remove the break point from the list if requested.
(...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 frame = this.exec_state_.frame(frame_number); 2099 frame = this.exec_state_.frame(frame_number);
2079 } 2100 }
2080 } 2101 }
2081 2102
2082 // Get the script selected. 2103 // Get the script selected.
2083 var script = frame.func().script(); 2104 var script = frame.func().script();
2084 if (!script) { 2105 if (!script) {
2085 return response.failed('No source'); 2106 return response.failed('No source');
2086 } 2107 }
2087 2108
2088 // Get the source slice and fill it into the response. 2109 var raw_script = script.value();
2089 var slice = script.sourceSlice(from_line, to_line); 2110
2090 if (!slice) { 2111 // Sanitize arguments and remove line offset.
2112 var line_offset = raw_script.line_offset;
2113 var line_count = %ScriptLineCount(raw_script);
2114 from_line = IS_UNDEFINED(from_line) ? 0 : from_line - line_offset;
2115 to_line = IS_UNDEFINED(to_line) ? line_count : to_line - line_offset;
2116
2117 if (from_line < 0) from_line = 0;
2118 if (to_line > line_count) to_line = line_count;
2119
2120 if (from_line >= line_count || to_line < 0 || from_line > to_line) {
2091 return response.failed('Invalid line interval'); 2121 return response.failed('Invalid line interval');
2092 } 2122 }
2123
2124 // Fill in the response.
2125
2093 response.body = {}; 2126 response.body = {};
2094 response.body.source = slice.sourceText(); 2127 response.body.fromLine = from_line + line_offset;
2095 response.body.fromLine = slice.from_line; 2128 response.body.toLine = to_line + line_offset;
2096 response.body.toLine = slice.to_line; 2129 response.body.fromPosition = %ScriptLineStartPosition(raw_script, from_line);
2097 response.body.fromPosition = slice.from_position; 2130 response.body.toPosition =
2098 response.body.toPosition = slice.to_position; 2131 (to_line == 0) ? 0 : %ScriptLineEndPosition(raw_script, to_line - 1);
2099 response.body.totalLines = script.lineCount(); 2132 response.body.totalLines = %ScriptLineCount(raw_script);
2133
2134 response.body.source = %_SubString(raw_script.source,
2135 response.body.fromPosition,
2136 response.body.toPosition);
2100 }; 2137 };
2101 2138
2102 2139
2103 DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) { 2140 DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) {
2104 var types = ScriptTypeFlag(Debug.ScriptType.Normal); 2141 var types = ScriptTypeFlag(Debug.ScriptType.Normal);
2105 var includeSource = false; 2142 var includeSource = false;
2106 var idsToInclude = null; 2143 var idsToInclude = null;
2107 if (request.arguments) { 2144 if (request.arguments) {
2108 // Pull out arguments. 2145 // Pull out arguments.
2109 if (!IS_UNDEFINED(request.arguments.types)) { 2146 if (!IS_UNDEFINED(request.arguments.types)) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2460 "IsBreakPointTriggered", IsBreakPointTriggered, 2497 "IsBreakPointTriggered", IsBreakPointTriggered,
2461 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, 2498 "UpdateScriptBreakPoints", UpdateScriptBreakPoints,
2462 ]); 2499 ]);
2463 2500
2464 // Export to liveedit.js 2501 // Export to liveedit.js
2465 utils.Export(function(to) { 2502 utils.Export(function(to) {
2466 to.GetScriptBreakPoints = GetScriptBreakPoints; 2503 to.GetScriptBreakPoints = GetScriptBreakPoints;
2467 }); 2504 });
2468 2505
2469 }) 2506 })
OLDNEW
« no previous file with comments | « no previous file | src/debug/mirrors.js » ('j') | src/runtime/runtime-debug.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698