| OLD | NEW |
| 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 465 |
| 466 | 466 |
| 467 Debug.setListener = function(listener, opt_data) { | 467 Debug.setListener = function(listener, opt_data) { |
| 468 if (!IS_FUNCTION(listener) && !IS_UNDEFINED(listener) && !IS_NULL(listener)) { | 468 if (!IS_FUNCTION(listener) && !IS_UNDEFINED(listener) && !IS_NULL(listener)) { |
| 469 throw MakeTypeError(kDebuggerType); | 469 throw MakeTypeError(kDebuggerType); |
| 470 } | 470 } |
| 471 %SetDebugEventListener(listener, opt_data); | 471 %SetDebugEventListener(listener, opt_data); |
| 472 }; | 472 }; |
| 473 | 473 |
| 474 | 474 |
| 475 Debug.breakLocations = function(f, opt_position_aligment) { | |
| 476 if (!IS_FUNCTION(f)) throw MakeTypeError(kDebuggerType); | |
| 477 var position_aligment = IS_UNDEFINED(opt_position_aligment) | |
| 478 ? Debug.BreakPositionAlignment.Statement : opt_position_aligment; | |
| 479 return %GetBreakLocations(f, position_aligment); | |
| 480 }; | |
| 481 | |
| 482 // Returns a Script object. If the parameter is a function the return value | 475 // Returns a Script object. If the parameter is a function the return value |
| 483 // is the script in which the function is defined. If the parameter is a string | 476 // is the script in which the function is defined. If the parameter is a string |
| 484 // the return value is the script for which the script name has that string | 477 // the return value is the script for which the script name has that string |
| 485 // value. If it is a regexp and there is a unique script whose name matches | 478 // value. If it is a regexp and there is a unique script whose name matches |
| 486 // we return that, otherwise undefined. | 479 // we return that, otherwise undefined. |
| 487 Debug.findScript = function(func_or_script_name) { | 480 Debug.findScript = function(func_or_script_name) { |
| 488 if (IS_FUNCTION(func_or_script_name)) { | 481 if (IS_FUNCTION(func_or_script_name)) { |
| 489 return %FunctionGetScript(func_or_script_name); | 482 return %FunctionGetScript(func_or_script_name); |
| 490 } else if (IS_REGEXP(func_or_script_name)) { | 483 } else if (IS_REGEXP(func_or_script_name)) { |
| 491 var scripts = this.scripts(); | 484 var scripts = this.scripts(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 } | 574 } |
| 582 return []; | 575 return []; |
| 583 }; | 576 }; |
| 584 | 577 |
| 585 Debug.setBreakPoint = function(func, opt_line, opt_column, opt_condition) { | 578 Debug.setBreakPoint = function(func, opt_line, opt_column, opt_condition) { |
| 586 if (!IS_FUNCTION(func)) throw MakeTypeError(kDebuggerType); | 579 if (!IS_FUNCTION(func)) throw MakeTypeError(kDebuggerType); |
| 587 // Break points in API functions are not supported. | 580 // Break points in API functions are not supported. |
| 588 if (%FunctionIsAPIFunction(func)) { | 581 if (%FunctionIsAPIFunction(func)) { |
| 589 throw MakeError(kDebugger, 'Cannot set break point in native code.'); | 582 throw MakeError(kDebugger, 'Cannot set break point in native code.'); |
| 590 } | 583 } |
| 591 // Find source position relative to start of the function | 584 // Find source position. |
| 592 var break_position = | 585 var source_position = |
| 593 this.findFunctionSourceLocation(func, opt_line, opt_column).position; | 586 this.findFunctionSourceLocation(func, opt_line, opt_column).position; |
| 594 var source_position = break_position - this.sourcePosition(func); | |
| 595 // Find the script for the function. | 587 // Find the script for the function. |
| 596 var script = %FunctionGetScript(func); | 588 var script = %FunctionGetScript(func); |
| 597 // Break in builtin JavaScript code is not supported. | 589 // Break in builtin JavaScript code is not supported. |
| 598 if (script.type == Debug.ScriptType.Native) { | 590 if (script.type == Debug.ScriptType.Native) { |
| 599 throw MakeError(kDebugger, 'Cannot set break point in native code.'); | 591 throw MakeError(kDebugger, 'Cannot set break point in native code.'); |
| 600 } | 592 } |
| 601 // If the script for the function has a name convert this to a script break | 593 // If the script for the function has a name convert this to a script break |
| 602 // point. | 594 // point. |
| 603 if (script && script.id) { | 595 if (script && script.id) { |
| 604 // Adjust the source position to be script relative. | |
| 605 source_position += %FunctionGetScriptSourcePosition(func); | |
| 606 // Find line and column for the position in the script and set a script | 596 // Find line and column for the position in the script and set a script |
| 607 // break point from that. | 597 // break point from that. |
| 608 var location = script.locationFromPosition(source_position, false); | 598 var location = script.locationFromPosition(source_position, false); |
| 609 return this.setScriptBreakPointById(script.id, | 599 return this.setScriptBreakPointById(script.id, |
| 610 location.line, location.column, | 600 location.line, location.column, |
| 611 opt_condition); | 601 opt_condition); |
| 612 } else { | 602 } else { |
| 613 // Set a break point directly on the function. | 603 // Set a break point directly on the function. |
| 614 var break_point = MakeBreakPoint(source_position); | 604 var break_point = MakeBreakPoint(source_position); |
| 615 var actual_position = | 605 var actual_position = |
| 616 %SetFunctionBreakPoint(func, source_position, break_point); | 606 %SetFunctionBreakPoint(func, source_position, break_point); |
| 617 actual_position += this.sourcePosition(func); | |
| 618 var actual_location = script.locationFromPosition(actual_position, true); | 607 var actual_location = script.locationFromPosition(actual_position, true); |
| 619 break_point.actual_location = { line: actual_location.line, | 608 break_point.actual_location = { line: actual_location.line, |
| 620 column: actual_location.column, | 609 column: actual_location.column, |
| 621 script_id: script.id }; | 610 script_id: script.id }; |
| 622 break_point.setCondition(opt_condition); | 611 break_point.setCondition(opt_condition); |
| 623 return break_point.number(); | 612 return break_point.number(); |
| 624 } | 613 } |
| 625 }; | 614 }; |
| 626 | 615 |
| 627 | 616 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); | 811 return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); |
| 823 }; | 812 }; |
| 824 | 813 |
| 825 Debug.isBreakOnUncaughtException = function() { | 814 Debug.isBreakOnUncaughtException = function() { |
| 826 return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); | 815 return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); |
| 827 }; | 816 }; |
| 828 | 817 |
| 829 Debug.showBreakPoints = function(f, full, opt_position_alignment) { | 818 Debug.showBreakPoints = function(f, full, opt_position_alignment) { |
| 830 if (!IS_FUNCTION(f)) throw MakeError(kDebuggerType); | 819 if (!IS_FUNCTION(f)) throw MakeError(kDebuggerType); |
| 831 var source = full ? this.scriptSource(f) : this.source(f); | 820 var source = full ? this.scriptSource(f) : this.source(f); |
| 832 var offset = full ? this.sourcePosition(f) : 0; | 821 var offset = full ? 0 : this.sourcePosition(f); |
| 833 var locations = this.breakLocations(f, opt_position_alignment); | 822 var position_alignment = IS_UNDEFINED(opt_position_alignment) |
| 823 ? Debug.BreakPositionAlignment.Statement : opt_position_alignment; |
| 824 var locations = %GetBreakLocations(f, position_alignment); |
| 834 if (!locations) return source; | 825 if (!locations) return source; |
| 835 locations.sort(function(x, y) { return x - y; }); | 826 locations.sort(function(x, y) { return x - y; }); |
| 836 var result = ""; | 827 var result = ""; |
| 837 var prev_pos = 0; | 828 var prev_pos = 0; |
| 838 var pos; | 829 var pos; |
| 839 for (var i = 0; i < locations.length; i++) { | 830 for (var i = 0; i < locations.length; i++) { |
| 840 pos = locations[i] - offset; | 831 pos = locations[i] - offset; |
| 841 result += source.slice(prev_pos, pos); | 832 result += source.slice(prev_pos, pos); |
| 842 result += "[B" + i + "]"; | 833 result += "[B" + i + "]"; |
| 843 prev_pos = pos; | 834 prev_pos = pos; |
| (...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2488 "IsBreakPointTriggered", IsBreakPointTriggered, | 2479 "IsBreakPointTriggered", IsBreakPointTriggered, |
| 2489 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, | 2480 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, |
| 2490 ]); | 2481 ]); |
| 2491 | 2482 |
| 2492 // Export to liveedit.js | 2483 // Export to liveedit.js |
| 2493 utils.Export(function(to) { | 2484 utils.Export(function(to) { |
| 2494 to.GetScriptBreakPoints = GetScriptBreakPoints; | 2485 to.GetScriptBreakPoints = GetScriptBreakPoints; |
| 2495 }); | 2486 }); |
| 2496 | 2487 |
| 2497 }) | 2488 }) |
| OLD | NEW |