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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 generator_poison_pill: ["'caller' and 'arguments' properties may not b
e accessed on generator functions."], | 155 generator_poison_pill: ["'caller' and 'arguments' properties may not b
e accessed on generator functions."], |
156 unprotected_let: ["Illegal let declaration in unprotected statem
ent context."], | 156 unprotected_let: ["Illegal let declaration in unprotected statem
ent context."], |
157 unprotected_const: ["Illegal const declaration in unprotected stat
ement context."], | 157 unprotected_const: ["Illegal const declaration in unprotected stat
ement context."], |
158 cant_prevent_ext_external_array_elements: ["Cannot prevent extension of an obj
ect with external array elements"], | 158 cant_prevent_ext_external_array_elements: ["Cannot prevent extension of an obj
ect with external array elements"], |
159 redef_external_array_element: ["Cannot redefine a property of an object with
external array elements"], | 159 redef_external_array_element: ["Cannot redefine a property of an object with
external array elements"], |
160 harmony_const_assign: ["Assignment to constant variable."], | 160 harmony_const_assign: ["Assignment to constant variable."], |
161 symbol_to_string: ["Cannot convert a Symbol value to a string"], | 161 symbol_to_string: ["Cannot convert a Symbol value to a string"], |
162 symbol_to_primitive: ["Cannot convert a Symbol wrapper object to a p
rimitive value"], | 162 symbol_to_primitive: ["Cannot convert a Symbol wrapper object to a p
rimitive value"], |
163 invalid_module_path: ["Module does not export '", "%0", "', or expor
t is not itself a module"], | 163 invalid_module_path: ["Module does not export '", "%0", "', or expor
t is not itself a module"], |
164 module_type_error: ["Module '", "%0", "' used improperly"], | 164 module_type_error: ["Module '", "%0", "' used improperly"], |
165 module_export_undefined: ["Export '", "%0", "' is not defined in module"
] | 165 module_export_undefined: ["Export '", "%0", "' is not defined in module"
], |
| 166 // Internal error. |
| 167 internal_error: ["Internal error"] |
166 }; | 168 }; |
167 | 169 |
168 | 170 |
169 function FormatString(format, args) { | 171 function FormatString(format, args) { |
170 var result = ""; | 172 var result = ""; |
171 var arg_num = 0; | 173 var arg_num = 0; |
172 for (var i = 0; i < format.length; i++) { | 174 for (var i = 0; i < format.length; i++) { |
173 var str = format[i]; | 175 var str = format[i]; |
174 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { | 176 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { |
175 // Two-char string starts with "%". | 177 // Two-char string starts with "%". |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 344 |
343 function MakeEvalError(type, args) { | 345 function MakeEvalError(type, args) { |
344 return MakeGenericError($EvalError, type, args); | 346 return MakeGenericError($EvalError, type, args); |
345 } | 347 } |
346 | 348 |
347 | 349 |
348 function MakeError(type, args) { | 350 function MakeError(type, args) { |
349 return MakeGenericError($Error, type, args); | 351 return MakeGenericError($Error, type, args); |
350 } | 352 } |
351 | 353 |
| 354 |
| 355 function MakeInternalError() { |
| 356 return MakeGenericError($InternalError, "internal_error"); |
| 357 } |
| 358 |
352 /** | 359 /** |
353 * Find a line number given a specific source position. | 360 * Find a line number given a specific source position. |
354 * @param {number} position The source position. | 361 * @param {number} position The source position. |
355 * @return {number} 0 if input too small, -1 if input too large, | 362 * @return {number} 0 if input too small, -1 if input too large, |
356 else the line number. | 363 else the line number. |
357 */ | 364 */ |
358 function ScriptLineFromPosition(position) { | 365 function ScriptLineFromPosition(position) { |
359 var lower = 0; | 366 var lower = 0; |
360 var upper = this.lineCount() - 1; | 367 var upper = this.lineCount() - 1; |
361 var line_ends = this.line_ends; | 368 var line_ends = this.line_ends; |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 // Store the error function in both the global object | 1184 // Store the error function in both the global object |
1178 // and the runtime object. The function is fetched | 1185 // and the runtime object. The function is fetched |
1179 // from the runtime object when throwing errors from | 1186 // from the runtime object when throwing errors from |
1180 // within the runtime system to avoid strange side | 1187 // within the runtime system to avoid strange side |
1181 // effects when overwriting the error functions from | 1188 // effects when overwriting the error functions from |
1182 // user code. | 1189 // user code. |
1183 var name = f.name; | 1190 var name = f.name; |
1184 %SetProperty(global, name, f, DONT_ENUM); | 1191 %SetProperty(global, name, f, DONT_ENUM); |
1185 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY); | 1192 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
1186 // Configure the error function. | 1193 // Configure the error function. |
1187 if (name == 'Error') { | 1194 if (name === 'Error') { |
1188 // The prototype of the Error object must itself be an error. | 1195 // The prototype of the Error object must itself be an error. |
1189 // However, it can't be an instance of the Error object because | 1196 // However, it can't be an instance of the Error object because |
1190 // it hasn't been properly configured yet. Instead we create a | 1197 // it hasn't been properly configured yet. Instead we create a |
1191 // special not-a-true-error-but-close-enough object. | 1198 // special not-a-true-error-but-close-enough object. |
1192 var ErrorPrototype = function() {}; | 1199 var ErrorPrototype = function() {}; |
1193 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); | 1200 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); |
1194 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); | 1201 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
1195 %FunctionSetPrototype(f, new ErrorPrototype()); | 1202 %FunctionSetPrototype(f, new ErrorPrototype()); |
1196 } else { | 1203 } else if (name !== 'InternalError') { |
1197 %FunctionSetPrototype(f, new $Error()); | 1204 %FunctionSetPrototype(f, new $Error()); |
1198 } | 1205 } |
1199 %FunctionSetInstanceClassName(f, 'Error'); | 1206 %FunctionSetInstanceClassName(f, 'Error'); |
1200 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1207 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
1201 %SetProperty(f.prototype, "name", name, DONT_ENUM); | 1208 %SetProperty(f.prototype, "name", name, DONT_ENUM); |
1202 %SetCode(f, function(m) { | 1209 %SetCode(f, function(m) { |
1203 if (%_IsConstructCall()) { | 1210 if (%_IsConstructCall()) { |
1204 // Define all the expected properties directly on the error | 1211 // Define all the expected properties directly on the error |
1205 // object. This avoids going through getters and setters defined | 1212 // object. This avoids going through getters and setters defined |
1206 // on prototype objects. | 1213 // on prototype objects. |
(...skipping 10 matching lines...) Expand all Loading... |
1217 %SetNativeFlag(f); | 1224 %SetNativeFlag(f); |
1218 }; | 1225 }; |
1219 | 1226 |
1220 DefineError(function Error() { }); | 1227 DefineError(function Error() { }); |
1221 DefineError(function TypeError() { }); | 1228 DefineError(function TypeError() { }); |
1222 DefineError(function RangeError() { }); | 1229 DefineError(function RangeError() { }); |
1223 DefineError(function SyntaxError() { }); | 1230 DefineError(function SyntaxError() { }); |
1224 DefineError(function ReferenceError() { }); | 1231 DefineError(function ReferenceError() { }); |
1225 DefineError(function EvalError() { }); | 1232 DefineError(function EvalError() { }); |
1226 DefineError(function URIError() { }); | 1233 DefineError(function URIError() { }); |
| 1234 DefineError(function InternalError() { }); |
1227 } | 1235 } |
1228 | 1236 |
1229 SetUpError(); | 1237 SetUpError(); |
1230 | 1238 |
1231 $Error.captureStackTrace = captureStackTrace; | 1239 $Error.captureStackTrace = captureStackTrace; |
1232 | 1240 |
1233 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); | 1241 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); |
1234 | 1242 |
1235 // Global list of error objects visited during ErrorToString. This is | 1243 // Global list of error objects visited during ErrorToString. This is |
1236 // used to detect cycles in error toString formatting. | 1244 // used to detect cycles in error toString formatting. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 return result; | 1342 return result; |
1335 }; | 1343 }; |
1336 | 1344 |
1337 %DefineOrRedefineAccessorProperty( | 1345 %DefineOrRedefineAccessorProperty( |
1338 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1346 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1339 | 1347 |
1340 return boilerplate; | 1348 return boilerplate; |
1341 } | 1349 } |
1342 | 1350 |
1343 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1351 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |