Support setting brekpoint by script name set in //@ scriptURL= comment,

in case script name is missing.

BUG=http://crbug.com/39290

Author: Andrey Kosyakov (caseq@chromium.org)
Original issue: http://codereview.chromium.org/1303003

TBR=sgjesse@chromium.org

Review URL: http://codereview.chromium.org/1527007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4337 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3c2964a7
...@@ -327,7 +327,7 @@ ScriptBreakPoint.prototype.matchesScript = function(script) { ...@@ -327,7 +327,7 @@ ScriptBreakPoint.prototype.matchesScript = function(script) {
if (this.type_ == Debug.ScriptBreakPointType.ScriptId) { if (this.type_ == Debug.ScriptBreakPointType.ScriptId) {
return this.script_id_ == script.id; return this.script_id_ == script.id;
} else { // this.type_ == Debug.ScriptBreakPointType.ScriptName } else { // this.type_ == Debug.ScriptBreakPointType.ScriptName
return this.script_name_ == script.name && return this.script_name_ == script.nameOrSourceURL() &&
script.line_offset <= this.line_ && script.line_offset <= this.line_ &&
this.line_ < script.line_offset + script.lineCount(); this.line_ < script.line_offset + script.lineCount();
} }
......
...@@ -432,6 +432,30 @@ Script.prototype.lineCount = function() { ...@@ -432,6 +432,30 @@ Script.prototype.lineCount = function() {
}; };
/**
* Returns the name of script if available, contents of sourceURL comment
* otherwise. See
* http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
* for details on using //@ sourceURL comment to identify scritps that don't
* have name.
*
* @return {?string} script name if present, value for //@ sourceURL comment
* otherwise.
*/
Script.prototype.nameOrSourceURL = function() {
if (this.name)
return this.name;
// TODO(608): the spaces in a regexp below had to be escaped as \040
// because this file is being processed by js2c whose handling of spaces
// in regexps is broken. Also, ['"] are excluded from allowed URLs to
// avoid matches against sources that invoke evals with sourceURL.
var sourceUrlPattern =
/\/\/@[\040\t]sourceURL=[\040\t]*([^\s'"]*)[\040\t]*$/m;
var match = sourceUrlPattern.exec(this.source);
return match ? match[1] : this.name;
}
/** /**
* Class for source location. A source location is a position within some * Class for source location. A source location is a position within some
* source with the following properties: * source with the following properties:
......
...@@ -1728,8 +1728,7 @@ ScriptMirror.prototype.value = function() { ...@@ -1728,8 +1728,7 @@ ScriptMirror.prototype.value = function() {
ScriptMirror.prototype.name = function() { ScriptMirror.prototype.name = function() {
// If we have name, we trust it more than sourceURL from comments return this.script_.name || this.script_.nameOrSourceURL();
return this.script_.name || this.sourceUrlFromComment_();
}; };
...@@ -1824,29 +1823,6 @@ ScriptMirror.prototype.toText = function() { ...@@ -1824,29 +1823,6 @@ ScriptMirror.prototype.toText = function() {
} }
/**
* Returns a suggested script URL from comments in script code (if found),
* undefined otherwise. Used primarily by debuggers for identifying eval()'ed
* scripts. See
* http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
* for details.
*
* @return {?string} value for //@ sourceURL comment
*/
ScriptMirror.prototype.sourceUrlFromComment_ = function() {
if (!('sourceUrl_' in this) && this.source()) {
// TODO(608): the spaces in a regexp below had to be escaped as \040
// because this file is being processed by js2c whose handling of spaces
// in regexps is broken.
// We're not using \s here to prevent \n from matching.
var sourceUrlPattern = /\/\/@[\040\t]sourceURL=[\040\t]*(\S+)[\040\t]*$/m;
var match = sourceUrlPattern.exec(this.source());
this.sourceUrl_ = match ? match[1] : undefined;
}
return this.sourceUrl_;
};
/** /**
* Mirror object for context. * Mirror object for context.
* @param {Object} data The context data * @param {Object} data The context data
......
...@@ -116,6 +116,8 @@ function listener(event, exec_state, event_data, data) { ...@@ -116,6 +116,8 @@ function listener(event, exec_state, event_data, data) {
mirror = debug.MakeMirror(o.a); mirror = debug.MakeMirror(o.a);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false); testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":1}', true, true);
// Indicate that all was processed. // Indicate that all was processed.
listenerComplete = true; listenerComplete = true;
} }
...@@ -136,6 +138,7 @@ function g() { ...@@ -136,6 +138,7 @@ function g() {
}; };
eval('function h(){}'); eval('function h(){}');
eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript');
o = {a:function(){},b:function(){}} o = {a:function(){},b:function(){}}
...@@ -143,9 +146,12 @@ o = {a:function(){},b:function(){}} ...@@ -143,9 +146,12 @@ o = {a:function(){},b:function(){}}
f_script_id = Debug.findScript(f).id; f_script_id = Debug.findScript(f).id;
g_script_id = Debug.findScript(g).id; g_script_id = Debug.findScript(g).id;
h_script_id = Debug.findScript(h).id; h_script_id = Debug.findScript(h).id;
sourceURL_script_id = Debug.findScript(sourceUrlFunc).id;
assertTrue(f_script_id > 0, "invalid script id for f"); assertTrue(f_script_id > 0, "invalid script id for f");
assertTrue(g_script_id > 0, "invalid script id for g"); assertTrue(g_script_id > 0, "invalid script id for g");
assertTrue(h_script_id > 0, "invalid script id for h"); assertTrue(h_script_id > 0, "invalid script id for h");
assertTrue(sourceURL_script_id > 0, "invalid script id for sourceUrlFunc");
assertEquals(f_script_id, g_script_id); assertEquals(f_script_id, g_script_id);
// Get the source line for the test functions. // Get the source line for the test functions.
...@@ -161,5 +167,20 @@ assertEquals(h_line, 0, "invalid line for h"); ...@@ -161,5 +167,20 @@ assertEquals(h_line, 0, "invalid line for h");
Debug.setBreakPoint(g, 0, 0); Debug.setBreakPoint(g, 0, 0);
g(); g();
// Make sure that the debug event listener vas invoked. // Make sure that the debug event listener was invoked.
assertTrue(listenerComplete, "listener did not run to completion: " + exception); assertTrue(listenerComplete, "listener did not run to completion: " + exception);
// Try setting breakpoint by url specified in sourceURL
var breakListenerCalled = false;
function breakListener(event) {
if (event == Debug.DebugEvent.Break)
breakListenerCalled = true;
}
Debug.setListener(breakListener);
sourceUrlFunc();
assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by sourceURL");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment