| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 function MakeGenericError(constructor, type, args) { | 278 function MakeGenericError(constructor, type, args) { |
| 279 if (IS_UNDEFINED(args)) args = []; | 279 if (IS_UNDEFINED(args)) args = []; |
| 280 return new constructor(FormatMessage(type, args)); | 280 return new constructor(FormatMessage(type, args)); |
| 281 } | 281 } |
| 282 | 282 |
| 283 | 283 |
| 284 /** | 284 /** |
| 285 * Set up the Script function and constructor. | 285 * Set up the Script function and constructor. |
| 286 */ | 286 */ |
| 287 %FunctionSetInstanceClassName(Script, 'Script'); | 287 %FunctionSetInstanceClassName(Script, 'Script'); |
| 288 %AddProperty(Script.prototype, 'constructor', Script, | 288 %AddNamedProperty(Script.prototype, 'constructor', Script, |
| 289 DONT_ENUM | DONT_DELETE | READ_ONLY); | 289 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 290 %SetCode(Script, function(x) { | 290 %SetCode(Script, function(x) { |
| 291 // Script objects can only be created by the VM. | 291 // Script objects can only be created by the VM. |
| 292 throw new $Error("Not supported"); | 292 throw new $Error("Not supported"); |
| 293 }); | 293 }); |
| 294 | 294 |
| 295 | 295 |
| 296 // Helper functions; called from the runtime system. | 296 // Helper functions; called from the runtime system. |
| 297 function FormatMessage(type, args) { | 297 function FormatMessage(type, args) { |
| 298 var format = kMessages[type]; | 298 var format = kMessages[type]; |
| 299 if (!format) return "<unknown message " + type + ">"; | 299 if (!format) return "<unknown message " + type + ">"; |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 // Define special error type constructors. | 1152 // Define special error type constructors. |
| 1153 | 1153 |
| 1154 var DefineError = function(f) { | 1154 var DefineError = function(f) { |
| 1155 // Store the error function in both the global object | 1155 // Store the error function in both the global object |
| 1156 // and the runtime object. The function is fetched | 1156 // and the runtime object. The function is fetched |
| 1157 // from the runtime object when throwing errors from | 1157 // from the runtime object when throwing errors from |
| 1158 // within the runtime system to avoid strange side | 1158 // within the runtime system to avoid strange side |
| 1159 // effects when overwriting the error functions from | 1159 // effects when overwriting the error functions from |
| 1160 // user code. | 1160 // user code. |
| 1161 var name = f.name; | 1161 var name = f.name; |
| 1162 %AddProperty(global, name, f, DONT_ENUM); | 1162 %AddNamedProperty(global, name, f, DONT_ENUM); |
| 1163 %AddProperty(builtins, '$' + name, f, | 1163 %AddNamedProperty(builtins, '$' + name, f, |
| 1164 DONT_ENUM | DONT_DELETE | READ_ONLY); | 1164 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1165 // Configure the error function. | 1165 // Configure the error function. |
| 1166 if (name == 'Error') { | 1166 if (name == 'Error') { |
| 1167 // The prototype of the Error object must itself be an error. | 1167 // The prototype of the Error object must itself be an error. |
| 1168 // However, it can't be an instance of the Error object because | 1168 // However, it can't be an instance of the Error object because |
| 1169 // it hasn't been properly configured yet. Instead we create a | 1169 // it hasn't been properly configured yet. Instead we create a |
| 1170 // special not-a-true-error-but-close-enough object. | 1170 // special not-a-true-error-but-close-enough object. |
| 1171 var ErrorPrototype = function() {}; | 1171 var ErrorPrototype = function() {}; |
| 1172 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); | 1172 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); |
| 1173 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); | 1173 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
| 1174 %FunctionSetPrototype(f, new ErrorPrototype()); | 1174 %FunctionSetPrototype(f, new ErrorPrototype()); |
| 1175 } else { | 1175 } else { |
| 1176 %FunctionSetPrototype(f, new $Error()); | 1176 %FunctionSetPrototype(f, new $Error()); |
| 1177 } | 1177 } |
| 1178 %FunctionSetInstanceClassName(f, 'Error'); | 1178 %FunctionSetInstanceClassName(f, 'Error'); |
| 1179 %AddProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1179 %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| 1180 %AddProperty(f.prototype, "name", name, DONT_ENUM); | 1180 %AddNamedProperty(f.prototype, "name", name, DONT_ENUM); |
| 1181 %SetCode(f, function(m) { | 1181 %SetCode(f, function(m) { |
| 1182 if (%_IsConstructCall()) { | 1182 if (%_IsConstructCall()) { |
| 1183 // Define all the expected properties directly on the error | 1183 // Define all the expected properties directly on the error |
| 1184 // object. This avoids going through getters and setters defined | 1184 // object. This avoids going through getters and setters defined |
| 1185 // on prototype objects. | 1185 // on prototype objects. |
| 1186 %AddProperty(this, 'stack', UNDEFINED, DONT_ENUM); | 1186 %AddNamedProperty(this, 'stack', UNDEFINED, DONT_ENUM); |
| 1187 if (!IS_UNDEFINED(m)) { | 1187 if (!IS_UNDEFINED(m)) { |
| 1188 %AddProperty(this, 'message', ToString(m), DONT_ENUM); | 1188 %AddNamedProperty(this, 'message', ToString(m), DONT_ENUM); |
| 1189 } | 1189 } |
| 1190 try { captureStackTrace(this, f); } catch (e) { } | 1190 try { captureStackTrace(this, f); } catch (e) { } |
| 1191 } else { | 1191 } else { |
| 1192 return new f(m); | 1192 return new f(m); |
| 1193 } | 1193 } |
| 1194 }); | 1194 }); |
| 1195 %SetNativeFlag(f); | 1195 %SetNativeFlag(f); |
| 1196 }; | 1196 }; |
| 1197 | 1197 |
| 1198 DefineError(function Error() { }); | 1198 DefineError(function Error() { }); |
| 1199 DefineError(function TypeError() { }); | 1199 DefineError(function TypeError() { }); |
| 1200 DefineError(function RangeError() { }); | 1200 DefineError(function RangeError() { }); |
| 1201 DefineError(function SyntaxError() { }); | 1201 DefineError(function SyntaxError() { }); |
| 1202 DefineError(function ReferenceError() { }); | 1202 DefineError(function ReferenceError() { }); |
| 1203 DefineError(function EvalError() { }); | 1203 DefineError(function EvalError() { }); |
| 1204 DefineError(function URIError() { }); | 1204 DefineError(function URIError() { }); |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 SetUpError(); | 1207 SetUpError(); |
| 1208 | 1208 |
| 1209 $Error.captureStackTrace = captureStackTrace; | 1209 $Error.captureStackTrace = captureStackTrace; |
| 1210 | 1210 |
| 1211 %AddProperty($Error.prototype, 'message', '', DONT_ENUM); | 1211 %AddNamedProperty($Error.prototype, 'message', '', DONT_ENUM); |
| 1212 | 1212 |
| 1213 // Global list of error objects visited during ErrorToString. This is | 1213 // Global list of error objects visited during ErrorToString. This is |
| 1214 // used to detect cycles in error toString formatting. | 1214 // used to detect cycles in error toString formatting. |
| 1215 var visited_errors = new InternalArray(); | 1215 var visited_errors = new InternalArray(); |
| 1216 var cyclic_error_marker = new $Object(); | 1216 var cyclic_error_marker = new $Object(); |
| 1217 | 1217 |
| 1218 function GetPropertyWithoutInvokingMonkeyGetters(error, name) { | 1218 function GetPropertyWithoutInvokingMonkeyGetters(error, name) { |
| 1219 var current = error; | 1219 var current = error; |
| 1220 // Climb the prototype chain until we find the holder. | 1220 // Climb the prototype chain until we find the holder. |
| 1221 while (current && !%HasOwnProperty(current, name)) { | 1221 while (current && !%HasOwnProperty(current, name)) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 function SetUpStackOverflowBoilerplate() { | 1280 function SetUpStackOverflowBoilerplate() { |
| 1281 var boilerplate = MakeRangeError('stack_overflow', []); | 1281 var boilerplate = MakeRangeError('stack_overflow', []); |
| 1282 | 1282 |
| 1283 %DefineAccessorPropertyUnchecked( | 1283 %DefineAccessorPropertyUnchecked( |
| 1284 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1284 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
| 1285 | 1285 |
| 1286 return boilerplate; | 1286 return boilerplate; |
| 1287 } | 1287 } |
| 1288 | 1288 |
| 1289 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1289 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |