| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 * for details on using //@ sourceURL comment to identify scritps that don't | 526 * for details on using //@ sourceURL comment to identify scritps that don't |
| 527 * have name. | 527 * have name. |
| 528 * | 528 * |
| 529 * @return {?string} script name if present, value for //@ sourceURL comment | 529 * @return {?string} script name if present, value for //@ sourceURL comment |
| 530 * otherwise. | 530 * otherwise. |
| 531 */ | 531 */ |
| 532 function ScriptNameOrSourceURL() { | 532 function ScriptNameOrSourceURL() { |
| 533 if (this.name) { | 533 if (this.name) { |
| 534 return this.name; | 534 return this.name; |
| 535 } | 535 } |
| 536 |
| 537 // The result is cached as on long scripts it takes noticable time to search |
| 538 // for the sourceURL. |
| 539 if (this.hasCachedNameOrSourceURL) |
| 540 return this.cachedNameOrSourceURL; |
| 541 this.hasCachedNameOrSourceURL = true; |
| 542 |
| 536 // TODO(608): the spaces in a regexp below had to be escaped as \040 | 543 // TODO(608): the spaces in a regexp below had to be escaped as \040 |
| 537 // because this file is being processed by js2c whose handling of spaces | 544 // because this file is being processed by js2c whose handling of spaces |
| 538 // in regexps is broken. Also, ['"] are excluded from allowed URLs to | 545 // in regexps is broken. Also, ['"] are excluded from allowed URLs to |
| 539 // avoid matches against sources that invoke evals with sourceURL. | 546 // avoid matches against sources that invoke evals with sourceURL. |
| 540 // A better solution would be to detect these special comments in | 547 // A better solution would be to detect these special comments in |
| 541 // the scanner/parser. | 548 // the scanner/parser. |
| 542 var source = ToString(this.source); | 549 var source = ToString(this.source); |
| 543 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); | 550 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); |
| 551 this.cachedNameOrSourceURL = this.name; |
| 544 if (sourceUrlPos > 4) { | 552 if (sourceUrlPos > 4) { |
| 545 var sourceUrlPattern = | 553 var sourceUrlPattern = |
| 546 /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; | 554 /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; |
| 547 // Don't reuse lastMatchInfo here, so we create a new array with room | 555 // Don't reuse lastMatchInfo here, so we create a new array with room |
| 548 // for four captures (array with length one longer than the index | 556 // for four captures (array with length one longer than the index |
| 549 // of the fourth capture, where the numbering is zero-based). | 557 // of the fourth capture, where the numbering is zero-based). |
| 550 var matchInfo = new InternalArray(CAPTURE(3) + 1); | 558 var matchInfo = new InternalArray(CAPTURE(3) + 1); |
| 551 var match = | 559 var match = |
| 552 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); | 560 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); |
| 553 if (match) { | 561 if (match) { |
| 554 return SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); | 562 this.cachedNameOrSourceURL = |
| 563 SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); |
| 555 } | 564 } |
| 556 } | 565 } |
| 557 return this.name; | 566 return this.cachedNameOrSourceURL; |
| 558 } | 567 } |
| 559 | 568 |
| 560 | 569 |
| 561 SetUpLockedPrototype(Script, | 570 SetUpLockedPrototype(Script, |
| 562 $Array("source", "name", "line_ends", "line_offset", "column_offset"), | 571 $Array("source", "name", "line_ends", "line_offset", "column_offset", |
| 572 "cachedNameOrSourceURL", "hasCachedNameOrSourceURL" ), |
| 563 $Array( | 573 $Array( |
| 564 "lineFromPosition", ScriptLineFromPosition, | 574 "lineFromPosition", ScriptLineFromPosition, |
| 565 "locationFromPosition", ScriptLocationFromPosition, | 575 "locationFromPosition", ScriptLocationFromPosition, |
| 566 "locationFromLine", ScriptLocationFromLine, | 576 "locationFromLine", ScriptLocationFromLine, |
| 567 "sourceSlice", ScriptSourceSlice, | 577 "sourceSlice", ScriptSourceSlice, |
| 568 "sourceLine", ScriptSourceLine, | 578 "sourceLine", ScriptSourceLine, |
| 569 "lineCount", ScriptLineCount, | 579 "lineCount", ScriptLineCount, |
| 570 "nameOrSourceURL", ScriptNameOrSourceURL | 580 "nameOrSourceURL", ScriptNameOrSourceURL |
| 571 ) | 581 ) |
| 572 ); | 582 ); |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 throw e; | 1216 throw e; |
| 1207 } | 1217 } |
| 1208 } | 1218 } |
| 1209 | 1219 |
| 1210 | 1220 |
| 1211 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1221 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
| 1212 | 1222 |
| 1213 // Boilerplate for exceptions for stack overflows. Used from | 1223 // Boilerplate for exceptions for stack overflows. Used from |
| 1214 // Isolate::StackOverflow(). | 1224 // Isolate::StackOverflow(). |
| 1215 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1225 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |