OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
6 | 6 |
7 var kMessages = { | 7 var kMessages = { |
8 // Error | 8 // Error |
9 cyclic_proto: ["Cyclic __proto__ value"], | 9 cyclic_proto: ["Cyclic __proto__ value"], |
10 code_gen_from_strings: ["%0"], | 10 code_gen_from_strings: ["%0"], |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 * and Source Map Revision 3 proposal for details on using //# sourceURL and | 548 * and Source Map Revision 3 proposal for details on using //# sourceURL and |
549 * deprecated //@ sourceURL comment to identify scripts that don't have name. | 549 * deprecated //@ sourceURL comment to identify scripts that don't have name. |
550 * | 550 * |
551 * @return {?string} script name if present, value for //# sourceURL or | 551 * @return {?string} script name if present, value for //# sourceURL or |
552 * deprecated //@ sourceURL comment otherwise. | 552 * deprecated //@ sourceURL comment otherwise. |
553 */ | 553 */ |
554 function ScriptNameOrSourceURL() { | 554 function ScriptNameOrSourceURL() { |
555 if (this.line_offset > 0 || this.column_offset > 0) { | 555 if (this.line_offset > 0 || this.column_offset > 0) { |
556 return this.name; | 556 return this.name; |
557 } | 557 } |
558 | 558 return this.source_url; |
559 // The result is cached as on long scripts it takes noticable time to search | |
560 // for the sourceURL. | |
561 if (this.hasCachedNameOrSourceURL) { | |
562 return this.cachedNameOrSourceURL; | |
563 } | |
564 this.hasCachedNameOrSourceURL = true; | |
565 | |
566 // TODO(608): the spaces in a regexp below had to be escaped as \040 | |
567 // because this file is being processed by js2c whose handling of spaces | |
568 // in regexps is broken. Also, ['"] are excluded from allowed URLs to | |
569 // avoid matches against sources that invoke evals with sourceURL. | |
570 // A better solution would be to detect these special comments in | |
571 // the scanner/parser. | |
572 var source = ToString(this.source); | |
573 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); | |
574 this.cachedNameOrSourceURL = this.name; | |
575 if (sourceUrlPos > 4) { | |
576 var sourceUrlPattern = | |
577 /\/\/[#@][\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; | |
578 // Don't reuse lastMatchInfo here, so we create a new array with room | |
579 // for four captures (array with length one longer than the index | |
580 // of the fourth capture, where the numbering is zero-based). | |
581 var matchInfo = new InternalArray(CAPTURE(3) + 1); | |
582 var match = | |
583 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); | |
584 if (match) { | |
585 this.cachedNameOrSourceURL = | |
586 %_SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); | |
587 } | |
588 } | |
589 return this.cachedNameOrSourceURL; | |
590 } | 559 } |
591 | 560 |
592 | 561 |
593 SetUpLockedPrototype(Script, | 562 SetUpLockedPrototype(Script, |
594 $Array("source", "name", "line_ends", "line_offset", "column_offset", | 563 $Array("source", "name", "source_url", "line_ends", "line_offset", "column_off
set"), |
595 "cachedNameOrSourceURL", "hasCachedNameOrSourceURL" ), | |
596 $Array( | 564 $Array( |
597 "lineFromPosition", ScriptLineFromPosition, | 565 "lineFromPosition", ScriptLineFromPosition, |
598 "locationFromPosition", ScriptLocationFromPosition, | 566 "locationFromPosition", ScriptLocationFromPosition, |
599 "locationFromLine", ScriptLocationFromLine, | 567 "locationFromLine", ScriptLocationFromLine, |
600 "sourceSlice", ScriptSourceSlice, | 568 "sourceSlice", ScriptSourceSlice, |
601 "sourceLine", ScriptSourceLine, | 569 "sourceLine", ScriptSourceLine, |
602 "lineCount", ScriptLineCount, | 570 "lineCount", ScriptLineCount, |
603 "nameOrSourceURL", ScriptNameOrSourceURL | 571 "nameOrSourceURL", ScriptNameOrSourceURL |
604 ) | 572 ) |
605 ); | 573 ); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 return result; | 1302 return result; |
1335 }; | 1303 }; |
1336 | 1304 |
1337 %DefineOrRedefineAccessorProperty( | 1305 %DefineOrRedefineAccessorProperty( |
1338 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1306 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1339 | 1307 |
1340 return boilerplate; | 1308 return boilerplate; |
1341 } | 1309 } |
1342 | 1310 |
1343 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1311 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |