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 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 e.type = type; | 156 e.type = type; |
157 e.arguments = args; | 157 e.arguments = args; |
158 return e; | 158 return e; |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 /** | 162 /** |
163 * Setup the Script function and constructor. | 163 * Setup the Script function and constructor. |
164 */ | 164 */ |
165 %FunctionSetInstanceClassName(Script, 'Script'); | 165 %FunctionSetInstanceClassName(Script, 'Script'); |
166 %AddProperty(Script.prototype, 'constructor', Script, DONT_ENUM); | 166 %SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); |
167 %SetCode(Script, function(x) { | 167 %SetCode(Script, function(x) { |
168 // Script objects can only be created by the VM. | 168 // Script objects can only be created by the VM. |
169 throw new $Error("Not supported"); | 169 throw new $Error("Not supported"); |
170 }); | 170 }); |
171 | 171 |
172 | 172 |
173 // Helper functions; called from the runtime system. | 173 // Helper functions; called from the runtime system. |
174 function FormatMessage(message) { | 174 function FormatMessage(message) { |
175 var format = kMessages[message.type]; | 175 var format = kMessages[message.type]; |
176 if (!format) return "<unknown message " + message.type + ">"; | 176 if (!format) return "<unknown message " + message.type + ">"; |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 // Error implementation | 626 // Error implementation |
627 | 627 |
628 function DefineError(f) { | 628 function DefineError(f) { |
629 // Store the error function in both the global object | 629 // Store the error function in both the global object |
630 // and the runtime object. The function is fetched | 630 // and the runtime object. The function is fetched |
631 // from the runtime object when throwing errors from | 631 // from the runtime object when throwing errors from |
632 // within the runtime system to avoid strange side | 632 // within the runtime system to avoid strange side |
633 // effects when overwriting the error functions from | 633 // effects when overwriting the error functions from |
634 // user code. | 634 // user code. |
635 var name = f.name; | 635 var name = f.name; |
636 %AddProperty(global, name, f, DONT_ENUM); | 636 %SetProperty(global, name, f, DONT_ENUM); |
637 this['$' + name] = f; | 637 this['$' + name] = f; |
638 // Configure the error function. | 638 // Configure the error function. |
639 // prototype of 'Error' must be as default: new Object(). | 639 // prototype of 'Error' must be as default: new Object(). |
640 if (name != 'Error') %FunctionSetPrototype(f, new $Error()); | 640 if (name != 'Error') %FunctionSetPrototype(f, new $Error()); |
641 %FunctionSetInstanceClassName(f, 'Error'); | 641 %FunctionSetInstanceClassName(f, 'Error'); |
642 f.prototype.name = name; | 642 f.prototype.name = name; |
643 f.prototype.constructor = f; | 643 f.prototype.constructor = f; |
644 %SetCode(f, function(m) { | 644 %SetCode(f, function(m) { |
645 if (%IsConstructCall()) { | 645 if (%IsConstructCall()) { |
646 if (!IS_UNDEFINED(m)) this.message = ToString(m); | 646 if (!IS_UNDEFINED(m)) this.message = ToString(m); |
647 } else { | 647 } else { |
648 return new f(m); | 648 return new f(m); |
649 } | 649 } |
650 }); | 650 }); |
651 } | 651 } |
652 | 652 |
653 $Math.__proto__ = global.Object.prototype; | 653 $Math.__proto__ = global.Object.prototype; |
654 | 654 |
655 DefineError(function Error() { }); | 655 DefineError(function Error() { }); |
656 DefineError(function TypeError() { }); | 656 DefineError(function TypeError() { }); |
657 DefineError(function RangeError() { }); | 657 DefineError(function RangeError() { }); |
658 DefineError(function SyntaxError() { }); | 658 DefineError(function SyntaxError() { }); |
659 DefineError(function ReferenceError() { }); | 659 DefineError(function ReferenceError() { }); |
660 DefineError(function EvalError() { }); | 660 DefineError(function EvalError() { }); |
661 DefineError(function URIError() { }); | 661 DefineError(function URIError() { }); |
662 | 662 |
663 // Setup extra properties of the Error.prototype object. | 663 // Setup extra properties of the Error.prototype object. |
664 $Error.prototype.message = ''; | 664 $Error.prototype.message = ''; |
665 | 665 |
666 %AddProperty($Error.prototype, 'toString', function toString() { | 666 %SetProperty($Error.prototype, 'toString', function toString() { |
667 var type = this.type; | 667 var type = this.type; |
668 if (type && !this.hasOwnProperty("message")) { | 668 if (type && !this.hasOwnProperty("message")) { |
669 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 669 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
670 } | 670 } |
671 var message = this.message; | 671 var message = this.message; |
672 return this.name + (message ? (": " + message) : ""); | 672 return this.name + (message ? (": " + message) : ""); |
673 }, DONT_ENUM); | 673 }, DONT_ENUM); |
674 | 674 |
675 | 675 |
676 // Boilerplate for exceptions for stack overflows. Used from | 676 // Boilerplate for exceptions for stack overflows. Used from |
677 // Top::StackOverflow(). | 677 // Top::StackOverflow(). |
678 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 678 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |