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

Side by Side Diff: src/mirror-delay.js

Issue 16539: Factored the generation of JSON serialization from beeing part of the mirror ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 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 | « no previous file | test/mjsunit/mirror-array.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Touch the RegExp and Date functions to make sure that date-delay.js and 28 // Touch the RegExp and Date functions to make sure that date-delay.js and
29 // regexp-delay.js has been loaded. This is required as the mirrors use 29 // regexp-delay.js has been loaded. This is required as the mirrors use
30 // functions within these files through the builtins object. See the 30 // functions within these files through the builtins object. See the
31 // function DateToISO8601_ as an example. 31 // function DateToISO8601_ as an example.
32 RegExp; 32 RegExp;
33 Date; 33 Date;
34 34
35 35
36 /**
37 * Returns the mirror for a specified value or object.
38 *
39 * @param {value or Object} value the value or object to retreive the mirror for
40 * @returns {Mirror} the mirror reflects the passed value or object
41 */
36 function MakeMirror(value) { 42 function MakeMirror(value) {
37 if (IS_UNDEFINED(value)) return new UndefinedMirror(); 43 if (IS_UNDEFINED(value)) return new UndefinedMirror();
38 if (IS_NULL(value)) return new NullMirror(); 44 if (IS_NULL(value)) return new NullMirror();
39 if (IS_BOOLEAN(value)) return new BooleanMirror(value); 45 if (IS_BOOLEAN(value)) return new BooleanMirror(value);
40 if (IS_NUMBER(value)) return new NumberMirror(value); 46 if (IS_NUMBER(value)) return new NumberMirror(value);
41 if (IS_STRING(value)) return new StringMirror(value); 47 if (IS_STRING(value)) return new StringMirror(value);
42 if (IS_ARRAY(value)) return new ArrayMirror(value); 48 if (IS_ARRAY(value)) return new ArrayMirror(value);
43 if (IS_DATE(value)) return new DateMirror(value); 49 if (IS_DATE(value)) return new DateMirror(value);
44 if (IS_FUNCTION(value)) return new FunctionMirror(value); 50 if (IS_FUNCTION(value)) return new FunctionMirror(value);
45 if (IS_REGEXP(value)) return new RegExpMirror(value); 51 if (IS_REGEXP(value)) return new RegExpMirror(value);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 PropertyType.Normal = 0; 105 PropertyType.Normal = 0;
100 PropertyType.Field = 1; 106 PropertyType.Field = 1;
101 PropertyType.ConstantFunction = 2; 107 PropertyType.ConstantFunction = 2;
102 PropertyType.Callbacks = 3; 108 PropertyType.Callbacks = 3;
103 PropertyType.Interceptor = 4; 109 PropertyType.Interceptor = 4;
104 PropertyType.MapTransition = 5; 110 PropertyType.MapTransition = 5;
105 PropertyType.ConstantTransition = 6; 111 PropertyType.ConstantTransition = 6;
106 PropertyType.NullDescriptor = 7; 112 PropertyType.NullDescriptor = 7;
107 113
108 114
109
110 // Different attributes for a property. 115 // Different attributes for a property.
111 PropertyAttribute = {}; 116 PropertyAttribute = {};
112 PropertyAttribute.None = NONE; 117 PropertyAttribute.None = NONE;
113 PropertyAttribute.ReadOnly = READ_ONLY; 118 PropertyAttribute.ReadOnly = READ_ONLY;
114 PropertyAttribute.DontEnum = DONT_ENUM; 119 PropertyAttribute.DontEnum = DONT_ENUM;
115 PropertyAttribute.DontDelete = DONT_DELETE; 120 PropertyAttribute.DontDelete = DONT_DELETE;
116 121
117 122
118 // Mirror hierarchy: 123 // Mirror hierarchy:
119 // - Mirror 124 // - Mirror
120 // - ValueMirror 125 // - ValueMirror
121 // - UndefinedMirror 126 // - UndefinedMirror
122 // - NullMirror 127 // - NullMirror
123 // - NumberMirror 128 // - NumberMirror
124 // - StringMirror 129 // - StringMirror
125 // - ObjectMirror 130 // - ObjectMirror
126 // - FunctionMirror 131 // - FunctionMirror
127 // - UnresolvedFunctionMirror 132 // - UnresolvedFunctionMirror
128 // - ArrayMirror 133 // - ArrayMirror
129 // - DateMirror 134 // - DateMirror
130 // - RegExpMirror 135 // - RegExpMirror
131 // - ErrorMirror 136 // - ErrorMirror
132 // - PropertyMirror 137 // - PropertyMirror
133 // - InterceptorPropertyMirror 138 // - InterceptorPropertyMirror
134 // - AccessorMirror 139 // - AccessorMirror
135 // - FrameMirror 140 // - FrameMirror
136 // - ScriptMirror 141 // - ScriptMirror
137 142
138 143
139 /** 144 /**
140 * Base class for all mirror objects. 145 * Base class for all mirror objects.
141 * @param {string} type The type of the mirror 146 * @param {string} type The type of the mirror
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 294
290 /** 295 /**
291 * Check whether the mirror reflects a stack frame. 296 * Check whether the mirror reflects a stack frame.
292 * @returns {boolean} True if the mirror reflects a stack frame 297 * @returns {boolean} True if the mirror reflects a stack frame
293 */ 298 */
294 Mirror.prototype.isFrame = function() { 299 Mirror.prototype.isFrame = function() {
295 return this instanceof FrameMirror; 300 return this instanceof FrameMirror;
296 } 301 }
297 302
298 303
299 Mirror.prototype.fillJSONType_ = function(content) { 304 /**
300 content.push(MakeJSONPair_('type', StringToJSON_(this.type()))); 305 * Check whether the mirror reflects a script.
301 }; 306 * @returns {boolean} True if the mirror reflects a script
302 307 */
303 308 Mirror.prototype.isScript = function() {
304 Mirror.prototype.fillJSON_ = function(content) { 309 return this instanceof ScriptMirror;
305 this.fillJSONType_(content); 310 }
306 };
307 311
308 312
309 /** 313 /**
310 * Serialize object in JSON format. For the basic mirrors this includes only 314 * Serialize object in JSON format. The actual serialization is handled by the
311 * the type in the following format. 315 * JSONProtocolSerializer.
312 * {"type":"<type name>"}
313 * For specialized mirrors inheriting from the base Mirror
314 * @param {boolean} details Indicate level of details to include 316 * @param {boolean} details Indicate level of details to include
315 * @return {string} JSON serialization 317 * @return {string} JSON serialization
316 */ 318 */
317 Mirror.prototype.toJSONProtocol = function(details, propertiesKind, interceptorP ropertiesKind) { 319 Mirror.prototype.toJSONProtocol = function(details) {
318 var content = new Array(); 320 var serializer = new JSONProtocolSerializer(details)
319 this.fillJSON_(content, details, propertiesKind, interceptorPropertiesKind); 321 return serializer.serialize(this)
320 content.push(MakeJSONPair_('text', StringToJSON_(this.toText())));
321 return ArrayToJSONObject_(content);
322 } 322 }
323 323
324 324
325 Mirror.prototype.toText = function() { 325 Mirror.prototype.toText = function() {
326 // Simpel to text which is used when on specialization in subclass. 326 // Simpel to text which is used when on specialization in subclass.
327 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; 327 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";
328 } 328 }
329 329
330 330
331 /** 331 /**
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 * @param {boolean} value The boolean value reflected by this mirror 402 * @param {boolean} value The boolean value reflected by this mirror
403 * @constructor 403 * @constructor
404 * @extends ValueMirror 404 * @extends ValueMirror
405 */ 405 */
406 function BooleanMirror(value) { 406 function BooleanMirror(value) {
407 ValueMirror.call(this, BOOLEAN_TYPE, value); 407 ValueMirror.call(this, BOOLEAN_TYPE, value);
408 } 408 }
409 inherits(BooleanMirror, ValueMirror); 409 inherits(BooleanMirror, ValueMirror);
410 410
411 411
412 BooleanMirror.prototype.fillJSON_ = function(content, details) {
413 BooleanMirror.super_.fillJSONType_.call(this, content);
414 content.push(MakeJSONPair_('value', BooleanToJSON_(this.value_)));
415 }
416
417
418 BooleanMirror.prototype.toText = function() { 412 BooleanMirror.prototype.toText = function() {
419 return this.value_ ? 'true' : 'false'; 413 return this.value_ ? 'true' : 'false';
420 } 414 }
421 415
422 416
423 /** 417 /**
424 * Mirror object for number values. 418 * Mirror object for number values.
425 * @param {number} value The number value reflected by this mirror 419 * @param {number} value The number value reflected by this mirror
426 * @constructor 420 * @constructor
427 * @extends ValueMirror 421 * @extends ValueMirror
428 */ 422 */
429 function NumberMirror(value) { 423 function NumberMirror(value) {
430 ValueMirror.call(this, NUMBER_TYPE, value); 424 ValueMirror.call(this, NUMBER_TYPE, value);
431 } 425 }
432 inherits(NumberMirror, ValueMirror); 426 inherits(NumberMirror, ValueMirror);
433 427
434 428
435 NumberMirror.prototype.fillJSON_ = function(content, details) {
436 NumberMirror.super_.fillJSONType_.call(this, content);
437 content.push(MakeJSONPair_('value', NumberToJSON_(this.value_)));
438 }
439
440
441 NumberMirror.prototype.toText = function() { 429 NumberMirror.prototype.toText = function() {
442 return %NumberToString(this.value_); 430 return %NumberToString(this.value_);
443 } 431 }
444 432
445 433
446 /** 434 /**
447 * Mirror object for string values. 435 * Mirror object for string values.
448 * @param {string} value The string value reflected by this mirror 436 * @param {string} value The string value reflected by this mirror
449 * @constructor 437 * @constructor
450 * @extends ValueMirror 438 * @extends ValueMirror
451 */ 439 */
452 function StringMirror(value) { 440 function StringMirror(value) {
453 ValueMirror.call(this, STRING_TYPE, value); 441 ValueMirror.call(this, STRING_TYPE, value);
454 } 442 }
455 inherits(StringMirror, ValueMirror); 443 inherits(StringMirror, ValueMirror);
456 444
457 445
458 StringMirror.prototype.length = function() { 446 StringMirror.prototype.length = function() {
459 return this.value_.length; 447 return this.value_.length;
460 }; 448 };
461 449
462 450
463 StringMirror.prototype.fillJSON_ = function(content, details) {
464 StringMirror.super_.fillJSONType_.call(this, content);
465 content.push(MakeJSONPair_('length', NumberToJSON_(this.length())));
466 if (this.length() > kMaxProtocolStringLength) {
467 content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0)));
468 content.push(MakeJSONPair_('toIndex',
469 NumberToJSON_(kMaxProtocolStringLength)));
470 var str = this.value_.substring(0, kMaxProtocolStringLength);
471 content.push(MakeJSONPair_('value', StringToJSON_(str)));
472 } else {
473 content.push(MakeJSONPair_('value', StringToJSON_(this.value_)));
474 }
475 }
476
477
478 StringMirror.prototype.toText = function() { 451 StringMirror.prototype.toText = function() {
479 if (this.length() > kMaxProtocolStringLength) { 452 if (this.length() > kMaxProtocolStringLength) {
480 return this.value_.substring(0, kMaxProtocolStringLength) + 453 return this.value_.substring(0, kMaxProtocolStringLength) +
481 '... (length: ' + this.length() + ')'; 454 '... (length: ' + this.length() + ')';
482 } else { 455 } else {
483 return this.value_; 456 return this.value_;
484 } 457 }
485 } 458 }
486 459
487 460
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 704
732 // Make mirrors for all the instances found. 705 // Make mirrors for all the instances found.
733 for (var i = 0; i < result.length; i++) { 706 for (var i = 0; i < result.length; i++) {
734 result[i] = MakeMirror(result[i]); 707 result[i] = MakeMirror(result[i]);
735 } 708 }
736 709
737 return result; 710 return result;
738 }; 711 };
739 712
740 713
741 ObjectMirror.prototype.fillJSONProperties_ = function(content, kind, name, detai ls) {
742 var propertyNames = this.propertyNames(kind);
743 var x = new Array(propertyNames.length);
744 for (var i = 0; i < propertyNames.length; i++) {
745 x[i] = this.property(propertyNames[i]).toJSONProtocol(details);
746 }
747 content.push(MakeJSONPair_(name || 'properties', ArrayToJSONArray_(x)));
748 };
749
750
751 ObjectMirror.prototype.fillJSONInterceptorProperties_ = function(content, kind, name, details) {
752 var propertyNames = this.interceptorPropertyNames(kind);
753 var x = new Array(propertyNames.length);
754 for (var i = 0; i < propertyNames.length; i++) {
755 x[i] = properties[i].toJSONProtocol(details);
756 }
757 content.push(MakeJSONPair_(name || 'interceptorProperties', ArrayToJSONArray_( x)));
758 };
759
760
761 ObjectMirror.prototype.fillJSON_ = function(content, details, propertiesKind, in terceptorPropertiesKind) {
762 ObjectMirror.super_.fillJSONType_.call(this, content);
763 content.push(MakeJSONPair_('className', StringToJSON_(this.className())));
764 if (details) {
765 content.push(MakeJSONPair_('constructorFunction', this.constructorFunction() .toJSONProtocol(false)));
766 content.push(MakeJSONPair_('protoObject', this.protoObject().toJSONProtocol( false)));
767 content.push(MakeJSONPair_('prototypeObject', this.prototypeObject().toJSONP rotocol(false)));
768 }
769 if (details) {
770 this.fillJSONProperties_(content, propertiesKind)
771 if (interceptorPropertiesKind) {
772 this.fillJSONInterceptorProperties_(content, interceptorPropertiesKind)
773 }
774 }
775 if (this.hasNamedInterceptor()) {
776 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true)));
777 }
778 if (this.hasIndexedInterceptor()) {
779 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true)));
780 }
781 };
782
783
784 ObjectMirror.prototype.toText = function() { 714 ObjectMirror.prototype.toText = function() {
785 var name; 715 var name;
786 var ctor = this.constructorFunction(); 716 var ctor = this.constructorFunction();
787 if (ctor.isUndefined()) { 717 if (ctor.isUndefined()) {
788 name = this.className(); 718 name = this.className();
789 } else { 719 } else {
790 name = ctor.name(); 720 name = ctor.name();
791 if (!name) { 721 if (!name) {
792 name = this.className(); 722 name = this.className();
793 } 723 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 result[i] = MakeMirror(result[i]); 807 result[i] = MakeMirror(result[i]);
878 } 808 }
879 809
880 return result; 810 return result;
881 } else { 811 } else {
882 return []; 812 return [];
883 } 813 }
884 }; 814 };
885 815
886 816
887 FunctionMirror.prototype.fillJSON_ = function(content, details) {
888 // Fill JSON properties from parent (ObjectMirror).
889 FunctionMirror.super_.fillJSON_.call(this, content, details);
890 // Add function specific properties.
891 content.push(MakeJSONPair_('name', StringToJSON_(this.name())));
892 content.push(MakeJSONPair_('resolved', BooleanToJSON_(this.resolved())));
893 if (details && this.resolved()) {
894 content.push(MakeJSONPair_('source', StringToJSON_(this.source())));
895 }
896 if (this.script()) {
897 content.push(MakeJSONPair_('script', this.script().toJSONProtocol()));
898 }
899 }
900
901
902 FunctionMirror.prototype.toText = function() { 817 FunctionMirror.prototype.toText = function() {
903 return this.source(); 818 return this.source();
904 } 819 }
905 820
906 821
907 /** 822 /**
908 * Mirror object for unresolved functions. 823 * Mirror object for unresolved functions.
909 * @param {string} value The name for the unresolved function reflected by this 824 * @param {string} value The name for the unresolved function reflected by this
910 * mirror. 825 * mirror.
911 * @constructor 826 * @constructor
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 value = new PropertyMirror(this, i, details[0], details[1]); 896 value = new PropertyMirror(this, i, details[0], details[1]);
982 } else { 897 } else {
983 value = new UndefinedMirror(); 898 value = new UndefinedMirror();
984 } 899 }
985 values[i - from_index] = value; 900 values[i - from_index] = value;
986 } 901 }
987 return values; 902 return values;
988 } 903 }
989 904
990 905
991 ArrayMirror.prototype.fillJSON_ = function(content, details) {
992 // Fill JSON as for parent (ObjectMirror) but just with named properties.
993 ArrayMirror.super_.fillJSON_.call(this, content, details, PropertyKind.Named);
994 // Fill indexed properties seperately.
995 if (details) {
996 this.fillJSONProperties_(content, PropertyKind.Indexed, 'indexedProperties')
997 }
998 // Add the array length.
999 content.push(MakeJSONPair_('length', NumberToJSON_(this.length())));
1000 }
1001
1002
1003 /** 906 /**
1004 * Mirror object for dates. 907 * Mirror object for dates.
1005 * @param {Date} value The Date object reflected by this mirror 908 * @param {Date} value The Date object reflected by this mirror
1006 * @constructor 909 * @constructor
1007 * @extends ObjectMirror 910 * @extends ObjectMirror
1008 */ 911 */
1009 function DateMirror(value) { 912 function DateMirror(value) {
1010 ObjectMirror.call(this, value); 913 ObjectMirror.call(this, value);
1011 } 914 }
1012 inherits(DateMirror, ObjectMirror); 915 inherits(DateMirror, ObjectMirror);
1013 916
1014 917
1015 DateMirror.prototype.fillJSON_ = function(content, details) {
1016 // Fill JSON properties from parent (ObjectMirror).
1017 DateMirror.super_.fillJSON_.call(this, content, details);
1018 // Add date specific properties.
1019 content.push(MakeJSONPair_('value', DateToJSON_(this.value_)));
1020 }
1021
1022
1023 DateMirror.prototype.toText = function() { 918 DateMirror.prototype.toText = function() {
1024 return DateToISO8601_(this.value_); 919 return DateToISO8601_(this.value_);
1025 } 920 }
1026 921
1027 922
1028 /** 923 /**
1029 * Mirror object for regular expressions. 924 * Mirror object for regular expressions.
1030 * @param {RegExp} value The RegExp object reflected by this mirror 925 * @param {RegExp} value The RegExp object reflected by this mirror
1031 * @constructor 926 * @constructor
1032 * @extends ObjectMirror 927 * @extends ObjectMirror
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 961
1067 /** 962 /**
1068 * Returns whether this regular expression has the multiline (m) flag set. 963 * Returns whether this regular expression has the multiline (m) flag set.
1069 * @return {boolean} Value of the multiline flag 964 * @return {boolean} Value of the multiline flag
1070 */ 965 */
1071 RegExpMirror.prototype.multiline = function() { 966 RegExpMirror.prototype.multiline = function() {
1072 return this.value_.multiline; 967 return this.value_.multiline;
1073 }; 968 };
1074 969
1075 970
1076 RegExpMirror.prototype.fillJSON_ = function(content, details) {
1077 // Fill JSON properties from parent (ObjectMirror).
1078 RegExpMirror.super_.fillJSON_.call(this, content, details);
1079 // Add regexp specific properties.
1080 content.push(MakeJSONPair_('source', StringToJSON_(this.source())));
1081 content.push(MakeJSONPair_('global', BooleanToJSON_(this.global())));
1082 content.push(MakeJSONPair_('ignoreCase', BooleanToJSON_(this.ignoreCase())));
1083 content.push(MakeJSONPair_('multiline', BooleanToJSON_(this.multiline())));
1084 }
1085
1086
1087 RegExpMirror.prototype.toText = function() { 971 RegExpMirror.prototype.toText = function() {
1088 // Simpel to text which is used when on specialization in subclass. 972 // Simpel to text which is used when on specialization in subclass.
1089 return "/" + this.source() + "/"; 973 return "/" + this.source() + "/";
1090 } 974 }
1091 975
1092 976
1093 /** 977 /**
1094 * Mirror object for error objects. 978 * Mirror object for error objects.
1095 * @param {Error} value The error object reflected by this mirror 979 * @param {Error} value The error object reflected by this mirror
1096 * @constructor 980 * @constructor
1097 * @extends ObjectMirror 981 * @extends ObjectMirror
1098 */ 982 */
1099 function ErrorMirror(value) { 983 function ErrorMirror(value) {
1100 ObjectMirror.call(this, value, ERROR_TYPE); 984 ObjectMirror.call(this, value, ERROR_TYPE);
1101 } 985 }
1102 inherits(ErrorMirror, ObjectMirror); 986 inherits(ErrorMirror, ObjectMirror);
1103 987
1104 988
1105 /** 989 /**
1106 * Returns the message for this eror object. 990 * Returns the message for this eror object.
1107 * @return {string or undefined} The message for this eror object 991 * @return {string or undefined} The message for this eror object
1108 */ 992 */
1109 ErrorMirror.prototype.message = function() { 993 ErrorMirror.prototype.message = function() {
1110 return this.value_.message; 994 return this.value_.message;
1111 }; 995 };
1112 996
1113 997
1114 ErrorMirror.prototype.fillJSON_ = function(content, details) {
1115 // Fill JSON properties from parent (ObjectMirror).
1116 ErrorMirror.super_.fillJSON_.call(this, content, details);
1117 // Add error specific properties.
1118 content.push(MakeJSONPair_('message', StringToJSON_(this.message())));
1119 }
1120
1121
1122 ErrorMirror.prototype.toText = function() { 998 ErrorMirror.prototype.toText = function() {
1123 // Use the same text representation as in messages.js. 999 // Use the same text representation as in messages.js.
1124 var text; 1000 var text;
1125 try { 1001 try {
1126 str = builtins.ToDetailString(this.value_); 1002 str = builtins.ToDetailString(this.value_);
1127 } catch (e) { 1003 } catch (e) {
1128 str = '#<an Error>'; 1004 str = '#<an Error>';
1129 } 1005 }
1130 return str; 1006 return str;
1131 } 1007 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 PropertyMirror.prototype.propertyType = function() { 1075 PropertyMirror.prototype.propertyType = function() {
1200 return %DebugPropertyTypeFromDetails(this.details_); 1076 return %DebugPropertyTypeFromDetails(this.details_);
1201 } 1077 }
1202 1078
1203 1079
1204 PropertyMirror.prototype.insertionIndex = function() { 1080 PropertyMirror.prototype.insertionIndex = function() {
1205 return %DebugPropertyIndexFromDetails(this.details_); 1081 return %DebugPropertyIndexFromDetails(this.details_);
1206 } 1082 }
1207 1083
1208 1084
1209 PropertyMirror.prototype.fillJSON_ = function(content, details) {
1210 content.push(MakeJSONPair_('name', StringToJSON_(this.name())));
1211 content.push(MakeJSONPair_('value', this.value().toJSONProtocol(details)));
1212 if (this.attributes() != PropertyAttribute.None) {
1213 content.push(MakeJSONPair_('attributes', NumberToJSON_(this.attributes())));
1214 }
1215 if (this.propertyType() != PropertyType.Normal) {
1216 content.push(MakeJSONPair_('propertyType', NumberToJSON_(this.propertyType() )));
1217 }
1218 }
1219
1220
1221 /** 1085 /**
1222 * Mirror object for interceptor named properties. 1086 * Mirror object for interceptor named properties.
1223 * @param {ObjectMirror} mirror The mirror object having this property 1087 * @param {ObjectMirror} mirror The mirror object having this property
1224 * @param {String} name The name of the property 1088 * @param {String} name The name of the property
1225 * @param {value} value The value of the property 1089 * @param {value} value The value of the property
1226 * @constructor 1090 * @constructor
1227 * @extends PropertyMirror 1091 * @extends PropertyMirror
1228 */ 1092 */
1229 function InterceptorPropertyMirror(mirror, name, value) { 1093 function InterceptorPropertyMirror(mirror, name, value) {
1230 PropertyMirror.call(this, mirror, name, value, PropertyType.Interceptor); 1094 PropertyMirror.call(this, mirror, name, value, PropertyType.Interceptor);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 /** 1135 /**
1272 * Returns a mirror for the function of a non native setter. 1136 * Returns a mirror for the function of a non native setter.
1273 * @return {FunctionMirror} Function mirror for the getter set using 1137 * @return {FunctionMirror} Function mirror for the getter set using
1274 * __defineSetter__. 1138 * __defineSetter__.
1275 */ 1139 */
1276 AccessorMirror.prototype.setter = function(details) { 1140 AccessorMirror.prototype.setter = function(details) {
1277 return MakeMirror(this.setter_); 1141 return MakeMirror(this.setter_);
1278 } 1142 }
1279 1143
1280 1144
1281 /**
1282 * Serialize the accessor mirror into JSON format. For accessor it has the
1283 * following format.
1284 * {"type":"accessor",
1285 "native:"<boolean>,
1286 "getter":<function mirror JSON serialization>,
1287 "setter":<function mirror JSON serialization>}
1288 * For specialized mirrors inheriting from the base Mirror
1289 * @param {boolean} details Indicate level of details to include
1290 * @return {string} JSON serialization
1291 */
1292 AccessorMirror.prototype.fillJSON_ = function(content, details) {
1293 AccessorMirror.super_.fillJSONType_.call(this, content);
1294 if (this.isNative()) {
1295 content.push(MakeJSONPair_('native', BooleanToJSON_(true)));
1296 } else {
1297 content.push(MakeJSONPair_('getter', this.getter().toJSONProtocol(false)));
1298 content.push(MakeJSONPair_('setter', this.setter().toJSONProtocol(false)));
1299 }
1300 }
1301
1302
1303 const kFrameDetailsFrameIdIndex = 0; 1145 const kFrameDetailsFrameIdIndex = 0;
1304 const kFrameDetailsReceiverIndex = 1; 1146 const kFrameDetailsReceiverIndex = 1;
1305 const kFrameDetailsFunctionIndex = 2; 1147 const kFrameDetailsFunctionIndex = 2;
1306 const kFrameDetailsArgumentCountIndex = 3; 1148 const kFrameDetailsArgumentCountIndex = 3;
1307 const kFrameDetailsLocalCountIndex = 4; 1149 const kFrameDetailsLocalCountIndex = 4;
1308 const kFrameDetailsSourcePositionIndex = 5; 1150 const kFrameDetailsSourcePositionIndex = 5;
1309 const kFrameDetailsConstructCallIndex = 6; 1151 const kFrameDetailsConstructCallIndex = 6;
1310 const kFrameDetailsDebuggerFrameIndex = 7; 1152 const kFrameDetailsDebuggerFrameIndex = 7;
1311 const kFrameDetailsFirstDynamicIndex = 8; 1153 const kFrameDetailsFirstDynamicIndex = 8;
1312 1154
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 }; 1393 };
1552 1394
1553 1395
1554 FrameMirror.prototype.evaluate = function(source, disable_break) { 1396 FrameMirror.prototype.evaluate = function(source, disable_break) {
1555 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), 1397 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(),
1556 source, Boolean(disable_break)); 1398 source, Boolean(disable_break));
1557 return MakeMirror(result); 1399 return MakeMirror(result);
1558 }; 1400 };
1559 1401
1560 1402
1561 FrameMirror.prototype.fillJSON_ = function(content, details) {
1562 FrameMirror.super_.fillJSONType_.call(this, content);
1563 content.push(MakeJSONPair_('index', NumberToJSON_(this.index())));
1564 content.push(MakeJSONPair_('receiver', this.receiver().toJSONProtocol(false))) ;
1565 content.push(MakeJSONPair_('func', this.func().toJSONProtocol(false)));
1566 content.push(MakeJSONPair_('constructCall', BooleanToJSON_(this.isConstructCal l())));
1567 content.push(MakeJSONPair_('debuggerFrame', BooleanToJSON_(this.isDebuggerFram e())));
1568 var x = new Array(this.argumentCount());
1569 for (var i = 0; i < this.argumentCount(); i++) {
1570 arg = new Array();
1571 var argument_name = this.argumentName(i)
1572 if (argument_name) {
1573 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name)));
1574 }
1575 arg.push(MakeJSONPair_('value', this.argumentValue(i).toJSONProtocol(false)) );
1576 x[i] = ArrayToJSONObject_(arg);
1577 }
1578 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x)));
1579 var x = new Array(this.localCount());
1580 for (var i = 0; i < this.localCount(); i++) {
1581 var name = MakeJSONPair_('name', StringToJSON_(this.localName(i)));
1582 var value = MakeJSONPair_('value', this.localValue(i).toJSONProtocol(false)) ;
1583 x[i] = '{' + name + ',' + value + '}';
1584 }
1585 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x)));
1586 content.push(MakeJSONPair_('position', NumberToJSON_(this.sourcePosition())));
1587 var line = this.sourceLine();
1588 if (!IS_UNDEFINED(line)) {
1589 content.push(MakeJSONPair_('line', NumberToJSON_(line)));
1590 }
1591 var column = this.sourceColumn();
1592 if (!IS_UNDEFINED(column)) {
1593 content.push(MakeJSONPair_('column', NumberToJSON_(column)));
1594 }
1595 var source_line_text = this.sourceLineText();
1596 if (!IS_UNDEFINED(source_line_text)) {
1597 content.push(MakeJSONPair_('sourceLineText', StringToJSON_(source_line_text) ));
1598 }
1599 }
1600
1601
1602 FrameMirror.prototype.invocationText = function() { 1403 FrameMirror.prototype.invocationText = function() {
1603 // Format frame invoaction (receiver, function and arguments). 1404 // Format frame invoaction (receiver, function and arguments).
1604 var result = ''; 1405 var result = '';
1605 var func = this.func(); 1406 var func = this.func();
1606 var receiver = this.receiver(); 1407 var receiver = this.receiver();
1607 if (this.isConstructCall()) { 1408 if (this.isConstructCall()) {
1608 // For constructor frames display new followed by the function name. 1409 // For constructor frames display new followed by the function name.
1609 result += 'new '; 1410 result += 'new ';
1610 result += func.name() ? func.name() : '[anonymous]'; 1411 result += func.name() ? func.name() : '[anonymous]';
1611 } else if (this.isDebuggerFrame()) { 1412 } else if (this.isDebuggerFrame()) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 ScriptMirror.prototype.locationFromPosition = function(position) { 1577 ScriptMirror.prototype.locationFromPosition = function(position) {
1777 return this.script_.locationFromPosition(position); 1578 return this.script_.locationFromPosition(position);
1778 } 1579 }
1779 1580
1780 1581
1781 ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) { 1582 ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) {
1782 return this.script_.sourceSlice(opt_from_line, opt_to_line); 1583 return this.script_.sourceSlice(opt_from_line, opt_to_line);
1783 } 1584 }
1784 1585
1785 1586
1786 ScriptMirror.prototype.fillJSON_ = function(content, details) {
1787 ScriptMirror.super_.fillJSONType_.call(this, content);
1788 if (this.name()) {
1789 content.push(MakeJSONPair_('name', StringToJSON_(this.name())));
1790 }
1791 content.push(MakeJSONPair_('lineOffset', NumberToJSON_(this.lineOffset())));
1792 content.push(MakeJSONPair_('columnOffset', NumberToJSON_(this.columnOffset())) );
1793 content.push(MakeJSONPair_('lineCount', NumberToJSON_(this.lineCount())));
1794 content.push(MakeJSONPair_('scriptType', NumberToJSON_(this.scriptType())));
1795 }
1796
1797
1798 ScriptMirror.prototype.toText = function() { 1587 ScriptMirror.prototype.toText = function() {
1799 var result = ''; 1588 var result = '';
1800 result += this.name(); 1589 result += this.name();
1801 result += ' (lines: '; 1590 result += ' (lines: ';
1802 if (this.lineOffset() > 0) { 1591 if (this.lineOffset() > 0) {
1803 result += this.lineOffset(); 1592 result += this.lineOffset();
1804 result += '-'; 1593 result += '-';
1805 result += this.lineOffset() + this.lineCount() - 1; 1594 result += this.lineOffset() + this.lineCount() - 1;
1806 } else { 1595 } else {
1807 result += this.lineCount(); 1596 result += this.lineCount();
1808 } 1597 }
1809 result += ')'; 1598 result += ')';
1810 return result; 1599 return result;
1811 } 1600 }
1812 1601
1813 1602
1603 function JSONProtocolSerializer(details) {
1604 this.details_ = details;
1605 }
1606
1607
1608 JSONProtocolSerializer.prototype.serialize = function(mirror) {
1609 // Collect the JSON property/value pairs in a array.
1610 var content = new Array();
1611
1612 // Always add the type
1613 content.push(MakeJSONPair_('type', StringToJSON_(mirror.type())));
1614
1615 switch (mirror.type()) {
1616 case UNDEFINED_TYPE:
1617 case NULL_TYPE:
1618 // Undefined and null are represented just by their type.
1619 break;
1620
1621 case BOOLEAN_TYPE:
1622 // Boolean values are simply represented by their value.
1623 content.push(MakeJSONPair_('value', BooleanToJSON_(mirror.value())));
1624 break;
1625
1626 case NUMBER_TYPE:
1627 // Number values are simply represented by their value.
1628 content.push(MakeJSONPair_('value', NumberToJSON_(mirror.value())));
1629 break;
1630
1631 case STRING_TYPE:
1632 // String values might have their value cropped to keep down size.
1633 if (mirror.length() > kMaxProtocolStringLength) {
1634 var str = mirror.value().substring(0, kMaxProtocolStringLength);
1635 content.push(MakeJSONPair_('value', StringToJSON_(str)));
1636 content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0)));
1637 content.push(MakeJSONPair_('toIndex',
1638 NumberToJSON_(kMaxProtocolStringLength)));
1639 } else {
1640 content.push(MakeJSONPair_('value', StringToJSON_(mirror.value())));
1641 }
1642 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length())));
1643 break;
1644
1645 case OBJECT_TYPE:
1646 case FUNCTION_TYPE:
1647 case ERROR_TYPE:
1648 case REGEXP_TYPE:
1649 // Add object representation.
1650 this.serializeObject_(mirror, content);
1651 break;
1652
1653 case PROPERTY_TYPE:
1654 // Properties are represented by name, value, attributes and type.
1655 content.push(MakeJSONPair_('name',
1656 StringToJSON_(mirror.name())));
1657 content.push(MakeJSONPair_('value',
1658 mirror.value().toJSONProtocol(this.details_)));
1659 if (mirror.attributes() != PropertyAttribute.None) {
1660 content.push(MakeJSONPair_('attributes',
1661 NumberToJSON_(mirror.attributes())));
1662 }
1663 if (mirror.propertyType() != PropertyType.Normal) {
1664 content.push(MakeJSONPair_('propertyType',
1665 NumberToJSON_(mirror.propertyType())));
1666 }
1667 break;
1668
1669 case ACCESSOR_TYPE:
1670 // An accessor can either be native or defined through JavaScript.
1671 if (mirror.isNative()) {
1672 content.push(MakeJSONPair_('native', BooleanToJSON_(true)));
1673 } else {
1674 content.push(MakeJSONPair_('getter',
1675 mirror.getter().toJSONProtocol(false)));
1676 content.push(MakeJSONPair_('setter',
1677 mirror.setter().toJSONProtocol(false)));
1678 }
1679 break;
1680
1681 case FRAME_TYPE:
1682 // Add object representation.
1683 this.serializeFrame_(mirror, content);
1684 break;
1685
1686 case SCRIPT_TYPE:
1687 // Script is represented by name and source attributes.
1688 if (mirror.name()) {
1689 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name())));
1690 }
1691 content.push(MakeJSONPair_('lineOffset',
1692 NumberToJSON_(mirror.lineOffset())));
1693 content.push(MakeJSONPair_('columnOffset',
1694 NumberToJSON_(mirror.columnOffset())));
1695 content.push(MakeJSONPair_('lineCount',
1696 NumberToJSON_(mirror.lineCount())));
1697 content.push(MakeJSONPair_('scriptType',
1698 NumberToJSON_(mirror.scriptType())));
1699 break;
1700
1701 }
1702
1703 // Always add the text representation.
1704 content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText())));
1705
1706 // Create and return the JSON string.
1707 return ArrayToJSONObject_(content);
1708 }
1709
1710
1711 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content) {
1712 content.push(MakeJSONPair_('className',
1713 StringToJSON_(mirror.className())));
1714
1715 if (this.details_) {
1716 content.push(MakeJSONPair_('constructorFunction',
1717 mirror.constructorFunction().toJSONProtocol(false)));
1718 content.push(MakeJSONPair_('protoObject',
1719 mirror.protoObject().toJSONProtocol(false)));
1720 content.push(MakeJSONPair_('prototypeObject',
1721 mirror.prototypeObject().toJSONProtocol(false)));
1722
1723 // Add properties. For arrays don't include indexed proeprties.
1724 var kind = PropertyKind.Named;
1725 if (!mirror.isArray()) {
1726 kind |= PropertyKind.Indexed
1727 }
1728 var propertyNames = mirror.propertyNames(kind);
1729 var x = new Array(propertyNames.length);
1730 for (var i = 0; i < propertyNames.length; i++) {
1731 x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false);
1732 }
1733 content.push(MakeJSONPair_('properties', ArrayToJSONArray_(x)));
1734
1735 // Add interceptor properties.
1736 propertyNames = mirror.interceptorPropertyNames();
1737 var x = new Array(propertyNames.length);
1738 for (var i = 0; i < propertyNames.length; i++) {
1739 x[i] = properties[i].toJSONProtocol(details);
1740 }
1741 content.push(MakeJSONPair_('interceptorProperties', ArrayToJSONArray_(x)));
1742
1743 // For arrays the indexed properties are added separately and the length is
1744 // added as well.
1745 if (mirror.isArray()) {
1746 var propertyNames = mirror.propertyNames(PropertyKind.Indexed);
1747 var x = new Array(propertyNames.length);
1748 for (var i = 0; i < propertyNames.length; i++) {
1749 x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false);
1750 }
1751 content.push(MakeJSONPair_('indexedProperties', ArrayToJSONArray_(x)));
1752
1753 // Add the array length.
1754 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length())));
1755 }
1756 }
1757
1758 if (mirror.hasNamedInterceptor()) {
1759 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true)));
1760 }
1761
1762 if (mirror.hasIndexedInterceptor()) {
1763 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true)));
1764 }
1765
1766 if (mirror.isFunction()) {
1767 // Add function specific properties.
1768 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name())));
1769 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved())));
1770 if (this.details_ && mirror.resolved()) {
1771 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
1772 }
1773 if (mirror.script()) {
1774 content.push(MakeJSONPair_('script', mirror.script().toJSONProtocol()));
1775 }
1776 } else if (mirror.isDate()) {
1777 // Add date specific properties.
1778 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value())));
1779 } else if (mirror.isRegExp()) {
1780 // Add regexp specific properties.
1781 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
1782 content.push(MakeJSONPair_('global', BooleanToJSON_(mirror.global())));
1783 content.push(MakeJSONPair_('ignoreCase',
1784 BooleanToJSON_(mirror.ignoreCase())));
1785 content.push(MakeJSONPair_('multiline',
1786 BooleanToJSON_(mirror.multiline())));
1787 } else if (mirror.isError()) {
1788 // Add error specific properties.
1789 content.push(MakeJSONPair_('message', StringToJSON_(mirror.message())));
1790 }
1791 }
1792
1793
1794 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
1795 content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index())));
1796 content.push(MakeJSONPair_('receiver',
1797 mirror.receiver().toJSONProtocol(false)));
1798 content.push(MakeJSONPair_('func', mirror.func().toJSONProtocol(false)));
1799 content.push(MakeJSONPair_('constructCall',
1800 BooleanToJSON_(mirror.isConstructCall())));
1801 content.push(MakeJSONPair_('debuggerFrame',
1802 BooleanToJSON_(mirror.isDebuggerFrame())));
1803 var x = new Array(mirror.argumentCount());
1804 for (var i = 0; i < mirror.argumentCount(); i++) {
1805 arg = new Array();
1806 var argument_name = mirror.argumentName(i)
1807 if (argument_name) {
1808 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name)));
1809 }
1810 arg.push(MakeJSONPair_('value',
1811 mirror.argumentValue(i).toJSONProtocol(false)));
1812 x[i] = ArrayToJSONObject_(arg);
1813 }
1814 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x)));
1815 var x = new Array(mirror.localCount());
1816 for (var i = 0; i < mirror.localCount(); i++) {
1817 var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i)));
1818 var value = MakeJSONPair_('value',
1819 mirror.localValue(i).toJSONProtocol(false));
1820 x[i] = '{' + name + ',' + value + '}';
1821 }
1822 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x)));
1823 content.push(MakeJSONPair_('position',
1824 NumberToJSON_(mirror.sourcePosition())));
1825 var line = mirror.sourceLine();
1826 if (!IS_UNDEFINED(line)) {
1827 content.push(MakeJSONPair_('line', NumberToJSON_(line)));
1828 }
1829 var column = mirror.sourceColumn();
1830 if (!IS_UNDEFINED(column)) {
1831 content.push(MakeJSONPair_('column', NumberToJSON_(column)));
1832 }
1833 var source_line_text = mirror.sourceLineText();
1834 if (!IS_UNDEFINED(source_line_text)) {
1835 content.push(MakeJSONPair_('sourceLineText',
1836 StringToJSON_(source_line_text)));
1837 }
1838 }
1839
1840
1814 function MakeJSONPair_(name, value) { 1841 function MakeJSONPair_(name, value) {
1815 return '"' + name + '":' + value; 1842 return '"' + name + '":' + value;
1816 } 1843 }
1817 1844
1818 1845
1819 function ArrayToJSONObject_(content) { 1846 function ArrayToJSONObject_(content) {
1820 return '{' + content.join(',') + '}'; 1847 return '{' + content.join(',') + '}';
1821 } 1848 }
1822 1849
1823 1850
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 /** 1942 /**
1916 * Convert a Date to ISO 8601 format. To avoid depending on the Date object 1943 * Convert a Date to ISO 8601 format. To avoid depending on the Date object
1917 * this method calls the functions in date.js directly and not through the 1944 * this method calls the functions in date.js directly and not through the
1918 * value. 1945 * value.
1919 * @param {Date} value The Date value to format as JSON 1946 * @param {Date} value The Date value to format as JSON
1920 * @return {string} JSON formatted Date value 1947 * @return {string} JSON formatted Date value
1921 */ 1948 */
1922 function DateToJSON_(value) { 1949 function DateToJSON_(value) {
1923 return '"' + DateToISO8601_(value) + '"'; 1950 return '"' + DateToISO8601_(value) + '"';
1924 } 1951 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/mirror-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698