| 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 if (this.source_url) { |
| 559 // The result is cached as on long scripts it takes noticable time to search | 559 return this.source_url; |
| 560 // for the sourceURL. | |
| 561 if (this.hasCachedNameOrSourceURL) { | |
| 562 return this.cachedNameOrSourceURL; | |
| 563 } | 560 } |
| 564 this.hasCachedNameOrSourceURL = true; | 561 return this.name; |
| 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 } | 562 } |
| 591 | 563 |
| 592 | 564 |
| 593 SetUpLockedPrototype(Script, | 565 SetUpLockedPrototype(Script, |
| 594 $Array("source", "name", "line_ends", "line_offset", "column_offset", | 566 $Array("source", "name", "source_url", "source_mapping_url", "line_ends", "lin
e_offset", "column_offset"), |
| 595 "cachedNameOrSourceURL", "hasCachedNameOrSourceURL" ), | |
| 596 $Array( | 567 $Array( |
| 597 "lineFromPosition", ScriptLineFromPosition, | 568 "lineFromPosition", ScriptLineFromPosition, |
| 598 "locationFromPosition", ScriptLocationFromPosition, | 569 "locationFromPosition", ScriptLocationFromPosition, |
| 599 "locationFromLine", ScriptLocationFromLine, | 570 "locationFromLine", ScriptLocationFromLine, |
| 600 "sourceSlice", ScriptSourceSlice, | 571 "sourceSlice", ScriptSourceSlice, |
| 601 "sourceLine", ScriptSourceLine, | 572 "sourceLine", ScriptSourceLine, |
| 602 "lineCount", ScriptLineCount, | 573 "lineCount", ScriptLineCount, |
| 603 "nameOrSourceURL", ScriptNameOrSourceURL | 574 "nameOrSourceURL", ScriptNameOrSourceURL |
| 604 ) | 575 ) |
| 605 ); | 576 ); |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 return result; | 1305 return result; |
| 1335 }; | 1306 }; |
| 1336 | 1307 |
| 1337 %DefineOrRedefineAccessorProperty( | 1308 %DefineOrRedefineAccessorProperty( |
| 1338 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1309 boilerplate, 'stack', getter, setter, DONT_ENUM); |
| 1339 | 1310 |
| 1340 return boilerplate; | 1311 return boilerplate; |
| 1341 } | 1312 } |
| 1342 | 1313 |
| 1343 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1314 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |