Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Unified Diff: src/messages.js

Issue 6709027: Make Script.prototype.nameOrSourceURL use indexOf search first before trying to match with a RegExp. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comment. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index ea0096fe1ae85a2c369e56c602e4d36129a20631..45de71c9285454e88fd24cb406c5d00110a84e5e 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -495,10 +495,24 @@ Script.prototype.nameOrSourceURL = function() {
// 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;
+ // A better solution would be to detect these special comments in
+ // the scanner/parser.
+ var source = ToString(this.source);
+ var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0);
+ if (sourceUrlPos > 4) {
+ var sourceUrlPattern =
+ /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm;
+ // Don't reuse lastMatchInfo here, so we create a new array with room
+ // for four captures (array with length one longer than the index
+ // of the fourth capture, where the numbering is zero-based).
+ var matchInfo = new InternalArray(CAPTURE(3) + 1);
+ var match =
+ %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo);
+ if (match) {
+ return SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]);
+ }
+ }
+ return this.name;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698