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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 * @return {?string} script name if present, value for //@ sourceURL comment 488 * @return {?string} script name if present, value for //@ sourceURL comment
489 * otherwise. 489 * otherwise.
490 */ 490 */
491 Script.prototype.nameOrSourceURL = function() { 491 Script.prototype.nameOrSourceURL = function() {
492 if (this.name) 492 if (this.name)
493 return this.name; 493 return this.name;
494 // TODO(608): the spaces in a regexp below had to be escaped as \040 494 // TODO(608): the spaces in a regexp below had to be escaped as \040
495 // because this file is being processed by js2c whose handling of spaces 495 // because this file is being processed by js2c whose handling of spaces
496 // in regexps is broken. Also, ['"] are excluded from allowed URLs to 496 // in regexps is broken. Also, ['"] are excluded from allowed URLs to
497 // avoid matches against sources that invoke evals with sourceURL. 497 // avoid matches against sources that invoke evals with sourceURL.
498 var sourceUrlPattern = 498 // A better solution would be to detect these special comments in
499 /\/\/@[\040\t]sourceURL=[\040\t]*([^\s'"]*)[\040\t]*$/m; 499 // the scanner/parser.
500 var match = sourceUrlPattern.exec(this.source); 500 var source = ToString(this.source);
501 return match ? match[1] : this.name; 501 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0);
502 if (sourceUrlPos > 4) {
503 var sourceUrlPattern =
504 /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm;
505 // Don't reuse lastMatchInfo here, so we create a new array with room
506 // for four captures (array with length one longer than the index
507 // of the fourth capture, where the numbering is zero-based).
508 var matchInfo = new InternalArray(CAPTURE(3) + 1);
509 var match =
510 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo);
511 if (match) {
512 return SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]);
513 }
514 }
515 return this.name;
502 } 516 }
503 517
504 518
505 /** 519 /**
506 * Class for source location. A source location is a position within some 520 * Class for source location. A source location is a position within some
507 * source with the following properties: 521 * source with the following properties:
508 * script : script object for the source 522 * script : script object for the source
509 * line : source line number 523 * line : source line number
510 * column : source column within the line 524 * column : source column within the line
511 * position : position within the source 525 * position : position within the source
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 else throw e; 1080 else throw e;
1067 } 1081 }
1068 } 1082 }
1069 1083
1070 1084
1071 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); 1085 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]);
1072 1086
1073 // Boilerplate for exceptions for stack overflows. Used from 1087 // Boilerplate for exceptions for stack overflows. Used from
1074 // Top::StackOverflow(). 1088 // Top::StackOverflow().
1075 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1089 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« 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