OLD | NEW |
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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 function StringMirror(value) { | 546 function StringMirror(value) { |
547 ValueMirror.call(this, STRING_TYPE, value); | 547 ValueMirror.call(this, STRING_TYPE, value); |
548 } | 548 } |
549 inherits(StringMirror, ValueMirror); | 549 inherits(StringMirror, ValueMirror); |
550 | 550 |
551 | 551 |
552 StringMirror.prototype.length = function() { | 552 StringMirror.prototype.length = function() { |
553 return this.value_.length; | 553 return this.value_.length; |
554 }; | 554 }; |
555 | 555 |
| 556 StringMirror.prototype.getTruncatedValue = function(maxLength) { |
| 557 if (maxLength != -1 && this.length() > maxLength) { |
| 558 return this.value_.substring(0, maxLength) + |
| 559 '... (length: ' + this.length() + ')'; |
| 560 } |
| 561 return this.value_; |
| 562 } |
556 | 563 |
557 StringMirror.prototype.toText = function() { | 564 StringMirror.prototype.toText = function() { |
558 if (this.length() > kMaxProtocolStringLength) { | 565 return this.getTruncatedValue(kMaxProtocolStringLength); |
559 return this.value_.substring(0, kMaxProtocolStringLength) + | |
560 '... (length: ' + this.length() + ')'; | |
561 } else { | |
562 return this.value_; | |
563 } | |
564 } | 566 } |
565 | 567 |
566 | 568 |
567 /** | 569 /** |
568 * Mirror object for objects. | 570 * Mirror object for objects. |
569 * @param {object} value The object reflected by this mirror | 571 * @param {object} value The object reflected by this mirror |
570 * @param {boolean} transient indicate whether this object is transient with a | 572 * @param {boolean} transient indicate whether this object is transient with a |
571 * transient handle | 573 * transient handle |
572 * @constructor | 574 * @constructor |
573 * @extends ValueMirror | 575 * @extends ValueMirror |
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 JSONProtocolSerializer.prototype.includeSource_ = function() { | 1950 JSONProtocolSerializer.prototype.includeSource_ = function() { |
1949 return this.options_ && this.options_.includeSource; | 1951 return this.options_ && this.options_.includeSource; |
1950 } | 1952 } |
1951 | 1953 |
1952 | 1954 |
1953 JSONProtocolSerializer.prototype.inlineRefs_ = function() { | 1955 JSONProtocolSerializer.prototype.inlineRefs_ = function() { |
1954 return this.options_ && this.options_.inlineRefs; | 1956 return this.options_ && this.options_.inlineRefs; |
1955 } | 1957 } |
1956 | 1958 |
1957 | 1959 |
| 1960 JSONProtocolSerializer.prototype.maxStringLength_ = function() { |
| 1961 if (IS_UNDEFINED(this.options_) || |
| 1962 IS_UNDEFINED(this.options_.maxStringLength)) { |
| 1963 return kMaxProtocolStringLength; |
| 1964 } |
| 1965 return this.options_.maxStringLength; |
| 1966 } |
| 1967 |
| 1968 |
1958 JSONProtocolSerializer.prototype.add_ = function(mirror) { | 1969 JSONProtocolSerializer.prototype.add_ = function(mirror) { |
1959 // If this mirror is already in the list just return. | 1970 // If this mirror is already in the list just return. |
1960 for (var i = 0; i < this.mirrors_.length; i++) { | 1971 for (var i = 0; i < this.mirrors_.length; i++) { |
1961 if (this.mirrors_[i] === mirror) { | 1972 if (this.mirrors_[i] === mirror) { |
1962 return; | 1973 return; |
1963 } | 1974 } |
1964 } | 1975 } |
1965 | 1976 |
1966 // Add the mirror to the list of mirrors to be serialized. | 1977 // Add the mirror to the list of mirrors to be serialized. |
1967 this.mirrors_.push(mirror); | 1978 this.mirrors_.push(mirror); |
(...skipping 12 matching lines...) Expand all Loading... |
1980 o.ref = mirror.handle(); | 1991 o.ref = mirror.handle(); |
1981 o.type = mirror.type(); | 1992 o.type = mirror.type(); |
1982 switch (mirror.type()) { | 1993 switch (mirror.type()) { |
1983 case UNDEFINED_TYPE: | 1994 case UNDEFINED_TYPE: |
1984 case NULL_TYPE: | 1995 case NULL_TYPE: |
1985 case BOOLEAN_TYPE: | 1996 case BOOLEAN_TYPE: |
1986 case NUMBER_TYPE: | 1997 case NUMBER_TYPE: |
1987 o.value = mirror.value(); | 1998 o.value = mirror.value(); |
1988 break; | 1999 break; |
1989 case STRING_TYPE: | 2000 case STRING_TYPE: |
1990 // Limit string length. | 2001 o.value = mirror.getTruncatedValue(this.maxStringLength_()); |
1991 o.value = mirror.toText(); | |
1992 break; | 2002 break; |
1993 case FUNCTION_TYPE: | 2003 case FUNCTION_TYPE: |
1994 o.name = mirror.name(); | 2004 o.name = mirror.name(); |
1995 o.inferredName = mirror.inferredName(); | 2005 o.inferredName = mirror.inferredName(); |
1996 if (mirror.script()) { | 2006 if (mirror.script()) { |
1997 o.scriptId = mirror.script().id(); | 2007 o.scriptId = mirror.script().id(); |
1998 } | 2008 } |
1999 break; | 2009 break; |
2000 case ERROR_TYPE: | 2010 case ERROR_TYPE: |
2001 case REGEXP_TYPE: | 2011 case REGEXP_TYPE: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 content.value = mirror.value(); | 2055 content.value = mirror.value(); |
2046 break; | 2056 break; |
2047 | 2057 |
2048 case NUMBER_TYPE: | 2058 case NUMBER_TYPE: |
2049 // Number values are simply represented by their value. | 2059 // Number values are simply represented by their value. |
2050 content.value = NumberToJSON_(mirror.value()); | 2060 content.value = NumberToJSON_(mirror.value()); |
2051 break; | 2061 break; |
2052 | 2062 |
2053 case STRING_TYPE: | 2063 case STRING_TYPE: |
2054 // String values might have their value cropped to keep down size. | 2064 // String values might have their value cropped to keep down size. |
2055 if (mirror.length() > kMaxProtocolStringLength) { | 2065 if (this.maxStringLength_() != -1 && |
2056 var str = mirror.value().substring(0, kMaxProtocolStringLength); | 2066 mirror.length() > this.maxStringLength_()) { |
| 2067 var str = mirror.getTruncatedValue(this.maxStringLength_()); |
2057 content.value = str; | 2068 content.value = str; |
2058 content.fromIndex = 0; | 2069 content.fromIndex = 0; |
2059 content.toIndex = kMaxProtocolStringLength; | 2070 content.toIndex = this.maxStringLength_(); |
2060 } else { | 2071 } else { |
2061 content.value = mirror.value(); | 2072 content.value = mirror.value(); |
2062 } | 2073 } |
2063 content.length = mirror.length(); | 2074 content.length = mirror.length(); |
2064 break; | 2075 break; |
2065 | 2076 |
2066 case OBJECT_TYPE: | 2077 case OBJECT_TYPE: |
2067 case FUNCTION_TYPE: | 2078 case FUNCTION_TYPE: |
2068 case ERROR_TYPE: | 2079 case ERROR_TYPE: |
2069 case REGEXP_TYPE: | 2080 case REGEXP_TYPE: |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 } | 2360 } |
2350 if (!isFinite(value)) { | 2361 if (!isFinite(value)) { |
2351 if (value > 0) { | 2362 if (value > 0) { |
2352 return 'Infinity'; | 2363 return 'Infinity'; |
2353 } else { | 2364 } else { |
2354 return '-Infinity'; | 2365 return '-Infinity'; |
2355 } | 2366 } |
2356 } | 2367 } |
2357 return value; | 2368 return value; |
2358 } | 2369 } |
OLD | NEW |