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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 if (IS_NULL(obj)) return 'null'; | 216 if (IS_NULL(obj)) return 'null'; |
217 if (IS_FUNCTION(obj)) { | 217 if (IS_FUNCTION(obj)) { |
218 var str = %_CallFunction(obj, FunctionToString); | 218 var str = %_CallFunction(obj, FunctionToString); |
219 if (str.length > 128) { | 219 if (str.length > 128) { |
220 str = %_SubString(str, 0, 111) + "...<omitted>..." + | 220 str = %_SubString(str, 0, 111) + "...<omitted>..." + |
221 %_SubString(str, str.length - 2, str.length); | 221 %_SubString(str, str.length - 2, str.length); |
222 } | 222 } |
223 return str; | 223 return str; |
224 } | 224 } |
225 if (IS_SYMBOL(obj)) return %_CallFunction(obj, SymbolToString); | 225 if (IS_SYMBOL(obj)) return %_CallFunction(obj, SymbolToString); |
226 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { | 226 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
227 return %_CallFunction(obj, ErrorToString); | |
228 } | |
229 if (IS_OBJECT(obj)) { | |
caitp (gmail)
2014/10/21 01:09:37
So, this will cause arrays to always be reported a
| |
227 var constructor = %GetDataProperty(obj, "constructor"); | 230 var constructor = %GetDataProperty(obj, "constructor"); |
228 if (typeof constructor == "function") { | 231 if (typeof constructor == "function") { |
229 var constructorName = constructor.name; | 232 var constructorName = constructor.name; |
230 if (IS_STRING(constructorName) && constructorName !== "") { | 233 if (IS_STRING(constructorName) && constructorName !== "") { |
231 return "#<" + constructorName + ">"; | 234 return "#<" + constructorName + ">"; |
232 } | 235 } |
233 } | 236 } |
234 } | 237 } |
235 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | |
236 return %_CallFunction(obj, ErrorToString); | |
237 } | |
238 return %_CallFunction(obj, ObjectToString); | 238 return %_CallFunction(obj, ObjectToString); |
239 } | 239 } |
240 | 240 |
241 // To determine whether we can safely stringify an object using ErrorToString | 241 // To determine whether we can safely stringify an object using ErrorToString |
242 // without the risk of side-effects, we need to check whether the object is | 242 // without the risk of side-effects, we need to check whether the object is |
243 // either an instance of a native error type (via '%_ClassOf'), or has $Error | 243 // either an instance of a native error type (via '%_ClassOf'), or has $Error |
244 // in its prototype chain and hasn't overwritten 'toString' with something | 244 // in its prototype chain and hasn't overwritten 'toString' with something |
245 // strange and unusual. | 245 // strange and unusual. |
246 function CanBeSafelyTreatedAsAnErrorObject(obj) { | 246 function CanBeSafelyTreatedAsAnErrorObject(obj) { |
247 switch (%_ClassOf(obj)) { | 247 switch (%_ClassOf(obj)) { |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 function SetUpStackOverflowBoilerplate() { | 1300 function SetUpStackOverflowBoilerplate() { |
1301 var boilerplate = MakeRangeError('stack_overflow', []); | 1301 var boilerplate = MakeRangeError('stack_overflow', []); |
1302 | 1302 |
1303 %DefineAccessorPropertyUnchecked( | 1303 %DefineAccessorPropertyUnchecked( |
1304 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1304 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
1305 | 1305 |
1306 return boilerplate; | 1306 return boilerplate; |
1307 } | 1307 } |
1308 | 1308 |
1309 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1309 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |