line = this.client.currentSourceLine + 1;
}
- if (script != +script && !this.client.scripts[script]) {
- Object.keys(this.client.scripts).forEach(function(id) {
- if (self.client.scripts[id].name.indexOf(script) !== -1) {
- if (scriptId) {
- ambiguous = true;
- }
- scriptId = id;
- }
- });
+ if (/\(\)$/.test(script)) {
+ // setBreakpoint('functionname()');
+ var req = {
+ type: 'function',
+ target: script.replace(/\(\)$/, ''),
+ condition: condition
+ };
} else {
- scriptId = script;
- }
+ // setBreakpoint('scriptname')
+ if (script != +script && !this.client.scripts[script]) {
+ var scripts = this.client.scripts;
+ Object.keys(scripts).forEach(function(id) {
+ if (scripts[id] && scripts[id].name.indexOf(script) !== -1) {
+ if (scriptId) {
+ ambiguous = true;
+ }
+ scriptId = id;
+ }
+ });
+ } else {
+ scriptId = script;
+ }
- if (!scriptId) return this.error('Script : ' + script + ' not found');
- if (ambiguous) return this.error('Script name is ambiguous');
- if (line <= 0) return this.error('Line should be a positive value');
+ if (!scriptId) return this.error('Script : ' + script + ' not found');
+ if (ambiguous) return this.error('Script name is ambiguous');
+ if (line <= 0) return this.error('Line should be a positive value');
- var req = {
- type: 'scriptId',
- target: scriptId,
- line: line - 1,
- condition: condition
- };
+ var req = {
+ type: 'scriptId',
+ target: scriptId,
+ line: line - 1,
+ condition: condition
+ };
+ }
self.pause();
self.client.setBreakpoint(req, function(res) {
if (!silent) {
self.list(5);
}
- self.client.breakpoints.push({
- id: res.body.breakpoint,
- scriptId: scriptId,
- script: (self.client.scripts[scriptId] || {}).name,
- line: line,
- condition: condition
- });
+
+ // Try load scriptId and line from response
+ if (!scriptId) {
+ scriptId = res.body.script_id;
+ line = res.body.line;
+ }
+
+ // If we finally have one - remember this breakpoint
+ if (scriptId) {
+ self.client.breakpoints.push({
+ id: res.body.breakpoint,
+ scriptId: scriptId,
+ script: (self.client.scripts[scriptId] || {}).name,
+ line: line,
+ condition: condition
+ });
+ }
} else {
if (!silent) {
- self.print(req.message || 'error!');
+ self.print(res.message || 'error!');
}
}
self.resume();
var expected = [];
child.on('line', function(line) {
- console.log(JSON.stringify(line));
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift();
function next() {
if (expected.length > 0) {
child.stdin.write(expected[0].input + '\n');
- console.log('---');
- console.log('>>', expected[0].input);
} else {
finish();
}
"\b 9 };"
]);
+// Set breakpoint by function name
+addTest('sb("setInterval()", "!(setInterval.flag++)")', [
+ "debug> \b 2 debugger;",
+ "\b 3 debugger;",
+ "\b 4 function a(x) {",
+ "\b 5 var i = 10;",
+ "\b 6 while (--i != 0);",
+ "\b 7 debugger;",
+ "\b 8 return i;",
+ "\b 9 };",
+ "\b 10 function b() {",
+ "\b 11 return ['hello', 'world'].join(' ');",
+ "\b 12 };"
+]);
+
+// Continue
+addTest('c', [
+ "debug> debug> debug> debug> \bbreak in node.js:150",
+ "\b*148 ",
+ "\b 149 global.setInterval = function() {",
+ "\b 150 var t = NativeModule.require('timers');",
+ "\b 151 return t.setInterval.apply(this, arguments);",
+ "\b 152 };"
+]);
+
// Continue
addTest('c, bt', [
"debug> \bCan't request backtrace now"