debug-debugger.js revision b8e0da25ee8efac3bb05cd6b2730aafbd96119f4
13100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Copyright 2006-2008 the V8 project authors. All rights reserved. 23100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Redistribution and use in source and binary forms, with or without 33100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// modification, are permitted provided that the following conditions are 43100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// met: 53100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// 63100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// * Redistributions of source code must retain the above copyright 73100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// notice, this list of conditions and the following disclaimer. 83100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// * Redistributions in binary form must reproduce the above 93100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// copyright notice, this list of conditions and the following 103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// disclaimer in the documentation and/or other materials provided 113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// with the distribution. 123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// * Neither the name of Google Inc. nor the names of its 133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// contributors may be used to endorse or promote products derived 143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// from this software without specific prior written permission. 153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// 163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Default number of frames to include in the response to backtrace request. 293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuconst kDefaultBacktraceLength = 10; 303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuconst Debug = {}; 323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Regular expression to skip "crud" at the beginning of a source line which is 343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// not really code. Currently the regular expression matches whitespace and 353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// comments. 363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuconst sourceLineBeginningSkip = /^(?:\s*(?:\/\*.*?\*\/)*)*/; 373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Debug events which can occour in the V8 JavaScript engine. These originate 393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// from the API include file debug.h. 403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.DebugEvent = { Break: 1, 413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Exception: 2, 423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu NewFunction: 3, 433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu BeforeCompile: 4, 443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu AfterCompile: 5, 453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu ScriptCollected: 6 }; 463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Types of exceptions that can be broken upon. 480d5e116f6aee03185f237311a943491bb079a768Kristian MonsenDebug.ExceptionBreak = { Caught : 0, 493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Uncaught: 1 }; 503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// The different types of steps. 523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.StepAction = { StepOut: 0, 533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu StepNext: 1, 543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu StepIn: 2, 553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu StepMin: 3, 563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu StepInMin: 4 }; 573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// The different types of scripts matching enum ScriptType in objects.h. 593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.ScriptType = { Native: 0, 603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Extension: 1, 613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Normal: 2 }; 623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// The different types of script compilations matching enum 643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Script::CompilationType in objects.h. 653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.ScriptCompilationType = { Host: 0, 663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Eval: 1, 673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu JSON: 2 }; 683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// The different script break point types. 703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.ScriptBreakPointType = { ScriptId: 0, 713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu ScriptName: 1 }; 723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ScriptTypeFlag(type) { 743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return (1 << type); 753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Globals. 783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvar next_response_seq = 0; 793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvar next_break_point_number = 1; 803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvar break_points = []; 813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvar script_break_points = []; 82bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdochvar debugger_flags = { 83bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch breakPointsActive: { 84bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch value: true, 85bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch getValue: function() { return this.value; }, 86bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch setValue: function(value) { 87bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch this.value = !!value; 88bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch %SetDisableBreak(!this.value); 89bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 900d5e116f6aee03185f237311a943491bb079a768Kristian Monsen }, 910d5e116f6aee03185f237311a943491bb079a768Kristian Monsen breakOnCaughtException: { 920d5e116f6aee03185f237311a943491bb079a768Kristian Monsen getValue: function() { return Debug.isBreakOnException(); }, 930d5e116f6aee03185f237311a943491bb079a768Kristian Monsen setValue: function(value) { 940d5e116f6aee03185f237311a943491bb079a768Kristian Monsen if (value) { 950d5e116f6aee03185f237311a943491bb079a768Kristian Monsen Debug.setBreakOnException(); 960d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } else { 970d5e116f6aee03185f237311a943491bb079a768Kristian Monsen Debug.clearBreakOnException(); 980d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } 990d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } 1000d5e116f6aee03185f237311a943491bb079a768Kristian Monsen }, 1010d5e116f6aee03185f237311a943491bb079a768Kristian Monsen breakOnUncaughtException: { 1020d5e116f6aee03185f237311a943491bb079a768Kristian Monsen getValue: function() { return Debug.isBreakOnUncaughtException(); }, 1030d5e116f6aee03185f237311a943491bb079a768Kristian Monsen setValue: function(value) { 1040d5e116f6aee03185f237311a943491bb079a768Kristian Monsen if (value) { 1050d5e116f6aee03185f237311a943491bb079a768Kristian Monsen Debug.setBreakOnUncaughtException(); 1060d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } else { 1070d5e116f6aee03185f237311a943491bb079a768Kristian Monsen Debug.clearBreakOnUncaughtException(); 1080d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } 1090d5e116f6aee03185f237311a943491bb079a768Kristian Monsen } 1100d5e116f6aee03185f237311a943491bb079a768Kristian Monsen }, 111bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch}; 1123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Create a new break point object and add it to the list of break points. 115b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochfunction MakeBreakPoint(source_position, opt_script_break_point) { 116b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch var break_point = new BreakPoint(source_position, opt_script_break_point); 1173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_points.push(break_point); 1183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return break_point; 1193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 1203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Object representing a break point. 1233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// NOTE: This object does not have a reference to the function having break 1243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// point as this would cause function not to be garbage collected when it is 1253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// not used any more. We do not want break points to keep functions alive. 126b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochfunction BreakPoint(source_position, opt_script_break_point) { 1273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.source_position_ = source_position; 1283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (opt_script_break_point) { 1293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.script_break_point_ = opt_script_break_point; 1303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 1313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.number_ = next_break_point_number++; 1323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 1333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.hit_count_ = 0; 1343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = true; 1353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.condition_ = null; 1363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.ignoreCount_ = 0; 1373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 1383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.number = function() { 1413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.number_; 1423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.func = function() { 1463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.func_; 1473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.source_position = function() { 1513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.source_position_; 1523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.hit_count = function() { 1563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.hit_count_; 1573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.active = function() { 1613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.script_break_point()) { 1623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_break_point().active(); 1633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 1643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.active_; 1653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.condition = function() { 1693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.script_break_point() && this.script_break_point().condition()) { 1703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_break_point().condition(); 1713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 1723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.condition_; 1733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.ignoreCount = function() { 1773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.ignoreCount_; 1783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.script_break_point = function() { 1823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_break_point_; 1833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.enable = function() { 1873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = true; 1883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.disable = function() { 1923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = false; 1933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.setCondition = function(condition) { 1973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.condition_ = condition; 1983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 1993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.setIgnoreCount = function(ignoreCount) { 2023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.ignoreCount_ = ignoreCount; 2033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 2043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakPoint.prototype.isTriggered = function(exec_state) { 2073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Break point not active - not triggered. 2083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!this.active()) return false; 2093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for conditional break point. 2113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.condition()) { 2123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If break point has condition try to evaluate it in the top frame. 2133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 2143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var mirror = exec_state.frame(0).evaluate(this.condition()); 2153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If no sensible mirror or non true value break point not triggered. 2163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!(mirror instanceof ValueMirror) || !%ToBoolean(mirror.value_)) { 2173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return false; 2183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch (e) { 2203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Exception evaluating condition counts as not triggered. 2213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return false; 2223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Update the hit count. 2263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.hit_count_++; 2273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.script_break_point_) { 2283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.script_break_point_.hit_count_++; 2293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If the break point has an ignore count it is not triggered. 2323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.ignoreCount_ > 0) { 2333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.ignoreCount_--; 2343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return false; 2353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Break point triggered. 2383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return true; 2393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 2403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Function called from the runtime when a break point is hit. Returns true if 2433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// the break point is triggered and supposed to break execution. 2443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction IsBreakPointTriggered(break_id, break_point) { 2453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return break_point.isTriggered(MakeExecutionState(break_id)); 2463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 2473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Object representing a script break point. The script is referenced by its 2503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// script name or script id and the break point is represented as line and 2513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// column. 2523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, 2533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_groupId) { 2543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.type_ = type; 2553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (type == Debug.ScriptBreakPointType.ScriptId) { 2563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.script_id_ = script_id_or_name; 2573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { // type == Debug.ScriptBreakPointType.ScriptName 2583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.script_name_ = script_id_or_name; 2593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.line_ = opt_line || 0; 2613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.column_ = opt_column; 2623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.groupId_ = opt_groupId; 2633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.hit_count_ = 0; 2643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = true; 2653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.condition_ = null; 2663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.ignoreCount_ = 0; 2678defd9ff6930b4e24729971a61cf7469daf119beSteve Block this.break_points_ = []; 2683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 2693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2716ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//Creates a clone of script breakpoint that is linked to another script. 2726ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockScriptBreakPoint.prototype.cloneForOtherScript = function (other_script) { 2736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var copy = new ScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, 2746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block other_script.id, this.line_, this.column_, this.groupId_); 2756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block copy.number_ = next_break_point_number++; 2766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block script_break_points.push(copy); 277bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 2786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block copy.hit_count_ = this.hit_count_; 2796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block copy.active_ = this.active_; 2806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block copy.condition_ = this.condition_; 2816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block copy.ignoreCount_ = this.ignoreCount_; 2826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return copy; 2836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block} 2846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 2856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 2863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.number = function() { 2873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.number_; 2883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 2893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.groupId = function() { 2923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.groupId_; 2933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 2943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 2963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.type = function() { 2973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.type_; 2983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 2993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.script_id = function() { 3023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_id_; 3033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.script_name = function() { 3073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_name_; 3083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.line = function() { 3123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.line_; 3133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.column = function() { 3173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.column_; 3183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3218defd9ff6930b4e24729971a61cf7469daf119beSteve BlockScriptBreakPoint.prototype.actual_locations = function() { 3228defd9ff6930b4e24729971a61cf7469daf119beSteve Block var locations = []; 3238defd9ff6930b4e24729971a61cf7469daf119beSteve Block for (var i = 0; i < this.break_points_.length; i++) { 3248defd9ff6930b4e24729971a61cf7469daf119beSteve Block locations.push(this.break_points_[i].actual_location); 3258defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 3268defd9ff6930b4e24729971a61cf7469daf119beSteve Block return locations; 3278defd9ff6930b4e24729971a61cf7469daf119beSteve Block} 3288defd9ff6930b4e24729971a61cf7469daf119beSteve Block 3298defd9ff6930b4e24729971a61cf7469daf119beSteve Block 3306ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockScriptBreakPoint.prototype.update_positions = function(line, column) { 3316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block this.line_ = line; 3326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block this.column_ = column; 3336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block} 3346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 3356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 3363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.hit_count = function() { 3373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.hit_count_; 3383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.active = function() { 3423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.active_; 3433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.condition = function() { 3473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.condition_; 3483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.ignoreCount = function() { 3523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.ignoreCount_; 3533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.enable = function() { 3573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = true; 3583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.disable = function() { 3623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.active_ = false; 3633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.setCondition = function(condition) { 3673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.condition_ = condition; 3683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.setIgnoreCount = function(ignoreCount) { 3723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.ignoreCount_ = ignoreCount; 3733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set ignore count on all break points created from this script break point. 3758defd9ff6930b4e24729971a61cf7469daf119beSteve Block for (var i = 0; i < this.break_points_.length; i++) { 3768defd9ff6930b4e24729971a61cf7469daf119beSteve Block this.break_points_[i].setIgnoreCount(ignoreCount); 3773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 3783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Check whether a script matches this script break point. Currently this is 3823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// only based on script name. 3833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.matchesScript = function(script) { 3843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { 3853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_id_ == script.id; 3863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { // this.type_ == Debug.ScriptBreakPointType.ScriptName 3876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return this.script_name_ == script.nameOrSourceURL() && 3883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script.line_offset <= this.line_ && 3893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.line_ < script.line_offset + script.lineCount(); 3903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 3913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 3923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 3943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Set the script break point in a script. 3953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.set = function (script) { 3963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var column = this.column(); 3973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var line = this.line(); 3983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If the column is undefined the break is on the line. To help locate the 3993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // first piece of breakable code on the line try to find the column on the 4003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // line which contains some source. 4013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(column)) { 4023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var source_line = script.sourceLine(this.line()); 4033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Allocate array for caching the columns where the actual source starts. 4053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!script.sourceColumnStart_) { 4063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script.sourceColumnStart_ = new Array(script.lineCount()); 4073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Fill cache if needed and get column where the actual source starts. 4103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(script.sourceColumnStart_[line])) { 4113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script.sourceColumnStart_[line] = 4123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu source_line.match(sourceLineBeginningSkip)[0].length; 4133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu column = script.sourceColumnStart_[line]; 4153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Convert the line and column into an absolute position within the script. 4188defd9ff6930b4e24729971a61cf7469daf119beSteve Block var position = Debug.findScriptSourcePosition(script, this.line(), column); 4193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If the position is not found in the script (the script might be shorter 4213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // than it used to be) just ignore it. 4228defd9ff6930b4e24729971a61cf7469daf119beSteve Block if (position === null) return; 4233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create a break point object and set the break point. 425b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point = MakeBreakPoint(position, this); 4263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point.setIgnoreCount(this.ignoreCount()); 4278defd9ff6930b4e24729971a61cf7469daf119beSteve Block var actual_position = %SetScriptBreakPoint(script, position, break_point); 4288defd9ff6930b4e24729971a61cf7469daf119beSteve Block if (IS_UNDEFINED(actual_position)) { 4298defd9ff6930b4e24729971a61cf7469daf119beSteve Block actual_position = position; 4308defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 4318defd9ff6930b4e24729971a61cf7469daf119beSteve Block var actual_location = script.locationFromPosition(actual_position, true); 4328defd9ff6930b4e24729971a61cf7469daf119beSteve Block break_point.actual_location = { line: actual_location.line, 4338defd9ff6930b4e24729971a61cf7469daf119beSteve Block column: actual_location.column }; 4348defd9ff6930b4e24729971a61cf7469daf119beSteve Block this.break_points_.push(break_point); 4353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return break_point; 4363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 4373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Clear all the break points created from this script break point 4403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptBreakPoint.prototype.clear = function () { 4413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var remaining_break_points = []; 4423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < break_points.length; i++) { 4433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_points[i].script_break_point() && 4443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_points[i].script_break_point() === this) { 4453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu %ClearBreakPoint(break_points[i]); 4463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 4473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu remaining_break_points.push(break_points[i]); 4483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_points = remaining_break_points; 4518defd9ff6930b4e24729971a61cf7469daf119beSteve Block this.break_points_ = []; 4523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 4533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Function called from runtime when a new script is compiled to set any script 4563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// break points set in this script. 4573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction UpdateScriptBreakPoints(script) { 4583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < script_break_points.length; i++) { 4593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script_break_points[i].type() == Debug.ScriptBreakPointType.ScriptName && 4603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_points[i].matchesScript(script)) { 4613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_points[i].set(script); 4623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 4653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4676ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockfunction GetScriptBreakPoints(script) { 4686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var result = []; 4696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block for (var i = 0; i < script_break_points.length; i++) { 4706ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (script_break_points[i].matchesScript(script)) { 4716ded16be15dd865a9b21ea304d5273c8be299c87Steve Block result.push(script_break_points[i]); 4726ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 4736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 4746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return result; 4756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block} 4766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 4776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 4783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setListener = function(listener, opt_data) { 4793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(listener) && !IS_UNDEFINED(listener) && !IS_NULL(listener)) { 4803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Parameters have wrong types.'); 4813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 4823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu %SetDebugEventListener(listener, opt_data); 4833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 4843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.breakExecution = function(f) { 4873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu %Break(); 4883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 4893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.breakLocations = function(f) { 4913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 4923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %GetBreakLocations(f); 4933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 4943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 4953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Returns a Script object. If the parameter is a function the return value 4963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// is the script in which the function is defined. If the parameter is a string 4973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// the return value is the script for which the script name has that string 4983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// value. If it is a regexp and there is a unique script whose name matches 4993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// we return that, otherwise undefined. 5003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.findScript = function(func_or_script_name) { 5013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_FUNCTION(func_or_script_name)) { 5023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %FunctionGetScript(func_or_script_name); 5033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (IS_REGEXP(func_or_script_name)) { 5043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var scripts = Debug.scripts(); 5053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var last_result = null; 5063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var result_count = 0; 5073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i in scripts) { 5083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = scripts[i]; 5093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (func_or_script_name.test(script.name)) { 5103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu last_result = script; 5113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu result_count++; 5123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Return the unique script matching the regexp. If there are more 5153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // than one we don't return a value since there is no good way to 5163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // decide which one to return. Returning a "random" one, say the 5173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // first, would introduce nondeterminism (or something close to it) 5183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // because the order is the heap iteration order. 5193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (result_count == 1) { 5203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return last_result; 5213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 5223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return undefined; 5233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 5253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %GetScript(func_or_script_name); 5263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Returns the script source. If the parameter is a function the return value 5303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// is the script source for the script in which the function is defined. If the 5313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// parameter is a string the return value is the script for which the script 5323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// name has that string value. 5333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.scriptSource = function(func_or_script_name) { 5343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.findScript(func_or_script_name).source; 5353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.source = function(f) { 5383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 5393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %FunctionGetSourceCode(f); 5403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.disassemble = function(f) { 5433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 5443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %DebugDisassembleFunction(f); 5453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.disassembleConstructor = function(f) { 5483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 5493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %DebugDisassembleConstructor(f); 5503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5526ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockDebug.ExecuteInDebugContext = function(f, without_debugger) { 5536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 5546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return %ExecuteInDebugContext(f, !!without_debugger); 5556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block}; 5566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 5573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.sourcePosition = function(f) { 5583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 5593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %FunctionGetScriptSourcePosition(f); 5603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.findFunctionSourceLocation = function(func, opt_line, opt_column) { 5643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = %FunctionGetScript(func); 5653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_offset = %FunctionGetScriptSourcePosition(func); 5663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return script.locationFromLine(opt_line, opt_column, script_offset); 5673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 5683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Returns the character position in a script based on a line number and an 5713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// optional position within that line. 5723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.findScriptSourcePosition = function(script, opt_line, opt_column) { 5733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var location = script.locationFromLine(opt_line, opt_column); 5743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return location ? location.position : null; 5753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 5763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.findBreakPoint = function(break_point_number, remove) { 5793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point; 5803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < break_points.length; i++) { 5813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_points[i].number() == break_point_number) { 5823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point = break_points[i]; 5833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Remove the break point from the list if requested. 5843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (remove) { 5853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_points.splice(i, 1); 5863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break; 5883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_point) { 5913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return break_point; 5923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 5933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.findScriptBreakPoint(break_point_number, remove); 5943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 5953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 5963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 5978defd9ff6930b4e24729971a61cf7469daf119beSteve BlockDebug.findBreakPointActualLocations = function(break_point_number) { 5988defd9ff6930b4e24729971a61cf7469daf119beSteve Block for (var i = 0; i < script_break_points.length; i++) { 5998defd9ff6930b4e24729971a61cf7469daf119beSteve Block if (script_break_points[i].number() == break_point_number) { 6008defd9ff6930b4e24729971a61cf7469daf119beSteve Block return script_break_points[i].actual_locations(); 6018defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 6028defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 6038defd9ff6930b4e24729971a61cf7469daf119beSteve Block for (var i = 0; i < break_points.length; i++) { 6048defd9ff6930b4e24729971a61cf7469daf119beSteve Block if (break_points[i].number() == break_point_number) { 6058defd9ff6930b4e24729971a61cf7469daf119beSteve Block return [break_points[i].actual_location]; 6068defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 6078defd9ff6930b4e24729971a61cf7469daf119beSteve Block } 6088defd9ff6930b4e24729971a61cf7469daf119beSteve Block return []; 6098defd9ff6930b4e24729971a61cf7469daf119beSteve Block} 6103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setBreakPoint = function(func, opt_line, opt_column, opt_condition) { 6123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(func)) throw new Error('Parameters have wrong types.'); 6133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Break points in API functions are not supported. 6143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (%FunctionIsAPIFunction(func)) { 6153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Cannot set break point in native code.'); 6163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 6173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find source position relative to start of the function 6183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_position = 6193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.findFunctionSourceLocation(func, opt_line, opt_column).position; 6203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var source_position = break_position - this.sourcePosition(func); 6213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find the script for the function. 6223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = %FunctionGetScript(func); 6233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Break in builtin JavaScript code is not supported. 6243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script.type == Debug.ScriptType.Native) { 6253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Cannot set break point in native code.'); 6263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 6273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If the script for the function has a name convert this to a script break 6283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // point. 6293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script && script.id) { 6303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Adjust the source position to be script relative. 6313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu source_position += %FunctionGetScriptSourcePosition(func); 6323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find line and column for the position in the script and set a script 6333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // break point from that. 6343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var location = script.locationFromPosition(source_position, false); 6353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.setScriptBreakPointById(script.id, 6363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu location.line, location.column, 6373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_condition); 6383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 6393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set a break point directly on the function. 640b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch var break_point = MakeBreakPoint(source_position); 6418defd9ff6930b4e24729971a61cf7469daf119beSteve Block var actual_position = 6428defd9ff6930b4e24729971a61cf7469daf119beSteve Block %SetFunctionBreakPoint(func, source_position, break_point); 6438defd9ff6930b4e24729971a61cf7469daf119beSteve Block actual_position += this.sourcePosition(func); 6448defd9ff6930b4e24729971a61cf7469daf119beSteve Block var actual_location = script.locationFromPosition(actual_position, true); 6458defd9ff6930b4e24729971a61cf7469daf119beSteve Block break_point.actual_location = { line: actual_location.line, 6468defd9ff6930b4e24729971a61cf7469daf119beSteve Block column: actual_location.column }; 6473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point.setCondition(opt_condition); 6483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return break_point.number(); 6493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 6503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 6513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 653b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben MurdochDebug.setBreakPointByScriptIdAndPosition = function(script_id, position, 654b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch condition, enabled) 655b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch{ 656b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point = MakeBreakPoint(position); 657b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point.setCondition(condition); 658b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch if (!enabled) 659b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point.disable(); 660b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch var scripts = this.scripts(); 661b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch for (var i = 0; i < scripts.length; i++) { 662b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch if (script_id == scripts[i].id) { 663b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point.actual_position = %SetScriptBreakPoint(scripts[i], position, 664b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break_point); 665b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch break; 666b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch } 667b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch } 668b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch return break_point; 669b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch}; 670b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch 671b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch 6723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.enableBreakPoint = function(break_point_number) { 6733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = this.findBreakPoint(break_point_number, false); 674086aeeaae12517475c22695a200be45495516549Ben Murdoch // Only enable if the breakpoint hasn't been deleted: 675086aeeaae12517475c22695a200be45495516549Ben Murdoch if (break_point) { 676086aeeaae12517475c22695a200be45495516549Ben Murdoch break_point.enable(); 677086aeeaae12517475c22695a200be45495516549Ben Murdoch } 6783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 6793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.disableBreakPoint = function(break_point_number) { 6823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = this.findBreakPoint(break_point_number, false); 683086aeeaae12517475c22695a200be45495516549Ben Murdoch // Only enable if the breakpoint hasn't been deleted: 684086aeeaae12517475c22695a200be45495516549Ben Murdoch if (break_point) { 685086aeeaae12517475c22695a200be45495516549Ben Murdoch break_point.disable(); 686086aeeaae12517475c22695a200be45495516549Ben Murdoch } 6873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 6883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.changeBreakPointCondition = function(break_point_number, condition) { 6913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = this.findBreakPoint(break_point_number, false); 6923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point.setCondition(condition); 6933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 6943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 6963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.changeBreakPointIgnoreCount = function(break_point_number, ignoreCount) { 6973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (ignoreCount < 0) { 6983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Invalid argument'); 6993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = this.findBreakPoint(break_point_number, false); 7013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point.setIgnoreCount(ignoreCount); 7023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 7033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.clearBreakPoint = function(break_point_number) { 7063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = this.findBreakPoint(break_point_number, true); 7073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_point) { 7083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %ClearBreakPoint(break_point); 7093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 7103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point = this.findScriptBreakPoint(break_point_number, true); 7113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!break_point) { 7123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Invalid breakpoint'); 7133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 7163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.clearAllBreakPoints = function() { 7193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < break_points.length; i++) { 7203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point = break_points[i]; 7213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu %ClearBreakPoint(break_point); 7223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_points = []; 7243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 7253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 727086aeeaae12517475c22695a200be45495516549Ben MurdochDebug.disableAllBreakPoints = function() { 728086aeeaae12517475c22695a200be45495516549Ben Murdoch // Disable all user defined breakpoints: 729086aeeaae12517475c22695a200be45495516549Ben Murdoch for (var i = 1; i < next_break_point_number; i++) { 730086aeeaae12517475c22695a200be45495516549Ben Murdoch Debug.disableBreakPoint(i); 731086aeeaae12517475c22695a200be45495516549Ben Murdoch } 732086aeeaae12517475c22695a200be45495516549Ben Murdoch // Disable all exception breakpoints: 733086aeeaae12517475c22695a200be45495516549Ben Murdoch %ChangeBreakOnException(Debug.ExceptionBreak.Caught, false); 734086aeeaae12517475c22695a200be45495516549Ben Murdoch %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); 735086aeeaae12517475c22695a200be45495516549Ben Murdoch}; 736086aeeaae12517475c22695a200be45495516549Ben Murdoch 737086aeeaae12517475c22695a200be45495516549Ben Murdoch 7383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.findScriptBreakPoint = function(break_point_number, remove) { 7393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point; 7403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < script_break_points.length; i++) { 7413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script_break_points[i].number() == break_point_number) { 7423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point = script_break_points[i]; 7433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Remove the break point from the list if requested. 7443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (remove) { 7453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.clear(); 7463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_points.splice(i,1); 7473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break; 7493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return script_break_point; 7523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 7533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Sets a breakpoint in a script identified through id or name at the 7563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// specified source line and column within that line. 7573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setScriptBreakPoint = function(type, script_id_or_name, 7583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_line, opt_column, opt_condition, 7593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_groupId) { 7603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create script break point object. 7613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = 7623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu new ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column, 7633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_groupId); 7643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Assign number to the new script break point and add it. 7663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.number_ = next_break_point_number++; 7673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.setCondition(opt_condition); 7683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_points.push(script_break_point); 7693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Run through all scripts to see if this script break point matches any 7713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // loaded scripts. 7723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var scripts = this.scripts(); 7733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < scripts.length; i++) { 7743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script_break_point.matchesScript(scripts[i])) { 7753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.set(scripts[i]); 7763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 7783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return script_break_point.number(); 7803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 7813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setScriptBreakPointById = function(script_id, 7843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_line, opt_column, 7853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_condition, opt_groupId) { 7863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, 7873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_id, opt_line, opt_column, 7883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_condition, opt_groupId); 7893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 7903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 7923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setScriptBreakPointByName = function(script_name, 7933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_line, opt_column, 7943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_condition, opt_groupId) { 7953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptName, 7963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_name, opt_line, opt_column, 7973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu opt_condition, opt_groupId); 7983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 7993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.enableScriptBreakPoint = function(break_point_number) { 8023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = this.findScriptBreakPoint(break_point_number, false); 8033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.enable(); 8043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.disableScriptBreakPoint = function(break_point_number) { 8083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = this.findScriptBreakPoint(break_point_number, false); 8093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.disable(); 8103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.changeScriptBreakPointCondition = function(break_point_number, condition) { 8143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = this.findScriptBreakPoint(break_point_number, false); 8153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.setCondition(condition); 8163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.changeScriptBreakPointIgnoreCount = function(break_point_number, ignoreCount) { 8203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (ignoreCount < 0) { 8213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Invalid argument'); 8223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 8233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = this.findScriptBreakPoint(break_point_number, false); 8243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_point.setIgnoreCount(ignoreCount); 8253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.scriptBreakPoints = function() { 8293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return script_break_points; 8303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 8313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.clearStepping = function() { 8343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu %ClearStepping(); 8353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 8363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setBreakOnException = function() { 8380d5e116f6aee03185f237311a943491bb079a768Kristian Monsen return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, true); 8393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.clearBreakOnException = function() { 8420d5e116f6aee03185f237311a943491bb079a768Kristian Monsen return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, false); 8430d5e116f6aee03185f237311a943491bb079a768Kristian Monsen}; 8440d5e116f6aee03185f237311a943491bb079a768Kristian Monsen 8450d5e116f6aee03185f237311a943491bb079a768Kristian MonsenDebug.isBreakOnException = function() { 8460d5e116f6aee03185f237311a943491bb079a768Kristian Monsen return !!%IsBreakOnException(Debug.ExceptionBreak.Caught); 8473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.setBreakOnUncaughtException = function() { 8503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, true); 8513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.clearBreakOnUncaughtException = function() { 8543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); 8553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8570d5e116f6aee03185f237311a943491bb079a768Kristian MonsenDebug.isBreakOnUncaughtException = function() { 8580d5e116f6aee03185f237311a943491bb079a768Kristian Monsen return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); 8590d5e116f6aee03185f237311a943491bb079a768Kristian Monsen}; 8600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen 8613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.showBreakPoints = function(f, full) { 8623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); 8633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var source = full ? this.scriptSource(f) : this.source(f); 8643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var offset = full ? this.sourcePosition(f) : 0; 8653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var locations = this.breakLocations(f); 8663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!locations) return source; 8673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu locations.sort(function(x, y) { return x - y; }); 8683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var result = ""; 8693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var prev_pos = 0; 8703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var pos; 8713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < locations.length; i++) { 8723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu pos = locations[i] - offset; 8733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu result += source.slice(prev_pos, pos); 8743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu result += "[B" + i + "]"; 8753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu prev_pos = pos; 8763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 8773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu pos = source.length; 8783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu result += source.substring(prev_pos, pos); 8793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return result; 8803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 8813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Get all the scripts currently loaded. Locating all the scripts is based on 8843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// scanning the heap. 8853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebug.scripts = function() { 8863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Collect all scripts in the heap. 8873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %DebugGetLoadedScripts(); 888bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch}; 889bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 890bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 891bb769b257e753aafcbd96767abb2abc645eaa20cBen MurdochDebug.debuggerFlags = function() { 892bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch return debugger_flags; 893bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch}; 894bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 895b0fe1620dcb4135ac3ab2d66ff93072373911299Ben MurdochDebug.MakeMirror = MakeMirror; 8963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 8973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeExecutionState(break_id) { 8983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new ExecutionState(break_id); 8993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 9003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ExecutionState(break_id) { 9023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.break_id = break_id; 9033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.selected_frame = 0; 9043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 9053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.prepareStep = function(opt_action, opt_count) { 9073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var action = Debug.StepAction.StepIn; 9083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(opt_action)) action = %ToNumber(opt_action); 9093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var count = opt_count ? %ToNumber(opt_count) : 1; 9103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %PrepareStep(this.break_id, action, count); 9123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 9133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 914b0fe1620dcb4135ac3ab2d66ff93072373911299Ben MurdochExecutionState.prototype.evaluateGlobal = function(source, disable_break, 915b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch opt_additional_context) { 916b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch return MakeMirror(%DebugEvaluateGlobal(this.break_id, source, 917b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch Boolean(disable_break), 918b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch opt_additional_context)); 9193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.frameCount = function() { 9223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %GetFrameCount(this.break_id); 9233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.threadCount = function() { 9263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %GetThreadCount(this.break_id); 9273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.frame = function(opt_index) { 9303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If no index supplied return the selected frame. 9313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (opt_index == null) opt_index = this.selected_frame; 9326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (opt_index < 0 || opt_index >= this.frameCount()) 9336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block throw new Error('Illegal frame index.'); 9343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new FrameMirror(this.break_id, opt_index); 9353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.setSelectedFrame = function(index) { 9383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var i = %ToNumber(index); 9393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (i < 0 || i >= this.frameCount()) throw new Error('Illegal frame index.'); 9403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.selected_frame = i; 9413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.selectedFrame = function() { 9443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.selected_frame; 9453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExecutionState.prototype.debugCommandProcessor = function(opt_is_running) { 9483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new DebugCommandProcessor(this, opt_is_running); 9493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeBreakEvent(exec_state, break_points_hit) { 9533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new BreakEvent(exec_state, break_points_hit); 9543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 9553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction BreakEvent(exec_state, break_points_hit) { 9583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_ = exec_state; 9593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.break_points_hit_ = break_points_hit; 9603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 9613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.executionState = function() { 9643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_; 9653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.eventType = function() { 9693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return Debug.DebugEvent.Break; 9703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.func = function() { 9743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).func(); 9753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.sourceLine = function() { 9793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceLine(); 9803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.sourceColumn = function() { 9843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceColumn(); 9853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.sourceLineText = function() { 9893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceLineText(); 9903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.breakPointsHit = function() { 9943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.break_points_hit_; 9953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 9963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 9983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuBreakEvent.prototype.toJSONProtocol = function() { 9993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var o = { seq: next_response_seq++, 10003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu type: "event", 10013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu event: "break", 10023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu body: { invocationText: this.exec_state_.frame(0).invocationText(), 10033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 10043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu }; 10053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add script related information to the event if available. 10073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = this.func().script(); 10083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script) { 10093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceLine = this.sourceLine(), 10103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceColumn = this.sourceColumn(), 10113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceLineText = this.sourceLineText(), 10123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.script = MakeScriptObject_(script, false); 10133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 10143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add an Array of break points hit if any. 10163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.breakPointsHit()) { 10173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.breakpoints = []; 10183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < this.breakPointsHit().length; i++) { 10193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find the break point number. For break points originating from a 10203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // script break point supply the script break point number. 10213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var breakpoint = this.breakPointsHit()[i]; 10223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script_break_point = breakpoint.script_break_point(); 10233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var number; 10243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script_break_point) { 10253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu number = script_break_point.number(); 10263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 10273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu number = breakpoint.number(); 10283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 10293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.breakpoints.push(number); 10303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 10313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 10323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return JSON.stringify(ObjectToProtocolObject_(o)); 10333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeExceptionEvent(exec_state, exception, uncaught) { 10373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new ExceptionEvent(exec_state, exception, uncaught); 10383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 10393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ExceptionEvent(exec_state, exception, uncaught) { 10423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_ = exec_state; 10433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exception_ = exception; 10443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.uncaught_ = uncaught; 10453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 10463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.executionState = function() { 10493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_; 10503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.eventType = function() { 10543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return Debug.DebugEvent.Exception; 10553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.exception = function() { 10593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exception_; 10603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 10613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.uncaught = function() { 10643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.uncaught_; 10653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 10663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.func = function() { 10693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).func(); 10703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.sourceLine = function() { 10743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceLine(); 10753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.sourceColumn = function() { 10793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceColumn(); 10803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.sourceLineText = function() { 10843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(0).sourceLineText(); 10853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 10863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuExceptionEvent.prototype.toJSONProtocol = function() { 10893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var o = new ProtocolMessage(); 10903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.event = "exception"; 10913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body = { uncaught: this.uncaught_, 10923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu exception: MakeMirror(this.exception_) 10933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu }; 10943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 10953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Exceptions might happen whithout any JavaScript frames. 10963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() > 0) { 10973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceLine = this.sourceLine(); 10983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceColumn = this.sourceColumn(); 10993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceLineText = this.sourceLineText(); 11003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add script information to the event if available. 11023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = this.func().script(); 11033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (script) { 11043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.script = MakeScriptObject_(script, false); 11053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 11063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 11073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.sourceLine = -1; 11083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 11093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return o.toJSONProtocol(); 11113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeCompileEvent(exec_state, script, before) { 11153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new CompileEvent(exec_state, script, before); 11163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction CompileEvent(exec_state, script, before) { 11203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_ = exec_state; 11213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.script_ = MakeMirror(script); 11223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.before_ = before; 11233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuCompileEvent.prototype.executionState = function() { 11273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_; 11283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuCompileEvent.prototype.eventType = function() { 11323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.before_) { 11333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return Debug.DebugEvent.BeforeCompile; 11343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 11353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return Debug.DebugEvent.AfterCompile; 11363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 11373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuCompileEvent.prototype.script = function() { 11413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.script_; 11423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuCompileEvent.prototype.toJSONProtocol = function() { 11463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var o = new ProtocolMessage(); 11473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.running = true; 11483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.before_) { 11493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.event = "beforeCompile"; 11503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 11513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.event = "afterCompile"; 11523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 11533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body = {}; 11543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.script = this.script_; 11553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return o.toJSONProtocol(); 11573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeNewFunctionEvent(func) { 11613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new NewFunctionEvent(func); 11623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction NewFunctionEvent(func) { 11663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.func = func; 11673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuNewFunctionEvent.prototype.eventType = function() { 11713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return Debug.DebugEvent.NewFunction; 11723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuNewFunctionEvent.prototype.name = function() { 11763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.func.name; 11773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuNewFunctionEvent.prototype.setBreakPoint = function(p) { 11813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.setBreakPoint(this.func, p || 0); 11823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeScriptCollectedEvent(exec_state, id) { 11863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new ScriptCollectedEvent(exec_state, id); 11873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ScriptCollectedEvent(exec_state, id) { 11913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_ = exec_state; 11923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.id_ = id; 11933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 11943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 11963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptCollectedEvent.prototype.id = function() { 11973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.id_; 11983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 11993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptCollectedEvent.prototype.executionState = function() { 12023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_; 12033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 12043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuScriptCollectedEvent.prototype.toJSONProtocol = function() { 12073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var o = new ProtocolMessage(); 12083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.running = true; 12093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.event = "scriptCollected"; 12103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body = {}; 12113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.body.script = { id: this.id() }; 12123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return o.toJSONProtocol(); 12133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 12143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction MakeScriptObject_(script, include_source) { 12173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var o = { id: script.id(), 12183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu name: script.name(), 12193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu lineOffset: script.lineOffset(), 12203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu columnOffset: script.columnOffset(), 12213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu lineCount: script.lineCount(), 12223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu }; 12233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(script.data())) { 12243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.data = script.data(); 12253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (include_source) { 12273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu o.source = script.source(); 12283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return o; 12303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 12313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction DebugCommandProcessor(exec_state, opt_is_running) { 12343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_ = exec_state; 12353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.running_ = opt_is_running || false; 12363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 12373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.processDebugRequest = function (request) { 12403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.processDebugJSONRequest(request); 12413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 12423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ProtocolMessage(request) { 12453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Update sequence number. 12463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.seq = next_response_seq++; 12473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request) { 12493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If message is based on a request this is a response. Fill the initial 12503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // response from the request. 12513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.type = 'response'; 12523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.request_seq = request.seq; 12533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.command = request.command; 12543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 12553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If message is not based on a request it is a dabugger generated event. 12563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.type = 'event'; 12573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.success = true; 12593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Handler may set this field to control debugger state. 12603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.running = undefined; 12613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 12623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuProtocolMessage.prototype.setOption = function(name, value) { 12653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!this.options_) { 12663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.options_ = {}; 12673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.options_[name] = value; 12693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 12703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuProtocolMessage.prototype.failed = function(message) { 12733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.success = false; 12743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.message = message; 12753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 12763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 12783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuProtocolMessage.prototype.toJSONProtocol = function() { 12793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Encode the protocol header. 12803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var json = {}; 12813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.seq= this.seq; 12823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.request_seq) { 12833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.request_seq = this.request_seq; 12843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.type = this.type; 12863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.event) { 12873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.event = this.event; 12883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.command) { 12903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.command = this.command; 12913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.success) { 12933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.success = this.success; 12943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 12953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.success = false; 12963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 12973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.body) { 12983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Encode the body part. 12993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var bodyJson; 13003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var serializer = MakeMirrorSerializer(true, this.options_); 13013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.body instanceof Mirror) { 13023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu bodyJson = serializer.serializeValue(this.body); 13033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (this.body instanceof Array) { 13043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu bodyJson = []; 13053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < this.body.length; i++) { 13063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.body[i] instanceof Mirror) { 13073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu bodyJson.push(serializer.serializeValue(this.body[i])); 13083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 13093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu bodyJson.push(ObjectToProtocolObject_(this.body[i], serializer)); 13103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 13133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu bodyJson = ObjectToProtocolObject_(this.body, serializer); 13143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.body = bodyJson; 13163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.refs = serializer.serializeReferencedObjects(); 13173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.message) { 13193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.message = this.message; 13203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.running = this.running; 13223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return JSON.stringify(json); 13233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 13243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.createResponse = function(request) { 13273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return new ProtocolMessage(request); 13283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 13293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.processDebugJSONRequest = function(json_request) { 13323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var request; // Current request. 13333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var response; // Generated response. 13343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 13353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 13363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Convert the JSON string to an object. 13373e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu request = %CompileString('(' + json_request + ')')(); 13383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create an initial response. 13403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response = this.createResponse(request); 13413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.type) { 13433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Type not specified'); 13443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.type != 'request') { 13473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error("Illegal type '" + request.type + "' in request"); 13483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.command) { 13513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Command not specified'); 13523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1354402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu if (request.arguments) { 1355402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu var args = request.arguments; 1356402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu // TODO(yurys): remove request.arguments.compactFormat check once 1357402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu // ChromeDevTools are switched to 'inlineRefs' 1358402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu if (args.inlineRefs || args.compactFormat) { 1359402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu response.setOption('inlineRefs', true); 1360402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu } 1361402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu if (!IS_UNDEFINED(args.maxStringLength)) { 1362402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu response.setOption('maxStringLength', args.maxStringLength); 1363402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu } 13643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 13653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 13663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.command == 'continue') { 13673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.continueRequest_(request, response); 13683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'break') { 13693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.breakRequest_(request, response); 13703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'setbreakpoint') { 13713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.setBreakPointRequest_(request, response); 13723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'changebreakpoint') { 13733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.changeBreakPointRequest_(request, response); 13743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'clearbreakpoint') { 13753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.clearBreakPointRequest_(request, response); 13763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'clearbreakpointgroup') { 13773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.clearBreakPointGroupRequest_(request, response); 1378086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (request.command == 'disconnect') { 1379086aeeaae12517475c22695a200be45495516549Ben Murdoch this.disconnectRequest_(request, response); 1380086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (request.command == 'setexceptionbreak') { 1381086aeeaae12517475c22695a200be45495516549Ben Murdoch this.setExceptionBreakRequest_(request, response); 138225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen } else if (request.command == 'listbreakpoints') { 138325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen this.listBreakpointsRequest_(request, response); 13843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'backtrace') { 13853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.backtraceRequest_(request, response); 13863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'frame') { 13873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.frameRequest_(request, response); 13883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'scopes') { 13893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.scopesRequest_(request, response); 13903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'scope') { 13913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.scopeRequest_(request, response); 13923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'evaluate') { 13933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.evaluateRequest_(request, response); 13943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'lookup') { 13953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.lookupRequest_(request, response); 13963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'references') { 13973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.referencesRequest_(request, response); 13983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'source') { 13993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.sourceRequest_(request, response); 14003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'scripts') { 14013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.scriptsRequest_(request, response); 14023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'threads') { 14033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.threadsRequest_(request, response); 14043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'suspend') { 14053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.suspendRequest_(request, response); 14063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'version') { 14073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.versionRequest_(request, response); 14083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.command == 'profile') { 1409bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch this.profileRequest_(request, response); 14106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } else if (request.command == 'changelive') { 1411bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch this.changeLiveRequest_(request, response); 1412bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } else if (request.command == 'flags') { 1413bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch this.debuggerFlagsRequest_(request, response); 1414086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (request.command == 'v8flags') { 1415086aeeaae12517475c22695a200be45495516549Ben Murdoch this.v8FlagsRequest_(request, response); 1416086aeeaae12517475c22695a200be45495516549Ben Murdoch 1417086aeeaae12517475c22695a200be45495516549Ben Murdoch // GC tools: 1418086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (request.command == 'gc') { 1419086aeeaae12517475c22695a200be45495516549Ben Murdoch this.gcRequest_(request, response); 1420086aeeaae12517475c22695a200be45495516549Ben Murdoch 14213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 14223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Unknown command "' + request.command + '" in request'); 14233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch (e) { 14253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // If there is no response object created one (without command). 14263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!response) { 14273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response = this.createResponse(); 14283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.success = false; 14303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.message = %ToString(e); 14313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Return the response as a JSON encoded string. 14343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 14353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(response.running)) { 14363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Response controls running state. 14373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.running_ = response.running; 14383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block response.running = this.running_; 14403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.toJSONProtocol(); 14413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch (e) { 14423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Failed to generate response - return generic error. 14433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return '{"seq":' + response.seq + ',' + 14443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu '"request_seq":' + request.seq + ',' + 14453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu '"type":"response",' + 14463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu '"success":false,' + 14473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu '"message":"Internal error: ' + %ToString(e) + '"}'; 14483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch (e) { 14503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Failed in one of the catch blocks above - most generic error. 14513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return '{"seq":0,"type":"response","success":false,"message":"Internal error"}'; 14523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 14543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.continueRequest_ = function(request, response) { 14573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for arguments for continue. 14583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments) { 14593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var count = 1; 14603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var action = Debug.StepAction.StepIn; 14613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 14633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var stepaction = request.arguments.stepaction; 14643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var stepcount = request.arguments.stepcount; 14653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the stepcount argument if any. 14673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (stepcount) { 14683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu count = %ToNumber(stepcount); 14693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (count < 0) { 14703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Invalid stepcount argument "' + stepcount + '".'); 14713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the stepaction argument. 14753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (stepaction) { 14763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (stepaction == 'in') { 14773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu action = Debug.StepAction.StepIn; 14783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (stepaction == 'min') { 14793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu action = Debug.StepAction.StepMin; 14803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (stepaction == 'next') { 14813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu action = Debug.StepAction.StepNext; 14823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (stepaction == 'out') { 14833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu action = Debug.StepAction.StepOut; 14843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 14853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu throw new Error('Invalid stepaction argument "' + stepaction + '".'); 14863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Setup the VM for stepping. 14903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_.prepareStep(action, count); 14913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 14923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // VM should be running after executing this request. 14943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.running = true; 14953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 14963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 14983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.breakRequest_ = function(request, response) { 14993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Ignore as break command does not do anything when broken. 15003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 15013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.setBreakPointRequest_ = 15043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu function(request, response) { 15053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal request. 15063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 15073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing arguments'); 15083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 15123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var type = request.arguments.type; 15133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var target = request.arguments.target; 15143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var line = request.arguments.line; 15153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var column = request.arguments.column; 15163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var enabled = IS_UNDEFINED(request.arguments.enabled) ? 15173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu true : request.arguments.enabled; 15183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var condition = request.arguments.condition; 15193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var ignoreCount = request.arguments.ignoreCount; 15203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var groupId = request.arguments.groupId; 15213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 15233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!type || IS_UNDEFINED(target)) { 15243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing argument "type" or "target"'); 15253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (type != 'function' && type != 'handle' && 15283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu type != 'script' && type != 'scriptId') { 15293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Illegal type "' + type + '"'); 15303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Either function or script break point. 15343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point_number; 15353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (type == 'function') { 15363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Handle function break point. 15373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_STRING(target)) { 15383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Argument "target" is not a string value'); 15393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var f; 15423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 15433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find the function through a global evaluate. 15443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu f = this.exec_state_.evaluateGlobal(target).value(); 15453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch (e) { 15463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Error: "' + %ToString(e) + 15473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu '" evaluating "' + target + '"'); 15483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_FUNCTION(f)) { 15513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('"' + target + '" does not evaluate to a function'); 15523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 15533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set function break point. 15563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point_number = Debug.setBreakPoint(f, line, column, condition); 15573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (type == 'handle') { 15583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Find the object pointed by the specified handle. 15593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var handle = parseInt(target, 10); 15603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var mirror = LookupMirror(handle); 15613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!mirror) { 15623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Object #' + handle + '# not found'); 15633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!mirror.isFunction()) { 15653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Object #' + handle + '# is not a function'); 15663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set function break point. 15693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point_number = Debug.setBreakPoint(mirror.value(), 15703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu line, column, condition); 15713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (type == 'script') { 15723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // set script break point. 15733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point_number = 15743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.setScriptBreakPointByName(target, line, column, condition, 15753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu groupId); 15763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { // type == 'scriptId. 15773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break_point_number = 15783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.setScriptBreakPointById(target, line, column, condition, groupId); 15793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set additional break point properties. 15823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = Debug.findBreakPoint(break_point_number); 15833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (ignoreCount) { 15843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.changeBreakPointIgnoreCount(break_point_number, ignoreCount); 15853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!enabled) { 15873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.disableBreakPoint(break_point_number); 15883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 15893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add the break point number to the response. 15913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { type: type, 15923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu breakpoint: break_point_number } 15933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 15943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add break point information to the response. 15953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_point instanceof ScriptBreakPoint) { 15963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { 15973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.type = 'scriptId'; 15983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.script_id = break_point.script_id(); 15993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 16003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.type = 'scriptName'; 16013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.script_name = break_point.script_name(); 16023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.line = break_point.line(); 16043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.column = break_point.column(); 16058defd9ff6930b4e24729971a61cf7469daf119beSteve Block response.body.actual_locations = break_point.actual_locations(); 16063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 16073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.type = 'function'; 16088defd9ff6930b4e24729971a61cf7469daf119beSteve Block response.body.actual_locations = [break_point.actual_location]; 16093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 16113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.changeBreakPointRequest_ = function(request, response) { 16143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal request. 16153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 16163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing arguments'); 16173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 16183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 16213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = %ToNumber(request.arguments.breakpoint); 16223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var enabled = request.arguments.enabled; 16233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var condition = request.arguments.condition; 16243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var ignoreCount = request.arguments.ignoreCount; 16253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 16273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!break_point) { 16283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing argument "breakpoint"'); 16293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 16303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Change enabled state if supplied. 16333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(enabled)) { 16343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (enabled) { 16353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.enableBreakPoint(break_point); 16363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 16373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.disableBreakPoint(break_point); 16383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Change condition if supplied 16423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(condition)) { 16433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.changeBreakPointCondition(break_point, condition); 16443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Change ignore count if supplied 16473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(ignoreCount)) { 16483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.changeBreakPointIgnoreCount(break_point, ignoreCount); 16493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 16513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.clearBreakPointGroupRequest_ = function(request, response) { 16543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal request. 16553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 16563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing arguments'); 16573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 16583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 16613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var group_id = request.arguments.groupId; 16623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 16643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!group_id) { 16653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing argument "groupId"'); 16663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 16673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var cleared_break_points = []; 16703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var new_script_break_points = []; 16713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < script_break_points.length; i++) { 16723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var next_break_point = script_break_points[i]; 16733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (next_break_point.groupId() == group_id) { 16743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu cleared_break_points.push(next_break_point.number()); 16753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu next_break_point.clear(); 16763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 16773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu new_script_break_points.push(next_break_point); 16783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu script_break_points = new_script_break_points; 16813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add the cleared break point numbers to the response. 16833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { breakpoints: cleared_break_points }; 16843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 16853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.clearBreakPointRequest_ = function(request, response) { 16883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal request. 16893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 16903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing arguments'); 16913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 16923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 16933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 16953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var break_point = %ToNumber(request.arguments.breakpoint); 16963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 16973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 16983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!break_point) { 16993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.failed('Missing argument "breakpoint"'); 17003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 17013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 17023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 17033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Clear break point. 17043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu Debug.clearBreakPoint(break_point); 17053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 17063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add the cleared break point number to the response. 17073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { breakpoint: break_point } 17083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 17093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 1710bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 171125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian MonsenDebugCommandProcessor.prototype.listBreakpointsRequest_ = function(request, response) { 171225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen var array = []; 171325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen for (var i = 0; i < script_break_points.length; i++) { 171425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen var break_point = script_break_points[i]; 171525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 171625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen var description = { 171725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen number: break_point.number(), 171825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen line: break_point.line(), 171925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen column: break_point.column(), 172025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen groupId: break_point.groupId(), 172125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen hit_count: break_point.hit_count(), 172225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen active: break_point.active(), 172325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen condition: break_point.condition(), 17248defd9ff6930b4e24729971a61cf7469daf119beSteve Block ignoreCount: break_point.ignoreCount(), 17258defd9ff6930b4e24729971a61cf7469daf119beSteve Block actual_locations: break_point.actual_locations() 172625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen } 1727bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 172825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { 172925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen description.type = 'scriptId'; 173025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen description.script_id = break_point.script_id(); 173125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen } else { 173225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen description.type = 'scriptName'; 173325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen description.script_name = break_point.script_name(); 173425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen } 173525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen array.push(description); 173625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen } 1737bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 1738086aeeaae12517475c22695a200be45495516549Ben Murdoch response.body = { 1739086aeeaae12517475c22695a200be45495516549Ben Murdoch breakpoints: array, 1740086aeeaae12517475c22695a200be45495516549Ben Murdoch breakOnExceptions: Debug.isBreakOnException(), 1741086aeeaae12517475c22695a200be45495516549Ben Murdoch breakOnUncaughtExceptions: Debug.isBreakOnUncaughtException() 1742086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1743086aeeaae12517475c22695a200be45495516549Ben Murdoch} 1744086aeeaae12517475c22695a200be45495516549Ben Murdoch 1745086aeeaae12517475c22695a200be45495516549Ben Murdoch 1746086aeeaae12517475c22695a200be45495516549Ben MurdochDebugCommandProcessor.prototype.disconnectRequest_ = 1747086aeeaae12517475c22695a200be45495516549Ben Murdoch function(request, response) { 1748086aeeaae12517475c22695a200be45495516549Ben Murdoch Debug.disableAllBreakPoints(); 1749086aeeaae12517475c22695a200be45495516549Ben Murdoch this.continueRequest_(request, response); 1750086aeeaae12517475c22695a200be45495516549Ben Murdoch} 1751086aeeaae12517475c22695a200be45495516549Ben Murdoch 1752086aeeaae12517475c22695a200be45495516549Ben Murdoch 1753086aeeaae12517475c22695a200be45495516549Ben MurdochDebugCommandProcessor.prototype.setExceptionBreakRequest_ = 1754086aeeaae12517475c22695a200be45495516549Ben Murdoch function(request, response) { 1755086aeeaae12517475c22695a200be45495516549Ben Murdoch // Check for legal request. 1756086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!request.arguments) { 1757086aeeaae12517475c22695a200be45495516549Ben Murdoch response.failed('Missing arguments'); 1758086aeeaae12517475c22695a200be45495516549Ben Murdoch return; 1759086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1760086aeeaae12517475c22695a200be45495516549Ben Murdoch 1761086aeeaae12517475c22695a200be45495516549Ben Murdoch // Pull out and check the 'type' argument: 1762086aeeaae12517475c22695a200be45495516549Ben Murdoch var type = request.arguments.type; 1763086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!type) { 1764086aeeaae12517475c22695a200be45495516549Ben Murdoch response.failed('Missing argument "type"'); 1765086aeeaae12517475c22695a200be45495516549Ben Murdoch return; 1766086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1767086aeeaae12517475c22695a200be45495516549Ben Murdoch 1768086aeeaae12517475c22695a200be45495516549Ben Murdoch // Initialize the default value of enable: 1769086aeeaae12517475c22695a200be45495516549Ben Murdoch var enabled; 1770086aeeaae12517475c22695a200be45495516549Ben Murdoch if (type == 'all') { 1771086aeeaae12517475c22695a200be45495516549Ben Murdoch enabled = !Debug.isBreakOnException(); 1772086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (type == 'uncaught') { 1773086aeeaae12517475c22695a200be45495516549Ben Murdoch enabled = !Debug.isBreakOnUncaughtException(); 1774086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1775086aeeaae12517475c22695a200be45495516549Ben Murdoch 1776086aeeaae12517475c22695a200be45495516549Ben Murdoch // Pull out and check the 'enabled' argument if present: 1777086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!IS_UNDEFINED(request.arguments.enabled)) { 1778086aeeaae12517475c22695a200be45495516549Ben Murdoch enabled = request.arguments.enabled; 1779086aeeaae12517475c22695a200be45495516549Ben Murdoch if ((enabled != true) && (enabled != false)) { 1780086aeeaae12517475c22695a200be45495516549Ben Murdoch response.failed('Illegal value for "enabled":"' + enabled + '"'); 1781086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1782086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1783086aeeaae12517475c22695a200be45495516549Ben Murdoch 1784086aeeaae12517475c22695a200be45495516549Ben Murdoch // Now set the exception break state: 1785086aeeaae12517475c22695a200be45495516549Ben Murdoch if (type == 'all') { 1786086aeeaae12517475c22695a200be45495516549Ben Murdoch %ChangeBreakOnException(Debug.ExceptionBreak.Caught, enabled); 1787086aeeaae12517475c22695a200be45495516549Ben Murdoch } else if (type == 'uncaught') { 1788086aeeaae12517475c22695a200be45495516549Ben Murdoch %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, enabled); 1789086aeeaae12517475c22695a200be45495516549Ben Murdoch } else { 1790086aeeaae12517475c22695a200be45495516549Ben Murdoch response.failed('Unknown "type":"' + type + '"'); 1791086aeeaae12517475c22695a200be45495516549Ben Murdoch } 1792086aeeaae12517475c22695a200be45495516549Ben Murdoch 1793086aeeaae12517475c22695a200be45495516549Ben Murdoch // Add the cleared break point number to the response. 1794086aeeaae12517475c22695a200be45495516549Ben Murdoch response.body = { 'type': type, 'enabled': enabled }; 179525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen} 179625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 17973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 17983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.backtraceRequest_ = function(request, response) { 17993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the number of frames. 18003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var total_frames = this.exec_state_.frameCount(); 18013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create simple response if there are no frames. 18033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (total_frames == 0) { 18043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { 18053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu totalFrames: total_frames 18063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 18083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Default frame range to include in backtrace. 18113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var from_index = 0 18123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var to_index = kDefaultBacktraceLength; 18133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the range from the arguments. 18153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments) { 18163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments.fromFrame) { 18173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu from_index = request.arguments.fromFrame; 18183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments.toFrame) { 18203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu to_index = request.arguments.toFrame; 18213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments.bottom) { 18233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var tmp_index = total_frames - from_index; 18243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu from_index = total_frames - to_index 18253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu to_index = tmp_index; 18263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (from_index < 0 || to_index < 0) { 18283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid frame number'); 18293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Adjust the index. 18333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu to_index = Math.min(total_frames, to_index); 18343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (to_index <= from_index) { 18363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var error = 'Invalid frame range'; 18373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed(error); 18383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create the response body. 18413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frames = []; 18423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = from_index; i < to_index; i++) { 18433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu frames.push(this.exec_state_.frame(i)); 18443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { 18463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu fromFrame: from_index, 18473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu toFrame: to_index, 18483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu totalFrames: total_frames, 18493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu frames: frames 18503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 18523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.frameRequest_ = function(request, response) { 18553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // No frames no source. 18563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() == 0) { 18573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No frames'); 18583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // With no arguments just keep the selected frame. 18613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments) { 18623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var index = request.arguments.number; 18633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (index < 0 || this.exec_state_.frameCount() <= index) { 18643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid frame number'); 18653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu this.exec_state_.setSelectedFrame(request.arguments.number); 18683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = this.exec_state_.frame(); 18703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 18713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.frameForScopeRequest_ = function(request) { 18743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the frame for which the scope or scopes are requested. With no frameNumber 18753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // argument use the currently selected frame. 18763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) { 18773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu frame_index = request.arguments.frameNumber; 18783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { 18793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid frame number'); 18803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(frame_index); 18823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 18833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.exec_state_.frame(); 18843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 18863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { 18893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // No frames no scopes. 18903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() == 0) { 18913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No scopes'); 18923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 18933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the frame for which the scopes are requested. 18953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame = this.frameForScopeRequest_(request); 18963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 18973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Fill all scopes for this frame. 18983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var total_scopes = frame.scopeCount(); 18993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var scopes = []; 19003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < total_scopes; i++) { 19013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu scopes.push(frame.scope(i)); 19023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { 19043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu fromScope: 0, 19053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu toScope: total_scopes, 19063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu totalScopes: total_scopes, 19073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu scopes: scopes 19083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 19103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { 19133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // No frames no scopes. 19143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() == 0) { 19153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No scopes'); 19163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the frame for which the scope is requested. 19193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame = this.frameForScopeRequest_(request); 19203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // With no scope argument just return top scope. 19223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var scope_index = 0; 19233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { 19243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu scope_index = %ToNumber(request.arguments.number); 19253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (scope_index < 0 || frame.scopeCount() <= scope_index) { 19263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid scope number'); 19273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = frame.scope(scope_index); 19313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 19323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { 19353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 19363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Missing arguments'); 19373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 19403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var expression = request.arguments.expression; 19413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame = request.arguments.frame; 19423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var global = request.arguments.global; 19433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var disable_break = request.arguments.disable_break; 1944b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch var additional_context = request.arguments.additional_context; 19453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // The expression argument could be an integer so we convert it to a 19473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // string. 19483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu try { 19493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu expression = String(expression); 19503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } catch(e) { 19513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Failed to convert expression argument to string'); 19523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 19553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(frame) && global) { 19563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Arguments "frame" and "global" are exclusive'); 19573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 1958b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch 1959b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch var additional_context_object; 1960b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch if (additional_context) { 1961b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch additional_context_object = {}; 1962b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch for (var i = 0; i < additional_context.length; i++) { 1963b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch var mapping = additional_context[i]; 1964b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch if (!IS_STRING(mapping.name) || !IS_NUMBER(mapping.handle)) { 1965b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch return response.failed("Context element #" + i + 1966b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch " must contain name:string and handle:number"); 1967b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch } 1968b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch var context_value_mirror = LookupMirror(mapping.handle); 1969b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch if (!context_value_mirror) { 1970b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch return response.failed("Context object '" + mapping.name + 1971b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch "' #" + mapping.handle + "# not found"); 1972b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch } 1973b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch additional_context_object[mapping.name] = context_value_mirror.value(); 1974b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch } 1975b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch } 19763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Global evaluate. 19783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (global) { 19793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Evaluate in the global context. 1980b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch response.body = this.exec_state_.evaluateGlobal( 1981b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch expression, Boolean(disable_break), additional_context_object); 19823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 19833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Default value for disable_break is true. 19863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(disable_break)) { 19873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu disable_break = true; 19883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // No frames no evaluate in frame. 19913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() == 0) { 19923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No frames'); 19933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 19943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 19953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check whether a frame was specified. 19963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(frame)) { 19973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame_number = %ToNumber(frame); 19983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { 19993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid frame "' + frame + '"'); 20003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Evaluate in the specified frame. 20023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = this.exec_state_.frame(frame_number).evaluate( 2003b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch expression, Boolean(disable_break), additional_context_object); 20043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 20053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 20063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Evaluate in the selected frame. 20073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = this.exec_state_.frame().evaluate( 2008b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch expression, Boolean(disable_break), additional_context_object); 20093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return; 20103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 20123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { 20153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 20163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Missing arguments'); 20173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 20203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var handles = request.arguments.handles; 20213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 20233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(handles)) { 20243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Argument "handles" missing'); 20253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Set 'includeSource' option for script lookup. 20283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(request.arguments.includeSource)) { 20293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu includeSource = %ToBoolean(request.arguments.includeSource); 20303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.setOption('includeSource', includeSource); 20313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Lookup handles. 20343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var mirrors = {}; 20353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < handles.length; i++) { 20363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var handle = handles[i]; 20373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var mirror = LookupMirror(handle); 20383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!mirror) { 20393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Object #' + handle + '# not found'); 20403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu mirrors[handle] = mirror; 20423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = mirrors; 20443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 20453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.referencesRequest_ = 20483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu function(request, response) { 20493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 20503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Missing arguments'); 20513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 20543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var type = request.arguments.type; 20553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var handle = request.arguments.handle; 20563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Check for legal arguments. 20583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(type)) { 20593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Argument "type" missing'); 20603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_UNDEFINED(handle)) { 20623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Argument "handle" missing'); 20633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (type != 'referencedBy' && type != 'constructedBy') { 20653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid type "' + type + '"'); 20663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Lookup handle and return objects with references the object. 20693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var mirror = LookupMirror(handle); 20703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (mirror) { 20713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (type == 'referencedBy') { 20723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = mirror.referencedBy(); 20733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 20743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = mirror.constructedBy(); 20753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 20773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Object #' + handle + '# not found'); 20783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 20803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.sourceRequest_ = function(request, response) { 20833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // No frames no source. 20843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (this.exec_state_.frameCount() == 0) { 20853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No source'); 20863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 20873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var from_line; 20893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var to_line; 20903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame = this.exec_state_.frame(); 20913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments) { 20923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 20933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu from_line = request.arguments.fromLine; 20943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu to_line = request.arguments.toLine; 20953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 20963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(request.arguments.frame)) { 20973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var frame_number = %ToNumber(request.arguments.frame); 20983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { 20993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid frame "' + frame + '"'); 21003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu frame = this.exec_state_.frame(frame_number); 21023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the script selected. 21063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var script = frame.func().script(); 21073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!script) { 21083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('No source'); 21093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the source slice and fill it into the response. 21123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var slice = script.sourceSlice(from_line, to_line); 21133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!slice) { 21143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid line interval'); 21153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = {}; 21173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.source = slice.sourceText(); 21183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.fromLine = slice.from_line; 21193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.toLine = slice.to_line; 21203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.fromPosition = slice.from_position; 21213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.toPosition = slice.to_position; 21223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.totalLines = script.lineCount(); 21233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 21243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) { 21273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var types = ScriptTypeFlag(Debug.ScriptType.Normal); 21283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var includeSource = false; 21293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var idsToInclude = null; 21303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments) { 21313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Pull out arguments. 21323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(request.arguments.types)) { 21333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu types = %ToNumber(request.arguments.types); 21343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (isNaN(types) || types < 0) { 21353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Invalid types "' + request.arguments.types + '"'); 21363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 21393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(request.arguments.includeSource)) { 21403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu includeSource = %ToBoolean(request.arguments.includeSource); 21413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.setOption('includeSource', includeSource); 21423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 21443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (IS_ARRAY(request.arguments.ids)) { 21453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu idsToInclude = {}; 21463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var ids = request.arguments.ids; 21473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < ids.length; i++) { 21483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu idsToInclude[ids[i]] = true; 21493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2151086aeeaae12517475c22695a200be45495516549Ben Murdoch 2152086aeeaae12517475c22695a200be45495516549Ben Murdoch var filterStr = null; 2153086aeeaae12517475c22695a200be45495516549Ben Murdoch var filterNum = null; 2154086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!IS_UNDEFINED(request.arguments.filter)) { 2155086aeeaae12517475c22695a200be45495516549Ben Murdoch var num = %ToNumber(request.arguments.filter); 2156086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!isNaN(num)) { 2157086aeeaae12517475c22695a200be45495516549Ben Murdoch filterNum = num; 2158086aeeaae12517475c22695a200be45495516549Ben Murdoch } 2159086aeeaae12517475c22695a200be45495516549Ben Murdoch filterStr = request.arguments.filter; 2160086aeeaae12517475c22695a200be45495516549Ben Murdoch } 21613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Collect all scripts in the heap. 21643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var scripts = %DebugGetLoadedScripts(); 21653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = []; 21673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < scripts.length; i++) { 21693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (idsToInclude && !idsToInclude[scripts[i].id]) { 21703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu continue; 21713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2172086aeeaae12517475c22695a200be45495516549Ben Murdoch if (filterStr || filterNum) { 2173086aeeaae12517475c22695a200be45495516549Ben Murdoch var script = scripts[i]; 2174086aeeaae12517475c22695a200be45495516549Ben Murdoch var found = false; 2175086aeeaae12517475c22695a200be45495516549Ben Murdoch if (filterNum && !found) { 2176086aeeaae12517475c22695a200be45495516549Ben Murdoch if (script.id && script.id === filterNum) { 2177086aeeaae12517475c22695a200be45495516549Ben Murdoch found = true; 2178086aeeaae12517475c22695a200be45495516549Ben Murdoch } 2179086aeeaae12517475c22695a200be45495516549Ben Murdoch } 2180086aeeaae12517475c22695a200be45495516549Ben Murdoch if (filterStr && !found) { 2181086aeeaae12517475c22695a200be45495516549Ben Murdoch if (script.name && script.name.indexOf(filterStr) >= 0) { 2182086aeeaae12517475c22695a200be45495516549Ben Murdoch found = true; 2183086aeeaae12517475c22695a200be45495516549Ben Murdoch } 2184086aeeaae12517475c22695a200be45495516549Ben Murdoch } 2185086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!found) continue; 2186086aeeaae12517475c22695a200be45495516549Ben Murdoch } 21873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (types & ScriptTypeFlag(scripts[i].type)) { 21883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body.push(MakeMirror(scripts[i])); 21893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 21913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 21923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.threadsRequest_ = function(request, response) { 21953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get the number of threads. 21963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var total_threads = this.exec_state_.threadCount(); 21973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 21983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Get information for all threads. 21993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var threads = []; 22003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < total_threads; i++) { 22013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var details = %GetThreadDetails(this.exec_state_.break_id, i); 22023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var thread_info = { current: details[0], 22033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu id: details[1] 22043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu threads.push(thread_info); 22063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Create the response body. 22093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { 22103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu totalThreads: total_threads, 22113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu threads: threads 22123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 22143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.suspendRequest_ = function(request, response) { 22173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.running = false; 22183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 22193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.versionRequest_ = function(request, response) { 22223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = { 22233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu V8Version: %GetV8Version() 22243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 22263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.profileRequest_ = function(request, response) { 22293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!request.arguments) { 22303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Missing arguments'); 22313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var modules = parseInt(request.arguments.modules); 22333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (isNaN(modules)) { 22343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Modules is not an integer'); 22353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 2236402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu var tag = parseInt(request.arguments.tag); 2237402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu if (isNaN(tag)) { 2238402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu tag = 0; 2239402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu } 22403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (request.arguments.command == 'resume') { 2241402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu %ProfilerResume(modules, tag); 22423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (request.arguments.command == 'pause') { 2243402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu %ProfilerPause(modules, tag); 22443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 22453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return response.failed('Unknown command'); 22463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 22473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu response.body = {}; 22483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 22493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 22516ded16be15dd865a9b21ea304d5273c8be299c87Steve BlockDebugCommandProcessor.prototype.changeLiveRequest_ = function(request, response) { 22526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (!Debug.LiveEdit) { 22536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return response.failed('LiveEdit feature is not supported'); 22546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (!request.arguments) { 22566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return response.failed('Missing arguments'); 22576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22586ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var script_id = request.arguments.script_id; 22598defd9ff6930b4e24729971a61cf7469daf119beSteve Block var preview_only = !!request.arguments.preview_only; 2260f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch 22616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var scripts = %DebugGetLoadedScripts(); 22626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 22636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var the_script = null; 22646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block for (var i = 0; i < scripts.length; i++) { 22656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (scripts[i].id == script_id) { 22666ded16be15dd865a9b21ea304d5273c8be299c87Steve Block the_script = scripts[i]; 22676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (!the_script) { 22706ded16be15dd865a9b21ea304d5273c8be299c87Steve Block response.failed('Script not found'); 22716ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return; 22726ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 22746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var change_log = new Array(); 2275bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 22766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block if (!IS_STRING(request.arguments.new_source)) { 22776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block throw "new_source argument expected"; 22786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 22796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 22806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block var new_source = request.arguments.new_source; 2281f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch 22828defd9ff6930b4e24729971a61cf7469daf119beSteve Block var result_description = Debug.LiveEdit.SetScriptSource(the_script, 22838defd9ff6930b4e24729971a61cf7469daf119beSteve Block new_source, preview_only, change_log); 22848defd9ff6930b4e24729971a61cf7469daf119beSteve Block response.body = {change_log: change_log, result: result_description}; 2285f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch 2286bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch if (!preview_only && !this.running_ && result_description.stack_modified) { 2287bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response.body.stepin_recommended = true; 2288bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 22896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block}; 22906ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 22916ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 2292bb769b257e753aafcbd96767abb2abc645eaa20cBen MurdochDebugCommandProcessor.prototype.debuggerFlagsRequest_ = function(request, 2293bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response) { 2294bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch // Check for legal request. 2295bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch if (!request.arguments) { 2296bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response.failed('Missing arguments'); 2297bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch return; 2298bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2299bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 2300bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch // Pull out arguments. 2301bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch var flags = request.arguments.flags; 2302bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 2303bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response.body = { flags: [] }; 2304bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch if (!IS_UNDEFINED(flags)) { 2305bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch for (var i = 0; i < flags.length; i++) { 2306bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch var name = flags[i].name; 2307bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch var debugger_flag = debugger_flags[name]; 2308bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch if (!debugger_flag) { 2309bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch continue; 2310bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2311bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch if ('value' in flags[i]) { 2312bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch debugger_flag.setValue(flags[i].value); 2313bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2314bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response.body.flags.push({ name: name, value: debugger_flag.getValue() }); 2315bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2316bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } else { 2317bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch for (var name in debugger_flags) { 2318bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch var value = debugger_flags[name].getValue(); 2319bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch response.body.flags.push({ name: name, value: value }); 2320bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2321bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch } 2322bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch} 2323bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 2324bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch 2325086aeeaae12517475c22695a200be45495516549Ben MurdochDebugCommandProcessor.prototype.v8FlagsRequest_ = function(request, response) { 2326086aeeaae12517475c22695a200be45495516549Ben Murdoch var flags = request.arguments.flags; 2327086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!flags) flags = ''; 2328086aeeaae12517475c22695a200be45495516549Ben Murdoch %SetFlags(flags); 2329086aeeaae12517475c22695a200be45495516549Ben Murdoch}; 2330086aeeaae12517475c22695a200be45495516549Ben Murdoch 2331086aeeaae12517475c22695a200be45495516549Ben Murdoch 2332086aeeaae12517475c22695a200be45495516549Ben MurdochDebugCommandProcessor.prototype.gcRequest_ = function(request, response) { 2333086aeeaae12517475c22695a200be45495516549Ben Murdoch var type = request.arguments.type; 2334086aeeaae12517475c22695a200be45495516549Ben Murdoch if (!type) type = 'all'; 2335086aeeaae12517475c22695a200be45495516549Ben Murdoch 2336086aeeaae12517475c22695a200be45495516549Ben Murdoch var before = %GetHeapUsage(); 2337086aeeaae12517475c22695a200be45495516549Ben Murdoch %CollectGarbage(type); 2338086aeeaae12517475c22695a200be45495516549Ben Murdoch var after = %GetHeapUsage(); 2339086aeeaae12517475c22695a200be45495516549Ben Murdoch 2340086aeeaae12517475c22695a200be45495516549Ben Murdoch response.body = { "before": before, "after": after }; 2341086aeeaae12517475c22695a200be45495516549Ben Murdoch}; 2342086aeeaae12517475c22695a200be45495516549Ben Murdoch 2343086aeeaae12517475c22695a200be45495516549Ben Murdoch 2344086aeeaae12517475c22695a200be45495516549Ben Murdoch 2345086aeeaae12517475c22695a200be45495516549Ben Murdoch 23463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Check whether the previously processed command caused the VM to become 23473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// running. 23483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.isRunning = function() { 23493100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return this.running_; 23503100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 23513100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23523100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23533100271588b61cbc1dc472a3f2f105d2eed8497fAndrei PopescuDebugCommandProcessor.prototype.systemBreak = function(cmd, args) { 23543100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return %SystemBreak(); 23553100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 23563100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction NumberToHex8Str(n) { 23593100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var r = ""; 23603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < 8; ++i) { 23613100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var c = hexCharArray[n & 0x0F]; // hexCharArray is defined in uri.js 23623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu r = c + r; 23633100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu n = n >>> 4; 23643100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 23653100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return r; 23663100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}; 23673100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23683100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23693100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu/** 23703100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * Convert an Object to its debugger protocol representation. The representation 23713100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * may be serilized to a JSON object using JSON.stringify(). 23723100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * This implementation simply runs through all string property names, converts 23733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * each property value to a protocol value and adds the property to the result 23743100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * object. For type "object" the function will be called recursively. Note that 23753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * circular structures will cause infinite recursion. 23763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {Object} object The object to format as protocol object. 23773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {MirrorSerializer} mirror_serializer The serializer to use if any 23783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * mirror objects are encountered. 23793100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @return {Object} Protocol object value. 23803100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu */ 23813100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ObjectToProtocolObject_(object, mirror_serializer) { 23823100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var content = {}; 23833100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var key in object) { 23843100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Only consider string keys. 23853100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (typeof key == 'string') { 23863100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Format the value based on its type. 23873100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var property_value_json = ValueToProtocolValue_(object[key], 23883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu mirror_serializer); 23893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Add the property if relevant. 23903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (!IS_UNDEFINED(property_value_json)) { 23913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu content[key] = property_value_json; 23923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 23933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 23943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 23956ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 23963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return content; 23973100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 23983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 23993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 24003100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu/** 24013100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * Convert an array to its debugger protocol representation. It will convert 24023100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * each array element to a protocol value. 24033100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {Array} array The array to format as protocol array. 24043100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {MirrorSerializer} mirror_serializer The serializer to use if any 24053100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * mirror objects are encountered. 24063100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @return {Array} Protocol array value. 24073100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu */ 24083100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ArrayToProtocolArray_(array, mirror_serializer) { 24093100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var json = []; 24103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu for (var i = 0; i < array.length; i++) { 24113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json.push(ValueToProtocolValue_(array[i], mirror_serializer)); 24123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 24133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return json; 24143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 24153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 24163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 24173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu/** 24186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Convert a value to its debugger protocol representation. 24193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {*} value The value to format as protocol value. 24203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @param {MirrorSerializer} mirror_serializer The serializer to use if any 24213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * mirror objects are encountered. 24223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu * @return {*} Protocol value. 24233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu */ 24243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescufunction ValueToProtocolValue_(value, mirror_serializer) { 24253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu // Format the value based on its type. 24263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu var json; 24273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu switch (typeof value) { 24283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu case 'object': 24293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu if (value instanceof Mirror) { 24303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json = mirror_serializer.serializeValue(value); 24313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else if (IS_ARRAY(value)){ 24323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json = ArrayToProtocolArray_(value, mirror_serializer); 24333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } else { 24343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json = ObjectToProtocolObject_(value, mirror_serializer); 24353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 24363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break; 24373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 24383100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu case 'boolean': 24393100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu case 'string': 24403100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu case 'number': 24413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json = value; 24423100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu break 24433100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu 24443100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu default: 24453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu json = null; 24463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu } 24473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu return json; 24483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} 2449