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