| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 | 28 |
| 29 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
| 30 // |
| 31 // Matches Script::Type from objects.h |
| 32 var TYPE_NATIVE = 0; |
| 33 var TYPE_EXTENSION = 1; |
| 34 var TYPE_NORMAL = 2; |
| 35 |
| 36 // Matches Script::CompilationType from objects.h |
| 37 var COMPILATION_TYPE_HOST = 0; |
| 38 var COMPILATION_TYPE_EVAL = 1; |
| 39 var COMPILATION_TYPE_JSON = 2; |
| 30 | 40 |
| 31 // Lazily initialized. | 41 // Lazily initialized. |
| 32 var kVowelSounds = 0; | 42 var kVowelSounds = 0; |
| 33 var kCapitalVowelSounds = 0; | 43 var kCapitalVowelSounds = 0; |
| 34 | 44 |
| 35 // If this object gets passed to an error constructor the error will | 45 // If this object gets passed to an error constructor the error will |
| 36 // get an accessor for .message that constructs a descriptive error | 46 // get an accessor for .message that constructs a descriptive error |
| 37 // message on access. | 47 // message on access. |
| 38 var kAddMessageAccessorsMarker = { }; | 48 var kAddMessageAccessorsMarker = { }; |
| 39 | 49 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 }; | 637 }; |
| 628 | 638 |
| 629 CallSite.prototype.isToplevel = function () { | 639 CallSite.prototype.isToplevel = function () { |
| 630 if (this.receiver == null) | 640 if (this.receiver == null) |
| 631 return true; | 641 return true; |
| 632 return IS_GLOBAL(this.receiver); | 642 return IS_GLOBAL(this.receiver); |
| 633 }; | 643 }; |
| 634 | 644 |
| 635 CallSite.prototype.isEval = function () { | 645 CallSite.prototype.isEval = function () { |
| 636 var script = %FunctionGetScript(this.fun); | 646 var script = %FunctionGetScript(this.fun); |
| 637 return script && script.compilation_type == 1; | 647 return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
| 638 }; | 648 }; |
| 639 | 649 |
| 640 CallSite.prototype.getEvalOrigin = function () { | 650 CallSite.prototype.getEvalOrigin = function () { |
| 641 var script = %FunctionGetScript(this.fun); | 651 var script = %FunctionGetScript(this.fun); |
| 642 return FormatEvalOrigin(script); | 652 return FormatEvalOrigin(script); |
| 643 }; | 653 }; |
| 644 | 654 |
| 645 CallSite.prototype.getFunction = function () { | 655 CallSite.prototype.getFunction = function () { |
| 646 return this.fun; | 656 return this.fun; |
| 647 }; | 657 }; |
| 648 | 658 |
| 649 CallSite.prototype.getFunctionName = function () { | 659 CallSite.prototype.getFunctionName = function () { |
| 650 // See if the function knows its own name | 660 // See if the function knows its own name |
| 651 var name = this.fun.name; | 661 var name = this.fun.name; |
| 652 if (name) { | 662 if (name) { |
| 653 return name; | 663 return name; |
| 654 } else { | 664 } else { |
| 655 return %FunctionGetInferredName(this.fun); | 665 return %FunctionGetInferredName(this.fun); |
| 656 } | 666 } |
| 657 // Maybe this is an evaluation? | 667 // Maybe this is an evaluation? |
| 658 var script = %FunctionGetScript(this.fun); | 668 var script = %FunctionGetScript(this.fun); |
| 659 if (script && script.compilation_type == 1) | 669 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) |
| 660 return "eval"; | 670 return "eval"; |
| 661 return null; | 671 return null; |
| 662 }; | 672 }; |
| 663 | 673 |
| 664 CallSite.prototype.getMethodName = function () { | 674 CallSite.prototype.getMethodName = function () { |
| 665 // See if we can find a unique property on the receiver that holds | 675 // See if we can find a unique property on the receiver that holds |
| 666 // this function. | 676 // this function. |
| 667 var ownName = this.fun.name; | 677 var ownName = this.fun.name; |
| 668 if (ownName && this.receiver && this.receiver[ownName] === this.fun) | 678 if (ownName && this.receiver && this.receiver[ownName] === this.fun) |
| 669 // To handle DontEnum properties we guess that the method has | 679 // To handle DontEnum properties we guess that the method has |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 var script = %FunctionGetScript(this.fun); | 715 var script = %FunctionGetScript(this.fun); |
| 706 var location = null; | 716 var location = null; |
| 707 if (script) { | 717 if (script) { |
| 708 location = script.locationFromPosition(this.pos, true); | 718 location = script.locationFromPosition(this.pos, true); |
| 709 } | 719 } |
| 710 return location ? location.column + 1: null; | 720 return location ? location.column + 1: null; |
| 711 }; | 721 }; |
| 712 | 722 |
| 713 CallSite.prototype.isNative = function () { | 723 CallSite.prototype.isNative = function () { |
| 714 var script = %FunctionGetScript(this.fun); | 724 var script = %FunctionGetScript(this.fun); |
| 715 return script ? (script.type == 0) : false; | 725 return script ? (script.type == TYPE_NATIVE) : false; |
| 716 }; | 726 }; |
| 717 | 727 |
| 718 CallSite.prototype.getPosition = function () { | 728 CallSite.prototype.getPosition = function () { |
| 719 return this.pos; | 729 return this.pos; |
| 720 }; | 730 }; |
| 721 | 731 |
| 722 CallSite.prototype.isConstructor = function () { | 732 CallSite.prototype.isConstructor = function () { |
| 723 var constructor = this.receiver ? this.receiver.constructor : null; | 733 var constructor = this.receiver ? this.receiver.constructor : null; |
| 724 if (!constructor) | 734 if (!constructor) |
| 725 return false; | 735 return false; |
| 726 return this.fun === constructor; | 736 return this.fun === constructor; |
| 727 }; | 737 }; |
| 728 | 738 |
| 729 function FormatEvalOrigin(script) { | 739 function FormatEvalOrigin(script) { |
| 730 var eval_origin = ""; | 740 var eval_origin = ""; |
| 731 if (script.eval_from_function_name) { | 741 if (script.eval_from_function_name) { |
| 732 eval_origin += script.eval_from_function_name; | 742 eval_origin += script.eval_from_function_name; |
| 733 } else { | 743 } else { |
| 734 eval_origin += "<anonymous>"; | 744 eval_origin += "<anonymous>"; |
| 735 } | 745 } |
| 736 | 746 |
| 737 var eval_from_script = script.eval_from_script; | 747 var eval_from_script = script.eval_from_script; |
| 738 if (eval_from_script) { | 748 if (eval_from_script) { |
| 739 if (eval_from_script.compilation_type == 1) { | 749 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { |
| 740 // eval script originated from another eval. | 750 // eval script originated from another eval. |
| 741 eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script) + ")"; | 751 eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script) + ")"; |
| 742 } else { | 752 } else { |
| 743 // eval script originated from "real" scource. | 753 // eval script originated from "real" scource. |
| 744 if (eval_from_script.name) { | 754 if (eval_from_script.name) { |
| 745 eval_origin += " (" + eval_from_script.name; | 755 eval_origin += " (" + eval_from_script.name; |
| 746 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); | 756 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); |
| 747 if (location) { | 757 if (location) { |
| 748 eval_origin += ":" + (location.line + 1); | 758 eval_origin += ":" + (location.line + 1); |
| 749 eval_origin += ":" + (location.column + 1); | 759 eval_origin += ":" + (location.column + 1); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 941 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
| 932 } | 942 } |
| 933 var message = this.message; | 943 var message = this.message; |
| 934 return this.name + (message ? (": " + message) : ""); | 944 return this.name + (message ? (": " + message) : ""); |
| 935 }, DONT_ENUM); | 945 }, DONT_ENUM); |
| 936 | 946 |
| 937 | 947 |
| 938 // Boilerplate for exceptions for stack overflows. Used from | 948 // Boilerplate for exceptions for stack overflows. Used from |
| 939 // Top::StackOverflow(). | 949 // Top::StackOverflow(). |
| 940 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 950 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |