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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 * and Source Map Revision 3 proposal for details on using //# sourceURL and | 553 * and Source Map Revision 3 proposal for details on using //# sourceURL and |
554 * deprecated //@ sourceURL comment to identify scripts that don't have name. | 554 * deprecated //@ sourceURL comment to identify scripts that don't have name. |
555 * | 555 * |
556 * @return {?string} script name if present, value for //# sourceURL or | 556 * @return {?string} script name if present, value for //# sourceURL or |
557 * deprecated //@ sourceURL comment otherwise. | 557 * deprecated //@ sourceURL comment otherwise. |
558 */ | 558 */ |
559 function ScriptNameOrSourceURL() { | 559 function ScriptNameOrSourceURL() { |
560 if (this.line_offset > 0 || this.column_offset > 0) { | 560 if (this.line_offset > 0 || this.column_offset > 0) { |
561 return this.name; | 561 return this.name; |
562 } | 562 } |
563 | 563 if (this.source_url) { |
564 // The result is cached as on long scripts it takes noticable time to search | 564 return this.source_url; |
565 // for the sourceURL. | |
566 if (this.hasCachedNameOrSourceURL) { | |
567 return this.cachedNameOrSourceURL; | |
568 } | 565 } |
569 this.hasCachedNameOrSourceURL = true; | 566 return this.name; |
570 | |
571 // TODO(608): the spaces in a regexp below had to be escaped as \040 | |
572 // because this file is being processed by js2c whose handling of spaces | |
573 // in regexps is broken. Also, ['"] are excluded from allowed URLs to | |
574 // avoid matches against sources that invoke evals with sourceURL. | |
575 // A better solution would be to detect these special comments in | |
576 // the scanner/parser. | |
577 var source = ToString(this.source); | |
578 var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); | |
579 this.cachedNameOrSourceURL = this.name; | |
580 if (sourceUrlPos > 4) { | |
581 var sourceUrlPattern = | |
582 /\/\/[#@][\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; | |
583 // Don't reuse lastMatchInfo here, so we create a new array with room | |
584 // for four captures (array with length one longer than the index | |
585 // of the fourth capture, where the numbering is zero-based). | |
586 var matchInfo = new InternalArray(CAPTURE(3) + 1); | |
587 var match = | |
588 %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); | |
589 if (match) { | |
590 this.cachedNameOrSourceURL = | |
591 %_SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); | |
592 } | |
593 } | |
594 return this.cachedNameOrSourceURL; | |
595 } | 567 } |
596 | 568 |
597 | 569 |
598 SetUpLockedPrototype(Script, | 570 SetUpLockedPrototype(Script, |
599 $Array("source", "name", "line_ends", "line_offset", "column_offset", | 571 $Array("source", "name", "source_url", "source_mapping_url", "line_ends", |
600 "cachedNameOrSourceURL", "hasCachedNameOrSourceURL" ), | 572 "line_offset", "column_offset"), |
601 $Array( | 573 $Array( |
602 "lineFromPosition", ScriptLineFromPosition, | 574 "lineFromPosition", ScriptLineFromPosition, |
603 "locationFromPosition", ScriptLocationFromPosition, | 575 "locationFromPosition", ScriptLocationFromPosition, |
604 "locationFromLine", ScriptLocationFromLine, | 576 "locationFromLine", ScriptLocationFromLine, |
605 "sourceSlice", ScriptSourceSlice, | 577 "sourceSlice", ScriptSourceSlice, |
606 "sourceLine", ScriptSourceLine, | 578 "sourceLine", ScriptSourceLine, |
607 "lineCount", ScriptLineCount, | 579 "lineCount", ScriptLineCount, |
608 "nameOrSourceURL", ScriptNameOrSourceURL | 580 "nameOrSourceURL", ScriptNameOrSourceURL |
609 ) | 581 ) |
610 ); | 582 ); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 return result; | 1311 return result; |
1340 }; | 1312 }; |
1341 | 1313 |
1342 %DefineAccessorPropertyUnchecked( | 1314 %DefineAccessorPropertyUnchecked( |
1343 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1315 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1344 | 1316 |
1345 return boilerplate; | 1317 return boilerplate; |
1346 } | 1318 } |
1347 | 1319 |
1348 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1320 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |