| 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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 // Error implementation | 677 // Error implementation |
| 678 | 678 |
| 679 // Defines accessors for a property that is calculated the first time | 679 // Defines accessors for a property that is calculated the first time |
| 680 // the property is read. | 680 // the property is read. |
| 681 function DefineOneShotAccessor(obj, name, fun) { | 681 function DefineOneShotAccessor(obj, name, fun) { |
| 682 // Note that the accessors consistently operate on 'obj', not 'this'. | 682 // Note that the accessors consistently operate on 'obj', not 'this'. |
| 683 // Since the object may occur in someone else's prototype chain we | 683 // Since the object may occur in someone else's prototype chain we |
| 684 // can't rely on 'this' being the same as 'obj'. | 684 // can't rely on 'this' being the same as 'obj'. |
| 685 var hasBeenSet = false; | 685 var hasBeenSet = false; |
| 686 var value; | 686 var value; |
| 687 obj.__defineGetter__(name, function () { | 687 function getter() { |
| 688 if (hasBeenSet) { | 688 if (hasBeenSet) { |
| 689 return value; | 689 return value; |
| 690 } | 690 } |
| 691 hasBeenSet = true; | 691 hasBeenSet = true; |
| 692 value = fun(obj); | 692 value = fun(obj); |
| 693 return value; | 693 return value; |
| 694 }); | 694 } |
| 695 obj.__defineSetter__(name, function (v) { | 695 function setter(v) { |
| 696 hasBeenSet = true; | 696 hasBeenSet = true; |
| 697 value = v; | 697 value = v; |
| 698 }); | 698 } |
| 699 var desc = { get: getter, |
| 700 set: setter, |
| 701 enumerable: false, |
| 702 configurable: true }; |
| 703 desc = ToPropertyDescriptor(desc); |
| 704 DefineOwnProperty(obj, name, desc, true); |
| 699 } | 705 } |
| 700 | 706 |
| 701 function CallSite(receiver, fun, pos) { | 707 function CallSite(receiver, fun, pos) { |
| 702 this.receiver = receiver; | 708 this.receiver = receiver; |
| 703 this.fun = fun; | 709 this.fun = fun; |
| 704 this.pos = pos; | 710 this.pos = pos; |
| 705 } | 711 } |
| 706 | 712 |
| 707 CallSite.prototype.getThis = function () { | 713 CallSite.prototype.getThis = function () { |
| 708 return this.receiver; | 714 return this.receiver; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 } else { | 998 } else { |
| 993 %FunctionSetPrototype(f, new $Error()); | 999 %FunctionSetPrototype(f, new $Error()); |
| 994 } | 1000 } |
| 995 %FunctionSetInstanceClassName(f, 'Error'); | 1001 %FunctionSetInstanceClassName(f, 'Error'); |
| 996 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1002 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| 997 // The name property on the prototype of error objects is not | 1003 // The name property on the prototype of error objects is not |
| 998 // specified as being read-one and dont-delete. However, allowing | 1004 // specified as being read-one and dont-delete. However, allowing |
| 999 // overwriting allows leaks of error objects between script blocks | 1005 // overwriting allows leaks of error objects between script blocks |
| 1000 // in the same context in a browser setting. Therefore we fix the | 1006 // in the same context in a browser setting. Therefore we fix the |
| 1001 // name. | 1007 // name. |
| 1002 %SetProperty(f.prototype, "name", name, READ_ONLY | DONT_DELETE); | 1008 %SetProperty(f.prototype, "name", name, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1003 %SetCode(f, function(m) { | 1009 %SetCode(f, function(m) { |
| 1004 if (%_IsConstructCall()) { | 1010 if (%_IsConstructCall()) { |
| 1005 // Define all the expected properties directly on the error | 1011 // Define all the expected properties directly on the error |
| 1006 // object. This avoids going through getters and setters defined | 1012 // object. This avoids going through getters and setters defined |
| 1007 // on prototype objects. | 1013 // on prototype objects. |
| 1008 %IgnoreAttributesAndSetProperty(this, 'stack', void 0); | 1014 %IgnoreAttributesAndSetProperty(this, 'stack', void 0, DONT_ENUM); |
| 1009 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0); | 1015 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0, DONT_ENUM); |
| 1010 %IgnoreAttributesAndSetProperty(this, 'type', void 0); | 1016 %IgnoreAttributesAndSetProperty(this, 'type', void 0, DONT_ENUM); |
| 1011 if (m === kAddMessageAccessorsMarker) { | 1017 if (m === kAddMessageAccessorsMarker) { |
| 1012 // DefineOneShotAccessor always inserts a message property and | 1018 // DefineOneShotAccessor always inserts a message property and |
| 1013 // ignores setters. | 1019 // ignores setters. |
| 1014 DefineOneShotAccessor(this, 'message', function (obj) { | 1020 DefineOneShotAccessor(this, 'message', function (obj) { |
| 1015 return FormatMessage(%NewMessageObject(obj.type, obj.arguments)); | 1021 return FormatMessage(%NewMessageObject(obj.type, obj.arguments)); |
| 1016 }); | 1022 }); |
| 1017 } else if (!IS_UNDEFINED(m)) { | 1023 } else if (!IS_UNDEFINED(m)) { |
| 1018 %IgnoreAttributesAndSetProperty(this, 'message', ToString(m)); | 1024 %IgnoreAttributesAndSetProperty(this, |
| 1025 'message', |
| 1026 ToString(m), |
| 1027 DONT_ENUM); |
| 1019 } | 1028 } |
| 1020 captureStackTrace(this, f); | 1029 captureStackTrace(this, f); |
| 1021 } else { | 1030 } else { |
| 1022 return new f(m); | 1031 return new f(m); |
| 1023 } | 1032 } |
| 1024 }); | 1033 }); |
| 1025 } | 1034 } |
| 1026 | 1035 |
| 1027 function captureStackTrace(obj, cons_opt) { | 1036 function captureStackTrace(obj, cons_opt) { |
| 1028 var stackTraceLimit = $Error.stackTraceLimit; | 1037 var stackTraceLimit = $Error.stackTraceLimit; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1043 DefineError(function TypeError() { }); | 1052 DefineError(function TypeError() { }); |
| 1044 DefineError(function RangeError() { }); | 1053 DefineError(function RangeError() { }); |
| 1045 DefineError(function SyntaxError() { }); | 1054 DefineError(function SyntaxError() { }); |
| 1046 DefineError(function ReferenceError() { }); | 1055 DefineError(function ReferenceError() { }); |
| 1047 DefineError(function EvalError() { }); | 1056 DefineError(function EvalError() { }); |
| 1048 DefineError(function URIError() { }); | 1057 DefineError(function URIError() { }); |
| 1049 | 1058 |
| 1050 $Error.captureStackTrace = captureStackTrace; | 1059 $Error.captureStackTrace = captureStackTrace; |
| 1051 | 1060 |
| 1052 // Setup extra properties of the Error.prototype object. | 1061 // Setup extra properties of the Error.prototype object. |
| 1053 $Error.prototype.message = ''; | 1062 function setErrorMessage() { |
| 1063 var desc = {value: '', |
| 1064 enumerable: false, |
| 1065 configurable: true, |
| 1066 writable: true }; |
| 1067 DefineOwnProperty($Error.prototype, |
| 1068 'message', |
| 1069 ToPropertyDescriptor(desc), |
| 1070 true); |
| 1071 |
| 1072 } |
| 1073 |
| 1074 setErrorMessage(); |
| 1054 | 1075 |
| 1055 // Global list of error objects visited during errorToString. This is | 1076 // Global list of error objects visited during errorToString. This is |
| 1056 // used to detect cycles in error toString formatting. | 1077 // used to detect cycles in error toString formatting. |
| 1057 var visited_errors = new $Array(); | 1078 var visited_errors = new $Array(); |
| 1058 var cyclic_error_marker = new $Object(); | 1079 var cyclic_error_marker = new $Object(); |
| 1059 | 1080 |
| 1060 function errorToStringDetectCycle() { | 1081 function errorToStringDetectCycle() { |
| 1061 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; | 1082 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; |
| 1062 try { | 1083 try { |
| 1063 var type = this.type; | 1084 var type = this.type; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1092 else throw e; | 1113 else throw e; |
| 1093 } | 1114 } |
| 1094 } | 1115 } |
| 1095 | 1116 |
| 1096 | 1117 |
| 1097 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); | 1118 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); |
| 1098 | 1119 |
| 1099 // Boilerplate for exceptions for stack overflows. Used from | 1120 // Boilerplate for exceptions for stack overflows. Used from |
| 1100 // Isolate::StackOverflow(). | 1121 // Isolate::StackOverflow(). |
| 1101 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1122 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |