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

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: Address comments Created 4 years, 6 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') | no next file with comments »
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 return %ScriptLocationFromLine(script, opt_line, opt_column, script_offset);
540 }; 540 };
541 541
542 542
543 // Returns the character position in a script based on a line number and an 543 // Returns the character position in a script based on a line number and an
544 // optional position within that line. 544 // optional position within that line.
545 Debug.findScriptSourcePosition = function(script, opt_line, opt_column) { 545 Debug.findScriptSourcePosition = function(script, opt_line, opt_column) {
546 var location = script.locationFromLine(opt_line, opt_column); 546 var location = %ScriptLocationFromLine(script, opt_line, opt_column, 0);
547 return location ? location.position : null; 547 return location ? location.position : null;
548 }; 548 };
549 549
550 550
551 Debug.findBreakPoint = function(break_point_number, remove) { 551 Debug.findBreakPoint = function(break_point_number, remove) {
552 var break_point; 552 var break_point;
553 for (var i = 0; i < break_points.length; i++) { 553 for (var i = 0; i < break_points.length; i++) {
554 if (break_points[i].number() == break_point_number) { 554 if (break_points[i].number() == break_point_number) {
555 break_point = break_points[i]; 555 break_point = break_points[i];
556 // Remove the break point from the list if requested. 556 // 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); 2078 frame = this.exec_state_.frame(frame_number);
2079 } 2079 }
2080 } 2080 }
2081 2081
2082 // Get the script selected. 2082 // Get the script selected.
2083 var script = frame.func().script(); 2083 var script = frame.func().script();
2084 if (!script) { 2084 if (!script) {
2085 return response.failed('No source'); 2085 return response.failed('No source');
2086 } 2086 }
2087 2087
2088 // Get the source slice and fill it into the response. 2088 var raw_script = script.value();
2089 var slice = script.sourceSlice(from_line, to_line); 2089
2090 if (!slice) { 2090 // Sanitize arguments and remove line offset.
2091 var line_offset = raw_script.line_offset;
2092 var line_count = %ScriptLineCount(raw_script);
2093 from_line = IS_UNDEFINED(from_line) ? 0 : from_line - line_offset;
2094 to_line = IS_UNDEFINED(to_line) ? line_count : to_line - line_offset;
2095
2096 if (from_line < 0) from_line = 0;
2097 if (to_line > line_count) to_line = line_count;
2098
2099 if (from_line >= line_count || to_line < 0 || from_line > to_line) {
2091 return response.failed('Invalid line interval'); 2100 return response.failed('Invalid line interval');
2092 } 2101 }
2102
2103 // Fill in the response.
2104
2093 response.body = {}; 2105 response.body = {};
2094 response.body.source = slice.sourceText(); 2106 response.body.fromLine = from_line + line_offset;
2095 response.body.fromLine = slice.from_line; 2107 response.body.toLine = to_line + line_offset;
2096 response.body.toLine = slice.to_line; 2108 response.body.fromPosition = %ScriptLineStartPosition(raw_script, from_line);
2097 response.body.fromPosition = slice.from_position; 2109 response.body.toPosition =
2098 response.body.toPosition = slice.to_position; 2110 (to_line == 0) ? 0 : %ScriptLineEndPosition(raw_script, to_line - 1);
2099 response.body.totalLines = script.lineCount(); 2111 response.body.totalLines = %ScriptLineCount(raw_script);
2112
2113 response.body.source = %_SubString(raw_script.source,
2114 response.body.fromPosition,
2115 response.body.toPosition);
2100 }; 2116 };
2101 2117
2102 2118
2103 DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) { 2119 DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) {
2104 var types = ScriptTypeFlag(Debug.ScriptType.Normal); 2120 var types = ScriptTypeFlag(Debug.ScriptType.Normal);
2105 var includeSource = false; 2121 var includeSource = false;
2106 var idsToInclude = null; 2122 var idsToInclude = null;
2107 if (request.arguments) { 2123 if (request.arguments) {
2108 // Pull out arguments. 2124 // Pull out arguments.
2109 if (!IS_UNDEFINED(request.arguments.types)) { 2125 if (!IS_UNDEFINED(request.arguments.types)) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2460 "IsBreakPointTriggered", IsBreakPointTriggered, 2476 "IsBreakPointTriggered", IsBreakPointTriggered,
2461 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, 2477 "UpdateScriptBreakPoints", UpdateScriptBreakPoints,
2462 ]); 2478 ]);
2463 2479
2464 // Export to liveedit.js 2480 // Export to liveedit.js
2465 utils.Export(function(to) { 2481 utils.Export(function(to) {
2466 to.GetScriptBreakPoints = GetScriptBreakPoints; 2482 to.GetScriptBreakPoints = GetScriptBreakPoints;
2467 }); 2483 });
2468 2484
2469 }) 2485 })
OLDNEW
« no previous file with comments | « no previous file | src/debug/mirrors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698