Revision: 4337
Author: [email protected]
Date: Thu Apr 1 09:25:07 2010
Log: Support setting brekpoint by script name set in //@ scriptURL= comment,
in case script name is missing.
BUG=http://crbug.com/39290
Author: Andrey Kosyakov ([email protected])
Original issue: http://codereview.chromium.org/1303003
[email protected]
Review URL: http://codereview.chromium.org/1527007
http://code.google.com/p/v8/source/detail?r=4337
Modified:
/branches/bleeding_edge/src/debug-debugger.js
/branches/bleeding_edge/src/messages.js
/branches/bleeding_edge/src/mirror-debugger.js
/branches/bleeding_edge/test/mjsunit/debug-setbreakpoint.js
=======================================
--- /branches/bleeding_edge/src/debug-debugger.js Tue Mar 30 00:15:23 2010
+++ /branches/bleeding_edge/src/debug-debugger.js Thu Apr 1 09:25:07 2010
@@ -327,7 +327,7 @@
if (this.type_ == Debug.ScriptBreakPointType.ScriptId) {
return this.script_id_ == script.id;
} else { // this.type_ == Debug.ScriptBreakPointType.ScriptName
- return this.script_name_ == script.name &&
+ return this.script_name_ == script.nameOrSourceURL() &&
script.line_offset <= this.line_ &&
this.line_ < script.line_offset + script.lineCount();
}
=======================================
--- /branches/bleeding_edge/src/messages.js Tue Mar 30 00:15:23 2010
+++ /branches/bleeding_edge/src/messages.js Thu Apr 1 09:25:07 2010
@@ -430,6 +430,30 @@
// Return number of source lines.
return this.line_ends.length;
};
+
+
+/**
+ * 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;
+}
/**
=======================================
--- /branches/bleeding_edge/src/mirror-debugger.js Tue Mar 30 00:15:23 2010
+++ /branches/bleeding_edge/src/mirror-debugger.js Thu Apr 1 09:25:07 2010
@@ -1728,8 +1728,7 @@
ScriptMirror.prototype.name = function() {
- // If we have name, we trust it more than sourceURL from comments
- return this.script_.name || this.sourceUrlFromComment_();
+ return this.script_.name || this.script_.nameOrSourceURL();
};
@@ -1822,29 +1821,6 @@
result += ')';
return result;
}
-
-
-/**
- * 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_;
-};
/**
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-setbreakpoint.js Thu Oct 15
13:06:08 2009
+++ /branches/bleeding_edge/test/mjsunit/debug-setbreakpoint.js Thu Apr 1
09:25:07 2010
@@ -116,6 +116,8 @@
mirror = debug.MakeMirror(o.a);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle()
+ '}', true, false);
+
testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":1}',
true, true);
+
// Indicate that all was processed.
listenerComplete = true;
}
@@ -136,6 +138,7 @@
};
eval('function h(){}');
+eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript');
o = {a:function(){},b:function(){}}
@@ -143,9 +146,12 @@
f_script_id = Debug.findScript(f).id;
g_script_id = Debug.findScript(g).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(g_script_id > 0, "invalid script id for g");
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);
// Get the source line for the test functions.
@@ -161,5 +167,20 @@
Debug.setBreakPoint(g, 0, 0);
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);
+
+// 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");
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
To unsubscribe, reply using "remove me" as the subject.