OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 function ScriptLineCount() { | 536 function ScriptLineCount() { |
537 // Return number of source lines. | 537 // Return number of source lines. |
538 return this.line_ends.length; | 538 return this.line_ends.length; |
539 } | 539 } |
540 | 540 |
541 | 541 |
542 /** | 542 /** |
543 * If sourceURL comment is available and script starts at zero returns sourceURL | 543 * If sourceURL comment is available and script starts at zero returns sourceURL |
544 * comment contents. Otherwise, script name is returned. See | 544 * comment contents. Otherwise, script name is returned. See |
545 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt | 545 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt |
546 * for details on using //@ sourceURL comment to identify scritps that don't | 546 * and Source Map Revision 3 proposal for details on using //# sourceURL and |
547 * have name. | 547 * deprecated //@ sourceURL comment to identify scripts that don't have name. |
548 * | 548 * |
549 * @return {?string} script name if present, value for //@ sourceURL comment | 549 * @return {?string} script name if present, value for //# sourceURL or |
550 * otherwise. | 550 * deprecated //@ sourceURL comment otherwise. |
551 */ | 551 */ |
552 function ScriptNameOrSourceURL() { | 552 function ScriptNameOrSourceURL() { |
553 if (this.line_offset > 0 || this.column_offset > 0) { | 553 if (this.line_offset > 0 || this.column_offset > 0) { |
554 return this.name; | 554 return this.name; |
555 } | 555 } |
556 | 556 |
557 // The result is cached as on long scripts it takes noticable time to search | 557 // The result is cached as on long scripts it takes noticable time to search |
558 // for the sourceURL. | 558 // for the sourceURL. |
559 if (this.hasCachedNameOrSourceURL) { | 559 if (this.hasCachedNameOrSourceURL) { |
560 return this.cachedNameOrSourceURL; | 560 return this.cachedNameOrSourceURL; |
561 } | 561 } |
562 this.hasCachedNameOrSourceURL = true; | 562 this.hasCachedNameOrSourceURL = true; |
563 | 563 |
564 // TODO(608): the spaces in a regexp below had to be escaped as \040 | 564 // TODO(608): the spaces in a regexp below had to be escaped as \040 |
565 // because this file is being processed by js2c whose handling of spaces | 565 // because this file is being processed by js2c whose handling of spaces |
566 // in regexps is broken. Also, ['"] are excluded from allowed URLs to | 566 // in regexps is broken. Also, ['"] are excluded from allowed URLs to |
567 // avoid matches against sources that invoke evals with sourceURL. | 567 // avoid matches against sources that invoke evals with sourceURL. |
568 // A better solution would be to detect these special comments in | 568 // A better solution would be to detect these special comments in |
569 // the scanner/parser. | 569 // the scanner/parser. |
570 var source = ToString(this.source); | 570 var source = ToString(this.source); |
571 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); | 571 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); |
572 this.cachedNameOrSourceURL = this.name; | 572 this.cachedNameOrSourceURL = this.name; |
573 if (sourceUrlPos > 4) { | 573 if (sourceUrlPos > 4) { |
574 var sourceUrlPattern = | 574 var sourceUrlPattern = |
575 /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; | 575 /\/\/[#@][\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; |
576 // Don't reuse lastMatchInfo here, so we create a new array with room | 576 // Don't reuse lastMatchInfo here, so we create a new array with room |
577 // for four captures (array with length one longer than the index | 577 // for four captures (array with length one longer than the index |
578 // of the fourth capture, where the numbering is zero-based). | 578 // of the fourth capture, where the numbering is zero-based). |
579 var matchInfo = new InternalArray(CAPTURE(3) + 1); | 579 var matchInfo = new InternalArray(CAPTURE(3) + 1); |
580 var match = | 580 var match = |
581 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); | 581 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); |
582 if (match) { | 582 if (match) { |
583 this.cachedNameOrSourceURL = | 583 this.cachedNameOrSourceURL = |
584 %_SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); | 584 %_SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); |
585 } | 585 } |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 %SetOverflowedStackTrace(this, void 0); | 1325 %SetOverflowedStackTrace(this, void 0); |
1326 } | 1326 } |
1327 | 1327 |
1328 %DefineOrRedefineAccessorProperty( | 1328 %DefineOrRedefineAccessorProperty( |
1329 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1329 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1330 | 1330 |
1331 return boilerplate; | 1331 return boilerplate; |
1332 } | 1332 } |
1333 | 1333 |
1334 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1334 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |