Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: src/messages.js

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase, rename ObjectToString Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap/heap.h ('k') | src/promise.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (IS_OBJECT(obj)
227 && %GetDataProperty(obj, "toString") === DefaultObjectToString) {
227 var constructor = %GetDataProperty(obj, "constructor"); 228 var constructor = %GetDataProperty(obj, "constructor");
228 if (typeof constructor == "function") { 229 if (typeof constructor == "function") {
229 var constructorName = constructor.name; 230 var constructorName = constructor.name;
230 if (IS_STRING(constructorName) && constructorName !== "") { 231 if (IS_STRING(constructorName) && constructorName !== "") {
231 return "#<" + constructorName + ">"; 232 return "#<" + constructorName + ">";
232 } 233 }
233 } 234 }
234 } 235 }
235 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { 236 if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
236 return %_CallFunction(obj, ErrorToString); 237 return %_CallFunction(obj, ErrorToString);
237 } 238 }
238 return %_CallFunction(obj, ObjectToString); 239
240 return %_CallFunction(obj, NoSideEffectsObjectToString);
239 } 241 }
240 242
241 // To determine whether we can safely stringify an object using ErrorToString 243 // 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 244 // 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 245 // 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 246 // in its prototype chain and hasn't overwritten 'toString' with something
245 // strange and unusual. 247 // strange and unusual.
246 function CanBeSafelyTreatedAsAnErrorObject(obj) { 248 function CanBeSafelyTreatedAsAnErrorObject(obj) {
247 switch (%_ClassOf(obj)) { 249 switch (%_ClassOf(obj)) {
248 case 'Error': 250 case 'Error':
(...skipping 18 matching lines...) Expand all
267 function ToStringCheckErrorObject(obj) { 269 function ToStringCheckErrorObject(obj) {
268 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { 270 if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
269 return %_CallFunction(obj, ErrorToString); 271 return %_CallFunction(obj, ErrorToString);
270 } else { 272 } else {
271 return ToString(obj); 273 return ToString(obj);
272 } 274 }
273 } 275 }
274 276
275 277
276 function ToDetailString(obj) { 278 function ToDetailString(obj) {
277 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { 279 if (obj != null && IS_OBJECT(obj) && obj.toString === DefaultObjectToString) {
278 var constructor = obj.constructor; 280 var constructor = obj.constructor;
279 if (typeof constructor == "function") { 281 if (typeof constructor == "function") {
280 var constructorName = constructor.name; 282 var constructorName = constructor.name;
281 if (IS_STRING(constructorName) && constructorName !== "") { 283 if (IS_STRING(constructorName) && constructorName !== "") {
282 return "#<" + constructorName + ">"; 284 return "#<" + constructorName + ">";
283 } 285 }
284 } 286 }
285 } 287 }
286 return ToStringCheckErrorObject(obj); 288 return ToStringCheckErrorObject(obj);
287 } 289 }
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 lines.push(" at " + line); 1100 lines.push(" at " + line);
1099 } 1101 }
1100 return %_CallFunction(lines, "\n", ArrayJoin); 1102 return %_CallFunction(lines, "\n", ArrayJoin);
1101 } 1103 }
1102 1104
1103 1105
1104 function GetTypeName(receiver, requireConstructor) { 1106 function GetTypeName(receiver, requireConstructor) {
1105 var constructor = receiver.constructor; 1107 var constructor = receiver.constructor;
1106 if (!constructor) { 1108 if (!constructor) {
1107 return requireConstructor ? null : 1109 return requireConstructor ? null :
1108 %_CallFunction(receiver, ObjectToString); 1110 %_CallFunction(receiver, NoSideEffectsObjectToString);
1109 } 1111 }
1110 var constructorName = constructor.name; 1112 var constructorName = constructor.name;
1111 if (!constructorName) { 1113 if (!constructorName) {
1112 return requireConstructor ? null : 1114 return requireConstructor ? null :
1113 %_CallFunction(receiver, ObjectToString); 1115 %_CallFunction(receiver, NoSideEffectsObjectToString);
1114 } 1116 }
1115 return constructorName; 1117 return constructorName;
1116 } 1118 }
1117 1119
1118 1120
1119 var stack_trace_symbol; // Set during bootstrapping. 1121 var stack_trace_symbol; // Set during bootstrapping.
1120 var formatted_stack_trace_symbol = NEW_PRIVATE_OWN("formatted stack trace"); 1122 var formatted_stack_trace_symbol = NEW_PRIVATE_OWN("formatted stack trace");
1121 1123
1122 1124
1123 // Format the stack trace if not yet done, and return it. 1125 // Format the stack trace if not yet done, and return it.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 function SetUpStackOverflowBoilerplate() { 1302 function SetUpStackOverflowBoilerplate() {
1301 var boilerplate = MakeRangeError('stack_overflow', []); 1303 var boilerplate = MakeRangeError('stack_overflow', []);
1302 1304
1303 %DefineAccessorPropertyUnchecked( 1305 %DefineAccessorPropertyUnchecked(
1304 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); 1306 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM);
1305 1307
1306 return boilerplate; 1308 return boilerplate;
1307 } 1309 }
1308 1310
1309 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); 1311 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate();
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/promise.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698