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();
}
/**
+ * 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
* source with the following properties:
* script : script object for the source
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();
};
/**
- * 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.
* @param {Object} data The context data
* @constructor
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;
}
};
eval('function h(){}');
+eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript');
o = {a:function(){},b:function(){}}
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.
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");