OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 invalid_typed_array_length: ["Invalid typed array length"], | 122 invalid_typed_array_length: ["Invalid typed array length"], |
123 invalid_typed_array_alignment: ["%0", " of ", "%1", " should be a multiple of
", "%2"], | 123 invalid_typed_array_alignment: ["%0", " of ", "%1", " should be a multiple of
", "%2"], |
124 typed_array_set_source_too_large: | 124 typed_array_set_source_too_large: |
125 ["Source is too large"], | 125 ["Source is too large"], |
126 typed_array_set_negative_offset: | 126 typed_array_set_negative_offset: |
127 ["Start offset is negative"], | 127 ["Start offset is negative"], |
128 invalid_data_view_offset: ["Start offset is outside the bounds of the buf
fer"], | 128 invalid_data_view_offset: ["Start offset is outside the bounds of the buf
fer"], |
129 invalid_data_view_length: ["Invalid data view length"], | 129 invalid_data_view_length: ["Invalid data view length"], |
130 invalid_data_view_accessor_offset: | 130 invalid_data_view_accessor_offset: |
131 ["Offset is outside the bounds of the DataView"
], | 131 ["Offset is outside the bounds of the DataView"
], |
132 | |
133 stack_overflow: ["Maximum call stack size exceeded"], | |
134 invalid_time_value: ["Invalid time value"], | 132 invalid_time_value: ["Invalid time value"], |
135 invalid_count_value: ["Invalid count value"], | 133 invalid_count_value: ["Invalid count value"], |
| 134 // StackOverflowError |
| 135 stack_overflow: ["Maximum call stack size exceeded"], |
136 // SyntaxError | 136 // SyntaxError |
137 paren_in_arg_string: ["Function arg string contains parenthesis"], | 137 paren_in_arg_string: ["Function arg string contains parenthesis"], |
138 not_isvar: ["builtin %IS_VAR: not a variable"], | 138 not_isvar: ["builtin %IS_VAR: not a variable"], |
139 single_function_literal: ["Single function literal required"], | 139 single_function_literal: ["Single function literal required"], |
140 invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor
'", "%0", "'"], | 140 invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor
'", "%0", "'"], |
141 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], | 141 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], |
142 illegal_break: ["Illegal break statement"], | 142 illegal_break: ["Illegal break statement"], |
143 illegal_continue: ["Illegal continue statement"], | 143 illegal_continue: ["Illegal continue statement"], |
144 illegal_return: ["Illegal return statement"], | 144 illegal_return: ["Illegal return statement"], |
145 illegal_let: ["Illegal let declaration outside extended mode
"], | 145 illegal_let: ["Illegal let declaration outside extended mode
"], |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // strange and unusual. | 245 // strange and unusual. |
246 function CanBeSafelyTreatedAsAnErrorObject(obj) { | 246 function CanBeSafelyTreatedAsAnErrorObject(obj) { |
247 switch (%_ClassOf(obj)) { | 247 switch (%_ClassOf(obj)) { |
248 case 'Error': | 248 case 'Error': |
249 case 'EvalError': | 249 case 'EvalError': |
250 case 'RangeError': | 250 case 'RangeError': |
251 case 'ReferenceError': | 251 case 'ReferenceError': |
252 case 'SyntaxError': | 252 case 'SyntaxError': |
253 case 'TypeError': | 253 case 'TypeError': |
254 case 'URIError': | 254 case 'URIError': |
| 255 case 'StackOverflowError': |
255 return true; | 256 return true; |
256 } | 257 } |
257 | 258 |
258 var objToString = %GetDataProperty(obj, "toString"); | 259 var objToString = %GetDataProperty(obj, "toString"); |
259 return obj instanceof $Error && objToString === ErrorToString; | 260 return obj instanceof $Error && objToString === ErrorToString; |
260 } | 261 } |
261 | 262 |
262 | 263 |
263 // When formatting internally created error messages, do not | 264 // When formatting internally created error messages, do not |
264 // invoke overwritten error toString methods but explicitly use | 265 // invoke overwritten error toString methods but explicitly use |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 function MakeTypeError(type, args) { | 339 function MakeTypeError(type, args) { |
339 return MakeGenericError($TypeError, type, args); | 340 return MakeGenericError($TypeError, type, args); |
340 } | 341 } |
341 | 342 |
342 | 343 |
343 function MakeRangeError(type, args) { | 344 function MakeRangeError(type, args) { |
344 return MakeGenericError($RangeError, type, args); | 345 return MakeGenericError($RangeError, type, args); |
345 } | 346 } |
346 | 347 |
347 | 348 |
| 349 function MakeStackOverflowError() { |
| 350 return MakeGenericError($StackOverflowError, 'stack_overflow', []); |
| 351 } |
| 352 |
| 353 |
348 function MakeSyntaxError(type, args) { | 354 function MakeSyntaxError(type, args) { |
349 return MakeGenericError($SyntaxError, type, args); | 355 return MakeGenericError($SyntaxError, type, args); |
350 } | 356 } |
351 | 357 |
352 | 358 |
353 function MakeReferenceError(type, args) { | 359 function MakeReferenceError(type, args) { |
354 return MakeGenericError($ReferenceError, type, args); | 360 return MakeGenericError($ReferenceError, type, args); |
355 } | 361 } |
356 | 362 |
357 | 363 |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 } | 1186 } |
1181 }; | 1187 }; |
1182 | 1188 |
1183 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM); | 1189 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM); |
1184 } | 1190 } |
1185 | 1191 |
1186 | 1192 |
1187 function SetUpError() { | 1193 function SetUpError() { |
1188 // Define special error type constructors. | 1194 // Define special error type constructors. |
1189 | 1195 |
1190 var DefineError = function(f) { | 1196 var DefineError = function(f, error_type) { |
1191 // Store the error function in both the global object | 1197 // Store the error function in both the global object |
1192 // and the runtime object. The function is fetched | 1198 // and the runtime object. The function is fetched |
1193 // from the runtime object when throwing errors from | 1199 // from the runtime object when throwing errors from |
1194 // within the runtime system to avoid strange side | 1200 // within the runtime system to avoid strange side |
1195 // effects when overwriting the error functions from | 1201 // effects when overwriting the error functions from |
1196 // user code. | 1202 // user code. |
1197 var name = f.name; | 1203 var name = f.name; |
1198 %SetProperty(global, name, f, DONT_ENUM); | 1204 if (name != 'StackOverflowError') { // StackOverflowError is not in spec. |
| 1205 %SetProperty(global, name, f, DONT_ENUM); |
| 1206 } |
1199 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY); | 1207 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
1200 // Configure the error function. | 1208 // Configure the error function. |
1201 if (name == 'Error') { | 1209 if (name == 'Error') { |
1202 // The prototype of the Error object must itself be an error. | 1210 // The prototype of the Error object must itself be an error. |
1203 // However, it can't be an instance of the Error object because | 1211 // However, it can't be an instance of the Error object because |
1204 // it hasn't been properly configured yet. Instead we create a | 1212 // it hasn't been properly configured yet. Instead we create a |
1205 // special not-a-true-error-but-close-enough object. | 1213 // special not-a-true-error-but-close-enough object. |
1206 var ErrorPrototype = function() {}; | 1214 var ErrorPrototype = function() {}; |
1207 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); | 1215 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); |
1208 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); | 1216 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
1209 %FunctionSetPrototype(f, new ErrorPrototype()); | 1217 %FunctionSetPrototype(f, new ErrorPrototype()); |
| 1218 } else if (name == 'StackOverflowError') { |
| 1219 // StackOverflowError extends RangeError for backward compatibility. |
| 1220 %FunctionSetPrototype(f, new $RangeError()); |
1210 } else { | 1221 } else { |
1211 %FunctionSetPrototype(f, new $Error()); | 1222 %FunctionSetPrototype(f, new $Error()); |
1212 } | 1223 } |
1213 %FunctionSetInstanceClassName(f, 'Error'); | 1224 %FunctionSetInstanceClassName(f, 'Error'); |
1214 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1225 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
1215 %SetProperty(f.prototype, "name", name, DONT_ENUM); | 1226 %SetProperty(f.prototype, "name", name, DONT_ENUM); |
1216 %SetCode(f, function(m) { | 1227 %SetCode(f, function(m) { |
1217 if (%_IsConstructCall()) { | 1228 if (%_IsConstructCall()) { |
1218 // Define all the expected properties directly on the error | 1229 // Define all the expected properties directly on the error |
1219 // object. This avoids going through getters and setters defined | 1230 // object. This avoids going through getters and setters defined |
1220 // on prototype objects. | 1231 // on prototype objects. |
1221 %IgnoreAttributesAndSetProperty(this, 'stack', UNDEFINED, DONT_ENUM); | 1232 %IgnoreAttributesAndSetProperty(this, 'stack', UNDEFINED, DONT_ENUM); |
1222 if (!IS_UNDEFINED(m)) { | 1233 if (!IS_UNDEFINED(m)) { |
1223 %IgnoreAttributesAndSetProperty( | 1234 %IgnoreAttributesAndSetProperty( |
1224 this, 'message', ToString(m), DONT_ENUM); | 1235 this, 'message', ToString(m), DONT_ENUM); |
1225 } | 1236 } |
| 1237 // Define error_type property as a private symbol. |
| 1238 %IgnoreAttributesAndSetProperty( |
| 1239 this, error_type_symbol, error_type, READ_ONLY | DONT_DELETE); |
1226 captureStackTrace(this, f); | 1240 captureStackTrace(this, f); |
1227 } else { | 1241 } else { |
1228 return new f(m); | 1242 return new f(m); |
1229 } | 1243 } |
1230 }); | 1244 }); |
1231 %SetNativeFlag(f); | 1245 %SetNativeFlag(f); |
1232 }; | 1246 }; |
1233 | 1247 |
1234 DefineError(function Error() { }); | 1248 DefineError(function Error() { }, kError); |
1235 DefineError(function TypeError() { }); | 1249 DefineError(function TypeError() { }, kTypeError); |
1236 DefineError(function RangeError() { }); | 1250 DefineError(function RangeError() { }, kRangeError); |
1237 DefineError(function SyntaxError() { }); | 1251 DefineError(function SyntaxError() { }, kSyntaxError); |
1238 DefineError(function ReferenceError() { }); | 1252 DefineError(function ReferenceError() { }, kReferenceError); |
1239 DefineError(function EvalError() { }); | 1253 DefineError(function EvalError() { }, kEvalError); |
1240 DefineError(function URIError() { }); | 1254 DefineError(function URIError() { }, kURIError); |
| 1255 DefineError(function StackOverflowError() { }, kStackOverflowError); |
1241 } | 1256 } |
1242 | 1257 |
1243 SetUpError(); | 1258 SetUpError(); |
1244 | 1259 |
1245 $Error.captureStackTrace = captureStackTrace; | 1260 $Error.captureStackTrace = captureStackTrace; |
1246 | 1261 |
1247 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); | 1262 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); |
1248 | 1263 |
1249 // Global list of error objects visited during ErrorToString. This is | 1264 // Global list of error objects visited during ErrorToString. This is |
1250 // used to detect cycles in error toString formatting. | 1265 // used to detect cycles in error toString formatting. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 throw e; | 1322 throw e; |
1308 } | 1323 } |
1309 } | 1324 } |
1310 | 1325 |
1311 | 1326 |
1312 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1327 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1313 | 1328 |
1314 // Boilerplate for exceptions for stack overflows. Used from | 1329 // Boilerplate for exceptions for stack overflows. Used from |
1315 // Isolate::StackOverflow(). | 1330 // Isolate::StackOverflow(). |
1316 function SetUpStackOverflowBoilerplate() { | 1331 function SetUpStackOverflowBoilerplate() { |
1317 var boilerplate = MakeRangeError('stack_overflow', []); | 1332 var boilerplate = MakeStackOverflowError(); |
1318 | 1333 |
1319 var error_string = boilerplate.name + ": " + boilerplate.message; | 1334 var error_string = boilerplate.name + ": " + boilerplate.message; |
1320 | 1335 |
1321 // The raw stack trace is stored as a hidden property on the holder of this | 1336 // The raw stack trace is stored as a hidden property on the holder of this |
1322 // getter, which may not be the same as the receiver. Find the holder to | 1337 // getter, which may not be the same as the receiver. Find the holder to |
1323 // retrieve the raw stack trace and then turn this accessor pair into a | 1338 // retrieve the raw stack trace and then turn this accessor pair into a |
1324 // data property. | 1339 // data property. |
1325 var getter = function() { | 1340 var getter = function() { |
1326 var holder = this; | 1341 var holder = this; |
1327 while (!IS_ERROR(holder)) { | 1342 while (!IS_ERROR(holder)) { |
(...skipping 19 matching lines...) Expand all Loading... |
1347 %GetAndClearOverflowedStackTrace(this); | 1362 %GetAndClearOverflowedStackTrace(this); |
1348 }; | 1363 }; |
1349 | 1364 |
1350 %DefineOrRedefineAccessorProperty( | 1365 %DefineOrRedefineAccessorProperty( |
1351 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1366 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1352 | 1367 |
1353 return boilerplate; | 1368 return boilerplate; |
1354 } | 1369 } |
1355 | 1370 |
1356 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1371 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |