| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 var arg_num = 0; | 170 var arg_num = 0; |
| 171 for (var i = 0; i < format.length; i++) { | 171 for (var i = 0; i < format.length; i++) { |
| 172 var str = format[i]; | 172 var str = format[i]; |
| 173 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { | 173 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { |
| 174 // Two-char string starts with "%". | 174 // Two-char string starts with "%". |
| 175 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; | 175 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; |
| 176 if (arg_num < 4) { | 176 if (arg_num < 4) { |
| 177 // str is one of %0, %1, %2 or %3. | 177 // str is one of %0, %1, %2 or %3. |
| 178 try { | 178 try { |
| 179 str = NoSideEffectToString(args[arg_num]); | 179 str = NoSideEffectToString(args[arg_num]); |
| 180 if (str.length > 256) { | |
| 181 str = %_SubString(str, 0, 239) + "...<omitted>..." + | |
| 182 %_SubString(str, str.length - 2, str.length); | |
| 183 } | |
| 184 } catch (e) { | 180 } catch (e) { |
| 185 if (%IsJSModule(args[arg_num])) | 181 if (%IsJSModule(args[arg_num])) |
| 186 str = "module"; | 182 str = "module"; |
| 187 else if (IS_SPEC_OBJECT(args[arg_num])) | 183 else if (IS_SPEC_OBJECT(args[arg_num])) |
| 188 str = "object"; | 184 str = "object"; |
| 189 else | 185 else |
| 190 str = "#<error>"; | 186 str = "#<error>"; |
| 191 } | 187 } |
| 192 } | 188 } |
| 193 } | 189 } |
| 194 result += str; | 190 result += str; |
| 195 } | 191 } |
| 196 return result; | 192 return result; |
| 197 } | 193 } |
| 198 | 194 |
| 199 | 195 |
| 200 function NoSideEffectToString(obj) { | 196 function NoSideEffectToString(obj) { |
| 201 if (IS_STRING(obj)) return obj; | 197 if (IS_STRING(obj)) return obj; |
| 202 if (IS_NUMBER(obj)) return %_NumberToString(obj); | 198 if (IS_NUMBER(obj)) return %_NumberToString(obj); |
| 203 if (IS_BOOLEAN(obj)) return x ? 'true' : 'false'; | 199 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; |
| 204 if (IS_UNDEFINED(obj)) return 'undefined'; | 200 if (IS_UNDEFINED(obj)) return 'undefined'; |
| 205 if (IS_NULL(obj)) return 'null'; | 201 if (IS_NULL(obj)) return 'null'; |
| 206 if (IS_FUNCTION(obj)) return %_CallFunction(obj, FunctionToString); | 202 if (IS_FUNCTION(obj)) { |
| 203 var str = %_CallFunction(obj, FunctionToString); |
| 204 if (str.length > 128) { |
| 205 str = %_SubString(str, 0, 111) + "...<omitted>..." + |
| 206 %_SubString(str, str.length - 2, str.length); |
| 207 } |
| 208 return str; |
| 209 } |
| 207 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { | 210 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { |
| 208 var constructor = %GetDataProperty(obj, "constructor"); | 211 var constructor = %GetDataProperty(obj, "constructor"); |
| 209 if (typeof constructor == "function") { | 212 if (typeof constructor == "function") { |
| 210 var constructorName = constructor.name; | 213 var constructorName = constructor.name; |
| 211 if (IS_STRING(constructorName) && constructorName !== "") { | 214 if (IS_STRING(constructorName) && constructorName !== "") { |
| 212 return "#<" + constructorName + ">"; | 215 return "#<" + constructorName + ">"; |
| 213 } | 216 } |
| 214 } | 217 } |
| 215 } | 218 } |
| 216 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 219 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 return result; | 1333 return result; |
| 1331 }; | 1334 }; |
| 1332 | 1335 |
| 1333 %DefineOrRedefineAccessorProperty( | 1336 %DefineOrRedefineAccessorProperty( |
| 1334 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1337 boilerplate, 'stack', getter, setter, DONT_ENUM); |
| 1335 | 1338 |
| 1336 return boilerplate; | 1339 return boilerplate; |
| 1337 } | 1340 } |
| 1338 | 1341 |
| 1339 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1342 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |