| 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 15 matching lines...) Expand all Loading... |
| 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 var next_handle_ = 0; |
| 37 var mirror_cache_ = []; |
| 38 |
| 39 /** |
| 40 * Clear the mirror handle cache. |
| 41 */ |
| 42 function ClearMirrorCache() { |
| 43 next_handle_ = 0; |
| 44 mirror_cache_ = []; |
| 45 } |
| 46 |
| 47 |
| 36 /** | 48 /** |
| 37 * Returns the mirror for a specified value or object. | 49 * Returns the mirror for a specified value or object. |
| 38 * | 50 * |
| 39 * @param {value or Object} value the value or object to retreive the mirror for | 51 * @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 | 52 * @returns {Mirror} the mirror reflects the passed value or object |
| 41 */ | 53 */ |
| 42 function MakeMirror(value) { | 54 function MakeMirror(value) { |
| 43 if (IS_UNDEFINED(value)) return new UndefinedMirror(); | 55 var mirror; |
| 44 if (IS_NULL(value)) return new NullMirror(); | 56 for (id in mirror_cache_) { |
| 45 if (IS_BOOLEAN(value)) return new BooleanMirror(value); | 57 mirror = mirror_cache_[id]; |
| 46 if (IS_NUMBER(value)) return new NumberMirror(value); | 58 if (mirror.value() === value) { |
| 47 if (IS_STRING(value)) return new StringMirror(value); | 59 return mirror; |
| 48 if (IS_ARRAY(value)) return new ArrayMirror(value); | 60 } |
| 49 if (IS_DATE(value)) return new DateMirror(value); | 61 // Special check for NaN as NaN == NaN is false. |
| 50 if (IS_FUNCTION(value)) return new FunctionMirror(value); | 62 if (mirror.isNumber() && isNaN(mirror.value()) && |
| 51 if (IS_REGEXP(value)) return new RegExpMirror(value); | 63 typeof value == 'number' && isNaN(value)) { |
| 52 if (IS_ERROR(value)) return new ErrorMirror(value); | 64 return mirror; |
| 53 return new ObjectMirror(value); | 65 } |
| 66 } |
| 67 |
| 68 if (IS_UNDEFINED(value)) { |
| 69 mirror = new UndefinedMirror(); |
| 70 } else if (IS_NULL(value)) { |
| 71 mirror = new NullMirror(); |
| 72 } else if (IS_BOOLEAN(value)) { |
| 73 mirror = new BooleanMirror(value); |
| 74 } else if (IS_NUMBER(value)) { |
| 75 mirror = new NumberMirror(value); |
| 76 } else if (IS_STRING(value)) { |
| 77 mirror = new StringMirror(value); |
| 78 } else if (IS_ARRAY(value)) { |
| 79 mirror = new ArrayMirror(value); |
| 80 } else if (IS_DATE(value)) { |
| 81 mirror = new DateMirror(value); |
| 82 } else if (IS_FUNCTION(value)) { |
| 83 mirror = new FunctionMirror(value); |
| 84 } else if (IS_REGEXP(value)) { |
| 85 mirror = new RegExpMirror(value); |
| 86 } else if (IS_ERROR(value)) { |
| 87 mirror = new ErrorMirror(value); |
| 88 } else { |
| 89 mirror = new ObjectMirror(value); |
| 90 } |
| 91 |
| 92 mirror_cache_[mirror.handle()] = mirror; |
| 93 return mirror; |
| 94 } |
| 95 |
| 96 |
| 97 /** |
| 98 * Returns the mirror for a specified mirror handle. |
| 99 * |
| 100 * @param {number} handle the handle to find the mirror for |
| 101 * @returns {Mirror or undefiend} the mirror with the requested handle or |
| 102 * undefined if no mirror with the requested handle was found |
| 103 */ |
| 104 function LookupMirror(handle) { |
| 105 return mirror_cache_[handle]; |
| 106 } |
| 107 |
| 108 |
| 109 /** |
| 110 * Returns the mirror for the undefined value. |
| 111 * |
| 112 * @returns {Mirror} the mirror reflects the undefined value |
| 113 */ |
| 114 function GetUndefinedMirror() { |
| 115 return MakeMirror(void 0); |
| 54 } | 116 } |
| 55 | 117 |
| 56 | 118 |
| 57 /** | 119 /** |
| 58 * Inherit the prototype methods from one constructor into another. | 120 * Inherit the prototype methods from one constructor into another. |
| 59 * | 121 * |
| 60 * The Function.prototype.inherits from lang.js rewritten as a standalone | 122 * The Function.prototype.inherits from lang.js rewritten as a standalone |
| 61 * function (not on Function.prototype). NOTE: If this file is to be loaded | 123 * function (not on Function.prototype). NOTE: If this file is to be loaded |
| 62 * during bootstrapping this function needs to be revritten using some native | 124 * during bootstrapping this function needs to be revritten using some native |
| 63 * functions as prototype setup using normal JavaScript does not work as | 125 * functions as prototype setup using normal JavaScript does not work as |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 const UNDEFINED_TYPE = 'undefined'; | 142 const UNDEFINED_TYPE = 'undefined'; |
| 81 const NULL_TYPE = 'null'; | 143 const NULL_TYPE = 'null'; |
| 82 const BOOLEAN_TYPE = 'boolean'; | 144 const BOOLEAN_TYPE = 'boolean'; |
| 83 const NUMBER_TYPE = 'number'; | 145 const NUMBER_TYPE = 'number'; |
| 84 const STRING_TYPE = 'string'; | 146 const STRING_TYPE = 'string'; |
| 85 const OBJECT_TYPE = 'object'; | 147 const OBJECT_TYPE = 'object'; |
| 86 const FUNCTION_TYPE = 'function'; | 148 const FUNCTION_TYPE = 'function'; |
| 87 const REGEXP_TYPE = 'regexp'; | 149 const REGEXP_TYPE = 'regexp'; |
| 88 const ERROR_TYPE = 'error'; | 150 const ERROR_TYPE = 'error'; |
| 89 const PROPERTY_TYPE = 'property'; | 151 const PROPERTY_TYPE = 'property'; |
| 90 const ACCESSOR_TYPE = 'accessor'; | |
| 91 const FRAME_TYPE = 'frame'; | 152 const FRAME_TYPE = 'frame'; |
| 92 const SCRIPT_TYPE = 'script'; | 153 const SCRIPT_TYPE = 'script'; |
| 93 | 154 |
| 94 // Maximum length when sending strings through the JSON protocol. | 155 // Maximum length when sending strings through the JSON protocol. |
| 95 const kMaxProtocolStringLength = 80; | 156 const kMaxProtocolStringLength = 80; |
| 96 | 157 |
| 97 // Different kind of properties. | 158 // Different kind of properties. |
| 98 PropertyKind = {}; | 159 PropertyKind = {}; |
| 99 PropertyKind.Named = 1; | 160 PropertyKind.Named = 1; |
| 100 PropertyKind.Indexed = 2; | 161 PropertyKind.Indexed = 2; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 this.type_ = type; | 209 this.type_ = type; |
| 149 }; | 210 }; |
| 150 | 211 |
| 151 | 212 |
| 152 Mirror.prototype.type = function() { | 213 Mirror.prototype.type = function() { |
| 153 return this.type_; | 214 return this.type_; |
| 154 }; | 215 }; |
| 155 | 216 |
| 156 | 217 |
| 157 /** | 218 /** |
| 219 * Check whether the mirror reflects a value. |
| 220 * @returns {boolean} True if the mirror reflects a value. |
| 221 */ |
| 222 Mirror.prototype.isValue = function() { |
| 223 return this instanceof ValueMirror; |
| 224 } |
| 225 |
| 226 |
| 227 /** |
| 158 * Check whether the mirror reflects the undefined value. | 228 * Check whether the mirror reflects the undefined value. |
| 159 * @returns {boolean} True if the mirror reflects the undefined value. | 229 * @returns {boolean} True if the mirror reflects the undefined value. |
| 160 */ | 230 */ |
| 161 Mirror.prototype.isUndefined = function() { | 231 Mirror.prototype.isUndefined = function() { |
| 162 return this instanceof UndefinedMirror; | 232 return this instanceof UndefinedMirror; |
| 163 } | 233 } |
| 164 | 234 |
| 165 | 235 |
| 166 /** | 236 /** |
| 167 * Check whether the mirror reflects the null value. | 237 * Check whether the mirror reflects the null value. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 /** | 353 /** |
| 284 * Check whether the mirror reflects a script. | 354 * Check whether the mirror reflects a script. |
| 285 * @returns {boolean} True if the mirror reflects a script | 355 * @returns {boolean} True if the mirror reflects a script |
| 286 */ | 356 */ |
| 287 Mirror.prototype.isScript = function() { | 357 Mirror.prototype.isScript = function() { |
| 288 return this instanceof ScriptMirror; | 358 return this instanceof ScriptMirror; |
| 289 } | 359 } |
| 290 | 360 |
| 291 | 361 |
| 292 /** | 362 /** |
| 293 * Serialize object in JSON format. The actual serialization is handled by the | 363 * Allocate a handle id for this object. |
| 294 * JSONProtocolSerializer. | |
| 295 * @param {boolean} details Indicate level of details to include | |
| 296 * @return {string} JSON serialization | |
| 297 */ | 364 */ |
| 298 Mirror.prototype.toJSONProtocol = function(details) { | 365 Mirror.prototype.allocateHandle_ = function() { |
| 299 var serializer = new JSONProtocolSerializer(details) | 366 this.handle_ = next_handle_++; |
| 300 return serializer.serialize(this) | |
| 301 } | 367 } |
| 302 | 368 |
| 303 | 369 |
| 304 Mirror.prototype.toText = function() { | 370 Mirror.prototype.toText = function() { |
| 305 // Simpel to text which is used when on specialization in subclass. | 371 // Simpel to text which is used when on specialization in subclass. |
| 306 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; | 372 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; |
| 307 } | 373 } |
| 308 | 374 |
| 309 | 375 |
| 310 /** | 376 /** |
| 311 * Base class for all value mirror objects. | 377 * Base class for all value mirror objects. |
| 312 * @param {string} type The type of the mirror | 378 * @param {string} type The type of the mirror |
| 313 * @param {value} value The value reflected by this mirror | 379 * @param {value} value The value reflected by this mirror |
| 314 * @constructor | 380 * @constructor |
| 315 * @extends Mirror | 381 * @extends Mirror |
| 316 */ | 382 */ |
| 317 function ValueMirror(type, value) { | 383 function ValueMirror(type, value) { |
| 318 Mirror.call(this, type); | 384 Mirror.call(this, type); |
| 319 this.value_ = value; | 385 this.value_ = value; |
| 386 this.allocateHandle_(); |
| 320 } | 387 } |
| 321 inherits(ValueMirror, Mirror); | 388 inherits(ValueMirror, Mirror); |
| 322 | 389 |
| 323 | 390 |
| 391 Mirror.prototype.handle = function() { |
| 392 return this.handle_; |
| 393 }; |
| 394 |
| 395 |
| 324 /** | 396 /** |
| 325 * Check whether this is a primitive value. | 397 * Check whether this is a primitive value. |
| 326 * @return {boolean} True if the mirror reflects a primitive value | 398 * @return {boolean} True if the mirror reflects a primitive value |
| 327 */ | 399 */ |
| 328 ValueMirror.prototype.isPrimitive = function() { | 400 ValueMirror.prototype.isPrimitive = function() { |
| 329 var type = this.type(); | 401 var type = this.type(); |
| 330 return type === 'undefined' || | 402 return type === 'undefined' || |
| 331 type === 'null' || | 403 type === 'null' || |
| 332 type === 'boolean' || | 404 type === 'boolean' || |
| 333 type === 'number' || | 405 type === 'number' || |
| 334 type === 'string'; | 406 type === 'string'; |
| 335 }; | 407 }; |
| 336 | 408 |
| 337 | 409 |
| 338 /** | 410 /** |
| 339 * Get the actual value reflected by this mirror. | 411 * Get the actual value reflected by this mirror. |
| 340 * @return {value} The value reflected by this mirror | 412 * @return {value} The value reflected by this mirror |
| 341 */ | 413 */ |
| 342 ValueMirror.prototype.value = function() { | 414 ValueMirror.prototype.value = function() { |
| 343 return this.value_; | 415 return this.value_; |
| 344 }; | 416 }; |
| 345 | 417 |
| 346 | 418 |
| 347 /** | 419 /** |
| 348 * Mirror object for Undefined. | 420 * Mirror object for Undefined. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return MakeMirror(%DebugGetProperty(this.value_, 'constructor')); | 530 return MakeMirror(%DebugGetProperty(this.value_, 'constructor')); |
| 459 }; | 531 }; |
| 460 | 532 |
| 461 | 533 |
| 462 ObjectMirror.prototype.prototypeObject = function() { | 534 ObjectMirror.prototype.prototypeObject = function() { |
| 463 return MakeMirror(%DebugGetProperty(this.value_, 'prototype')); | 535 return MakeMirror(%DebugGetProperty(this.value_, 'prototype')); |
| 464 }; | 536 }; |
| 465 | 537 |
| 466 | 538 |
| 467 ObjectMirror.prototype.protoObject = function() { | 539 ObjectMirror.prototype.protoObject = function() { |
| 468 return MakeMirror(%GetPrototype(this.value_)); | 540 return MakeMirror(%DebugGetPrototype(this.value_)); |
| 469 }; | 541 }; |
| 470 | 542 |
| 471 | 543 |
| 472 ObjectMirror.prototype.hasNamedInterceptor = function() { | 544 ObjectMirror.prototype.hasNamedInterceptor = function() { |
| 473 // Get information on interceptors for this object. | 545 // Get information on interceptors for this object. |
| 474 var x = %DebugInterceptorInfo(this.value_); | 546 var x = %DebugInterceptorInfo(this.value_); |
| 475 return (x & 2) != 0; | 547 return (x & 2) != 0; |
| 476 }; | 548 }; |
| 477 | 549 |
| 478 | 550 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 }; | 646 }; |
| 575 | 647 |
| 576 | 648 |
| 577 ObjectMirror.prototype.property = function(name) { | 649 ObjectMirror.prototype.property = function(name) { |
| 578 var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); | 650 var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); |
| 579 if (details) { | 651 if (details) { |
| 580 return new PropertyMirror(this, name, details); | 652 return new PropertyMirror(this, name, details); |
| 581 } | 653 } |
| 582 | 654 |
| 583 // Nothing found. | 655 // Nothing found. |
| 584 return new UndefinedMirror(); | 656 return GetUndefinedMirror(); |
| 585 }; | 657 }; |
| 586 | 658 |
| 587 | 659 |
| 588 | 660 |
| 589 /** | 661 /** |
| 590 * Try to find a property from its value. | 662 * Try to find a property from its value. |
| 591 * @param {Mirror} value The property value to look for | 663 * @param {Mirror} value The property value to look for |
| 592 * @return {PropertyMirror} The property with the specified value. If no | 664 * @return {PropertyMirror} The property with the specified value. If no |
| 593 * property was found with the specified value UndefinedMirror is returned | 665 * property was found with the specified value UndefinedMirror is returned |
| 594 */ | 666 */ |
| 595 ObjectMirror.prototype.lookupProperty = function(value) { | 667 ObjectMirror.prototype.lookupProperty = function(value) { |
| 596 var properties = this.properties(); | 668 var properties = this.properties(); |
| 597 | 669 |
| 598 // Look for property value in properties. | 670 // Look for property value in properties. |
| 599 for (var i = 0; i < properties.length; i++) { | 671 for (var i = 0; i < properties.length; i++) { |
| 600 | 672 |
| 601 // Skip properties which are defined through assessors. | 673 // Skip properties which are defined through assessors. |
| 602 var property = properties[i]; | 674 var property = properties[i]; |
| 603 if (property.propertyType() != PropertyType.Callbacks) { | 675 if (property.propertyType() != PropertyType.Callbacks) { |
| 604 if (%_ObjectEquals(property.value_, value.value_)) { | 676 if (%_ObjectEquals(property.value_, value.value_)) { |
| 605 return property; | 677 return property; |
| 606 } | 678 } |
| 607 } | 679 } |
| 608 } | 680 } |
| 609 | 681 |
| 610 // Nothing found. | 682 // Nothing found. |
| 611 return new UndefinedMirror(); | 683 return GetUndefinedMirror(); |
| 612 }; | 684 }; |
| 613 | 685 |
| 614 | 686 |
| 615 /** | 687 /** |
| 616 * Returns objects which has direct references to this object | 688 * Returns objects which has direct references to this object |
| 617 * @param {number} opt_max_instances Optional parameter specifying the maximum | 689 * @param {number} opt_max_instances Optional parameter specifying the maximum |
| 618 * number of instances to return. | 690 * number of instances to return. |
| 619 * @return {Array} The objects which has direct references to this object. | 691 * @return {Array} The objects which has direct references to this object. |
| 620 */ | 692 */ |
| 621 ObjectMirror.prototype.referencedBy = function(opt_max_instances) { | 693 ObjectMirror.prototype.referencedBy = function(opt_max_instances) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 752 |
| 681 /** | 753 /** |
| 682 * Returns the source code for the function. | 754 * Returns the source code for the function. |
| 683 * @return {string or undefined} The source code for the function. If the | 755 * @return {string or undefined} The source code for the function. If the |
| 684 * function is not resolved undefined will be returned. | 756 * function is not resolved undefined will be returned. |
| 685 */ | 757 */ |
| 686 FunctionMirror.prototype.source = function() { | 758 FunctionMirror.prototype.source = function() { |
| 687 // Return source if function is resolved. Otherwise just fall through to | 759 // Return source if function is resolved. Otherwise just fall through to |
| 688 // return undefined. | 760 // return undefined. |
| 689 if (this.resolved()) { | 761 if (this.resolved()) { |
| 690 // This builtins function is context independant (only uses runtime | |
| 691 // calls and typeof. | |
| 692 return builtins.FunctionSourceString(this.value_); | 762 return builtins.FunctionSourceString(this.value_); |
| 693 } | 763 } |
| 694 }; | 764 }; |
| 695 | 765 |
| 696 | 766 |
| 697 /** | 767 /** |
| 698 * Returns the script object for the function. | 768 * Returns the script object for the function. |
| 699 * @return {ScriptMirror or undefined} Script object for the function or | 769 * @return {ScriptMirror or undefined} Script object for the function or |
| 700 * undefined if the function has no script | 770 * undefined if the function has no script |
| 701 */ | 771 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 826 } |
| 757 inherits(UnresolvedFunctionMirror, FunctionMirror); | 827 inherits(UnresolvedFunctionMirror, FunctionMirror); |
| 758 | 828 |
| 759 | 829 |
| 760 UnresolvedFunctionMirror.prototype.className = function() { | 830 UnresolvedFunctionMirror.prototype.className = function() { |
| 761 return 'Function'; | 831 return 'Function'; |
| 762 }; | 832 }; |
| 763 | 833 |
| 764 | 834 |
| 765 UnresolvedFunctionMirror.prototype.constructorFunction = function() { | 835 UnresolvedFunctionMirror.prototype.constructorFunction = function() { |
| 766 return new UndefinedMirror(); | 836 return GetUndefinedMirror(); |
| 767 }; | 837 }; |
| 768 | 838 |
| 769 | 839 |
| 770 UnresolvedFunctionMirror.prototype.prototypeObject = function() { | 840 UnresolvedFunctionMirror.prototype.prototypeObject = function() { |
| 771 return new UndefinedMirror(); | 841 return GetUndefinedMirror(); |
| 772 }; | 842 }; |
| 773 | 843 |
| 774 | 844 |
| 775 UnresolvedFunctionMirror.prototype.protoObject = function() { | 845 UnresolvedFunctionMirror.prototype.protoObject = function() { |
| 776 return new UndefinedMirror(); | 846 return GetUndefinedMirror(); |
| 777 }; | 847 }; |
| 778 | 848 |
| 779 | 849 |
| 780 UnresolvedFunctionMirror.prototype.name = function() { | 850 UnresolvedFunctionMirror.prototype.name = function() { |
| 781 return this.value_; | 851 return this.value_; |
| 782 }; | 852 }; |
| 783 | 853 |
| 784 | 854 |
| 785 UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) { | 855 UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) { |
| 786 return []; | 856 return []; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 808 var from_index = opt_from_index || 0; | 878 var from_index = opt_from_index || 0; |
| 809 var to_index = opt_to_index || this.length() - 1; | 879 var to_index = opt_to_index || this.length() - 1; |
| 810 if (from_index > to_index) return new Array(); | 880 if (from_index > to_index) return new Array(); |
| 811 var values = new Array(to_index - from_index + 1); | 881 var values = new Array(to_index - from_index + 1); |
| 812 for (var i = from_index; i <= to_index; i++) { | 882 for (var i = from_index; i <= to_index; i++) { |
| 813 var details = %DebugGetPropertyDetails(this.value_, %ToString(i)); | 883 var details = %DebugGetPropertyDetails(this.value_, %ToString(i)); |
| 814 var value; | 884 var value; |
| 815 if (details) { | 885 if (details) { |
| 816 value = new PropertyMirror(this, i, details); | 886 value = new PropertyMirror(this, i, details); |
| 817 } else { | 887 } else { |
| 818 value = new UndefinedMirror(); | 888 value = GetUndefinedMirror(); |
| 819 } | 889 } |
| 820 values[i - from_index] = value; | 890 values[i - from_index] = value; |
| 821 } | 891 } |
| 822 return values; | 892 return values; |
| 823 } | 893 } |
| 824 | 894 |
| 825 | 895 |
| 826 /** | 896 /** |
| 827 * Mirror object for dates. | 897 * Mirror object for dates. |
| 828 * @param {Date} value The Date object reflected by this mirror | 898 * @param {Date} value The Date object reflected by this mirror |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 | 1288 |
| 1219 | 1289 |
| 1220 FrameMirror.prototype.func = function() { | 1290 FrameMirror.prototype.func = function() { |
| 1221 // Get the function for this frame from the VM. | 1291 // Get the function for this frame from the VM. |
| 1222 var f = this.details_.func(); | 1292 var f = this.details_.func(); |
| 1223 | 1293 |
| 1224 // Create a function mirror. NOTE: MakeMirror cannot be used here as the | 1294 // Create a function mirror. NOTE: MakeMirror cannot be used here as the |
| 1225 // value returned from the VM might be a string if the function for the | 1295 // value returned from the VM might be a string if the function for the |
| 1226 // frame is unresolved. | 1296 // frame is unresolved. |
| 1227 if (IS_FUNCTION(f)) { | 1297 if (IS_FUNCTION(f)) { |
| 1228 return new FunctionMirror(f); | 1298 return MakeMirror(f); |
| 1229 } else { | 1299 } else { |
| 1230 return new UnresolvedFunctionMirror(f); | 1300 return new UnresolvedFunctionMirror(f); |
| 1231 } | 1301 } |
| 1232 }; | 1302 }; |
| 1233 | 1303 |
| 1234 | 1304 |
| 1235 FrameMirror.prototype.receiver = function() { | 1305 FrameMirror.prototype.receiver = function() { |
| 1236 return MakeMirror(this.details_.receiver()); | 1306 return MakeMirror(this.details_.receiver()); |
| 1237 }; | 1307 }; |
| 1238 | 1308 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 } else if (this.isDebuggerFrame()) { | 1408 } else if (this.isDebuggerFrame()) { |
| 1339 result += '[debugger]'; | 1409 result += '[debugger]'; |
| 1340 } else { | 1410 } else { |
| 1341 // If the receiver has a className which is 'global' don't display it. | 1411 // If the receiver has a className which is 'global' don't display it. |
| 1342 var display_receiver = !receiver.className || receiver.className() != 'globa
l'; | 1412 var display_receiver = !receiver.className || receiver.className() != 'globa
l'; |
| 1343 if (display_receiver) { | 1413 if (display_receiver) { |
| 1344 result += receiver.toText(); | 1414 result += receiver.toText(); |
| 1345 } | 1415 } |
| 1346 // Try to find the function as a property in the receiver. Include the | 1416 // Try to find the function as a property in the receiver. Include the |
| 1347 // prototype chain in the lookup. | 1417 // prototype chain in the lookup. |
| 1348 var property = new UndefinedMirror(); | 1418 var property = GetUndefinedMirror(); |
| 1349 if (!receiver.isUndefined()) { | 1419 if (!receiver.isUndefined()) { |
| 1350 for (var r = receiver; !r.isNull() && property.isUndefined(); r = r.protoO
bject()) { | 1420 for (var r = receiver; !r.isNull() && property.isUndefined(); r = r.protoO
bject()) { |
| 1351 property = r.lookupProperty(func); | 1421 property = r.lookupProperty(func); |
| 1352 } | 1422 } |
| 1353 } | 1423 } |
| 1354 if (!property.isUndefined()) { | 1424 if (!property.isUndefined()) { |
| 1355 // The function invoked was found on the receiver. Use the property name | 1425 // The function invoked was found on the receiver. Use the property name |
| 1356 // for the backtrace. | 1426 // for the backtrace. |
| 1357 if (!property.isIndexed()) { | 1427 if (!property.isIndexed()) { |
| 1358 if (display_receiver) { | 1428 if (display_receiver) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 | 1534 |
| 1465 /** | 1535 /** |
| 1466 * Mirror object for script source. | 1536 * Mirror object for script source. |
| 1467 * @param {Script} script The script object | 1537 * @param {Script} script The script object |
| 1468 * @constructor | 1538 * @constructor |
| 1469 * @extends Mirror | 1539 * @extends Mirror |
| 1470 */ | 1540 */ |
| 1471 function ScriptMirror(script) { | 1541 function ScriptMirror(script) { |
| 1472 Mirror.call(this, SCRIPT_TYPE); | 1542 Mirror.call(this, SCRIPT_TYPE); |
| 1473 this.script_ = script; | 1543 this.script_ = script; |
| 1544 this.allocateHandle_(); |
| 1474 } | 1545 } |
| 1475 inherits(ScriptMirror, Mirror); | 1546 inherits(ScriptMirror, Mirror); |
| 1476 | 1547 |
| 1477 | 1548 |
| 1478 ScriptMirror.prototype.name = function() { | 1549 ScriptMirror.prototype.name = function() { |
| 1479 return this.script_.name; | 1550 return this.script_.name; |
| 1480 }; | 1551 }; |
| 1481 | 1552 |
| 1482 | 1553 |
| 1483 ScriptMirror.prototype.lineOffset = function() { | 1554 ScriptMirror.prototype.lineOffset = function() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 result += '-'; | 1590 result += '-'; |
| 1520 result += this.lineOffset() + this.lineCount() - 1; | 1591 result += this.lineOffset() + this.lineCount() - 1; |
| 1521 } else { | 1592 } else { |
| 1522 result += this.lineCount(); | 1593 result += this.lineCount(); |
| 1523 } | 1594 } |
| 1524 result += ')'; | 1595 result += ')'; |
| 1525 return result; | 1596 return result; |
| 1526 } | 1597 } |
| 1527 | 1598 |
| 1528 | 1599 |
| 1529 function JSONProtocolSerializer(details) { | 1600 /** |
| 1530 this.details_ = details; | 1601 * Returns a mirror serializer |
| 1602 * |
| 1603 * @param {boolean} details Set to true to include details |
| 1604 * @returns {MirrorSerializer} mirror serializer |
| 1605 */ |
| 1606 function MakeMirrorSerializer(details) { |
| 1607 return new JSONProtocolSerializer(details); |
| 1531 } | 1608 } |
| 1532 | 1609 |
| 1533 | 1610 |
| 1534 JSONProtocolSerializer.prototype.serialize = function(mirror) { | 1611 /** |
| 1535 // Collect the JSON property/value pairs in a array. | 1612 * Object for serializing a mirror objects and its direct references. |
| 1613 * @param {boolean} details Indicates whether to include details for the mirror |
| 1614 * serialized |
| 1615 * @constructor |
| 1616 */ |
| 1617 function JSONProtocolSerializer(details) { |
| 1618 this.details_ = details; |
| 1619 this.mirrors_ = [ ]; |
| 1620 } |
| 1621 |
| 1622 |
| 1623 /** |
| 1624 * Returns a serialization of an object reference. The referenced object are |
| 1625 * added to the serialization state. |
| 1626 * |
| 1627 * @param {Mirror} mirror The mirror to serialize |
| 1628 * @returns {String} JSON serialization |
| 1629 */ |
| 1630 JSONProtocolSerializer.prototype.serializeReference = function(mirror) { |
| 1631 return this.serialize_(mirror, true, true); |
| 1632 } |
| 1633 |
| 1634 |
| 1635 /** |
| 1636 * Returns a serialization of an object value. The referenced objects are |
| 1637 * added to the serialization state. |
| 1638 * |
| 1639 * @param {Mirror} mirror The mirror to serialize |
| 1640 * @returns {String} JSON serialization |
| 1641 */ |
| 1642 JSONProtocolSerializer.prototype.serializeValue = function(mirror) { |
| 1643 var json = this.serialize_(mirror, false, true); |
| 1644 return json; |
| 1645 } |
| 1646 |
| 1647 |
| 1648 /** |
| 1649 * Returns a serialization of all the objects referenced. |
| 1650 * |
| 1651 * @param {Mirror} mirror The mirror to serialize |
| 1652 * @returns {String} JSON serialization |
| 1653 */ |
| 1654 JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { |
| 1655 // Collect the JSON serialization of the referenced objects in an array. |
| 1656 var content = new Array(); |
| 1657 |
| 1658 // Get the number of referenced objects. |
| 1659 var count = this.mirrors_.length; |
| 1660 |
| 1661 for (var i = 0; i < count; i++) { |
| 1662 content.push(this.serialize_(this.mirrors_[i], false, false)); |
| 1663 } |
| 1664 |
| 1665 var json = ArrayToJSONArray_(content); |
| 1666 return json; |
| 1667 } |
| 1668 |
| 1669 |
| 1670 JSONProtocolSerializer.prototype.add_ = function(mirror) { |
| 1671 // If this mirror is already in the list just return. |
| 1672 for (var i = 0; i < this.mirrors_.length; i++) { |
| 1673 if (this.mirrors_[i] === mirror) { |
| 1674 return; |
| 1675 } |
| 1676 } |
| 1677 |
| 1678 // Add the mirror to the list of mirrors to be serialized. |
| 1679 this.mirrors_.push(mirror); |
| 1680 } |
| 1681 |
| 1682 |
| 1683 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
| 1684 details) { |
| 1685 // If serializing a reference to a mirror just return the reference and add |
| 1686 // the mirror to the referenced mirrors. |
| 1687 if (reference && |
| 1688 (mirror.isValue() || mirror.isScript())) { |
| 1689 this.add_(mirror); |
| 1690 return '{"ref":' + mirror.handle() + '}'; |
| 1691 } |
| 1692 |
| 1693 // Collect the JSON property/value pairs in an array. |
| 1536 var content = new Array(); | 1694 var content = new Array(); |
| 1537 | 1695 |
| 1538 // Always add the type | 1696 // Add the handle for value mirrors. |
| 1697 if (mirror.isValue()) { |
| 1698 content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle()))); |
| 1699 } |
| 1700 |
| 1701 // Always add the type. |
| 1539 content.push(MakeJSONPair_('type', StringToJSON_(mirror.type()))); | 1702 content.push(MakeJSONPair_('type', StringToJSON_(mirror.type()))); |
| 1540 | 1703 |
| 1541 switch (mirror.type()) { | 1704 switch (mirror.type()) { |
| 1542 case UNDEFINED_TYPE: | 1705 case UNDEFINED_TYPE: |
| 1543 case NULL_TYPE: | 1706 case NULL_TYPE: |
| 1544 // Undefined and null are represented just by their type. | 1707 // Undefined and null are represented just by their type. |
| 1545 break; | 1708 break; |
| 1546 | 1709 |
| 1547 case BOOLEAN_TYPE: | 1710 case BOOLEAN_TYPE: |
| 1548 // Boolean values are simply represented by their value. | 1711 // Boolean values are simply represented by their value. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1566 content.push(MakeJSONPair_('value', StringToJSON_(mirror.value()))); | 1729 content.push(MakeJSONPair_('value', StringToJSON_(mirror.value()))); |
| 1567 } | 1730 } |
| 1568 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); | 1731 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); |
| 1569 break; | 1732 break; |
| 1570 | 1733 |
| 1571 case OBJECT_TYPE: | 1734 case OBJECT_TYPE: |
| 1572 case FUNCTION_TYPE: | 1735 case FUNCTION_TYPE: |
| 1573 case ERROR_TYPE: | 1736 case ERROR_TYPE: |
| 1574 case REGEXP_TYPE: | 1737 case REGEXP_TYPE: |
| 1575 // Add object representation. | 1738 // Add object representation. |
| 1576 this.serializeObject_(mirror, content); | 1739 this.serializeObject_(mirror, content, details); |
| 1577 break; | 1740 break; |
| 1578 | 1741 |
| 1579 case PROPERTY_TYPE: | 1742 case PROPERTY_TYPE: |
| 1580 // Properties are represented by name, value, attributes and type. | 1743 throw new Error('PropertyMirror cannot be serialized independeltly') |
| 1581 content.push(MakeJSONPair_('name', | |
| 1582 StringToJSON_(mirror.name()))); | |
| 1583 content.push(MakeJSONPair_('value', | |
| 1584 mirror.value().toJSONProtocol(this.details_))); | |
| 1585 if (mirror.attributes() != PropertyAttribute.None) { | |
| 1586 content.push(MakeJSONPair_('attributes', | |
| 1587 NumberToJSON_(mirror.attributes()))); | |
| 1588 } | |
| 1589 if (mirror.propertyType() != PropertyType.Normal) { | |
| 1590 content.push(MakeJSONPair_('propertyType', | |
| 1591 NumberToJSON_(mirror.propertyType()))); | |
| 1592 } | |
| 1593 break; | |
| 1594 | |
| 1595 case ACCESSOR_TYPE: | |
| 1596 // An accessor can either be native or defined through JavaScript. | |
| 1597 if (mirror.isNative()) { | |
| 1598 content.push(MakeJSONPair_('native', BooleanToJSON_(true))); | |
| 1599 } else { | |
| 1600 content.push(MakeJSONPair_('getter', | |
| 1601 mirror.getter().toJSONProtocol(false))); | |
| 1602 content.push(MakeJSONPair_('setter', | |
| 1603 mirror.setter().toJSONProtocol(false))); | |
| 1604 } | |
| 1605 break; | 1744 break; |
| 1606 | 1745 |
| 1607 case FRAME_TYPE: | 1746 case FRAME_TYPE: |
| 1608 // Add object representation. | 1747 // Add object representation. |
| 1609 this.serializeFrame_(mirror, content); | 1748 this.serializeFrame_(mirror, content); |
| 1610 break; | 1749 break; |
| 1611 | 1750 |
| 1612 case SCRIPT_TYPE: | 1751 case SCRIPT_TYPE: |
| 1613 // Script is represented by name and source attributes. | 1752 // Script is represented by name and source attributes. |
| 1614 if (mirror.name()) { | 1753 if (mirror.name()) { |
| 1615 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); | 1754 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); |
| 1616 } | 1755 } |
| 1617 content.push(MakeJSONPair_('lineOffset', | 1756 content.push(MakeJSONPair_('lineOffset', |
| 1618 NumberToJSON_(mirror.lineOffset()))); | 1757 NumberToJSON_(mirror.lineOffset()))); |
| 1619 content.push(MakeJSONPair_('columnOffset', | 1758 content.push(MakeJSONPair_('columnOffset', |
| 1620 NumberToJSON_(mirror.columnOffset()))); | 1759 NumberToJSON_(mirror.columnOffset()))); |
| 1621 content.push(MakeJSONPair_('lineCount', | 1760 content.push(MakeJSONPair_('lineCount', |
| 1622 NumberToJSON_(mirror.lineCount()))); | 1761 NumberToJSON_(mirror.lineCount()))); |
| 1623 content.push(MakeJSONPair_('scriptType', | 1762 content.push(MakeJSONPair_('scriptType', |
| 1624 NumberToJSON_(mirror.scriptType()))); | 1763 NumberToJSON_(mirror.scriptType()))); |
| 1625 break; | 1764 break; |
| 1626 | |
| 1627 } | 1765 } |
| 1628 | 1766 |
| 1629 // Always add the text representation. | 1767 // Always add the text representation. |
| 1630 content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText()))); | 1768 content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText()))); |
| 1631 | 1769 |
| 1632 // Create and return the JSON string. | 1770 // Create and return the JSON string. |
| 1633 return ArrayToJSONObject_(content); | 1771 return ArrayToJSONObject_(content); |
| 1634 } | 1772 } |
| 1635 | 1773 |
| 1636 | 1774 |
| 1637 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content) { | 1775 /** |
| 1776 * Serialize object information to the following JSON format. |
| 1777 * |
| 1778 * {"className":"<class name>", |
| 1779 * "constructorFunction":{"ref":<number>}, |
| 1780 * "protoObject":{"ref":<number>}, |
| 1781 * "prototypeObject":{"ref":<number>}, |
| 1782 * "namedInterceptor":<boolean>, |
| 1783 * "indexedInterceptor":<boolean>, |
| 1784 * "properties":[<properties>]} |
| 1785 */ |
| 1786 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, |
| 1787 details) { |
| 1788 // Add general object properties. |
| 1638 content.push(MakeJSONPair_('className', | 1789 content.push(MakeJSONPair_('className', |
| 1639 StringToJSON_(mirror.className()))); | 1790 StringToJSON_(mirror.className()))); |
| 1791 content.push(MakeJSONPair_('constructorFunction', |
| 1792 this.serializeReference(mirror.constructorFunction()))); |
| 1793 content.push(MakeJSONPair_('protoObject', |
| 1794 this.serializeReference(mirror.protoObject()))); |
| 1795 content.push(MakeJSONPair_('prototypeObject', |
| 1796 this.serializeReference(mirror.prototypeObject()))); |
| 1640 | 1797 |
| 1641 if (this.details_) { | 1798 // Add flags to indicate whether there are interceptors. |
| 1642 content.push(MakeJSONPair_('constructorFunction', | |
| 1643 mirror.constructorFunction().toJSONProtocol(false))); | |
| 1644 content.push(MakeJSONPair_('protoObject', | |
| 1645 mirror.protoObject().toJSONProtocol(false))); | |
| 1646 content.push(MakeJSONPair_('prototypeObject', | |
| 1647 mirror.prototypeObject().toJSONProtocol(false))); | |
| 1648 | |
| 1649 // Add properties. For arrays don't include indexed proeprties. | |
| 1650 var kind = PropertyKind.Named; | |
| 1651 if (!mirror.isArray()) { | |
| 1652 kind |= PropertyKind.Indexed | |
| 1653 } | |
| 1654 var propertyNames = mirror.propertyNames(kind); | |
| 1655 var x = new Array(propertyNames.length); | |
| 1656 for (var i = 0; i < propertyNames.length; i++) { | |
| 1657 x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false); | |
| 1658 } | |
| 1659 content.push(MakeJSONPair_('properties', ArrayToJSONArray_(x))); | |
| 1660 | |
| 1661 // For arrays the indexed properties are added separately and the length is | |
| 1662 // added as well. | |
| 1663 if (mirror.isArray()) { | |
| 1664 var propertyNames = mirror.propertyNames(PropertyKind.Indexed); | |
| 1665 var x = new Array(propertyNames.length); | |
| 1666 for (var i = 0; i < propertyNames.length; i++) { | |
| 1667 x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false); | |
| 1668 } | |
| 1669 content.push(MakeJSONPair_('indexedProperties', ArrayToJSONArray_(x))); | |
| 1670 | |
| 1671 // Add the array length. | |
| 1672 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); | |
| 1673 } | |
| 1674 } | |
| 1675 | |
| 1676 if (mirror.hasNamedInterceptor()) { | 1799 if (mirror.hasNamedInterceptor()) { |
| 1677 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true))); | 1800 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true))); |
| 1678 } | 1801 } |
| 1679 | |
| 1680 if (mirror.hasIndexedInterceptor()) { | 1802 if (mirror.hasIndexedInterceptor()) { |
| 1681 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true))); | 1803 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true))); |
| 1682 } | 1804 } |
| 1683 | 1805 |
| 1806 // Add function specific properties. |
| 1684 if (mirror.isFunction()) { | 1807 if (mirror.isFunction()) { |
| 1685 // Add function specific properties. | 1808 // Add function specific properties. |
| 1686 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); | 1809 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); |
| 1687 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); | 1810 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); |
| 1688 if (this.details_ && mirror.resolved()) { | 1811 if (mirror.resolved()) { |
| 1689 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); | 1812 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); |
| 1690 } | 1813 } |
| 1691 if (mirror.script()) { | 1814 if (mirror.script()) { |
| 1692 content.push(MakeJSONPair_('script', mirror.script().toJSONProtocol())); | 1815 content.push(MakeJSONPair_('script', this.serializeReference(mirror.script
()))); |
| 1693 } | 1816 } |
| 1694 } else if (mirror.isDate()) { | 1817 } |
| 1818 |
| 1819 // Add date specific properties. |
| 1820 if (mirror.isDate()) { |
| 1695 // Add date specific properties. | 1821 // Add date specific properties. |
| 1696 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value()))); | 1822 content.push(MakeJSONPair_('value', DateToJSON_(mirror.value()))); |
| 1697 } else if (mirror.isRegExp()) { | |
| 1698 // Add regexp specific properties. | |
| 1699 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); | |
| 1700 content.push(MakeJSONPair_('global', BooleanToJSON_(mirror.global()))); | |
| 1701 content.push(MakeJSONPair_('ignoreCase', | |
| 1702 BooleanToJSON_(mirror.ignoreCase()))); | |
| 1703 content.push(MakeJSONPair_('multiline', | |
| 1704 BooleanToJSON_(mirror.multiline()))); | |
| 1705 } else if (mirror.isError()) { | |
| 1706 // Add error specific properties. | |
| 1707 content.push(MakeJSONPair_('message', StringToJSON_(mirror.message()))); | |
| 1708 } | 1823 } |
| 1824 |
| 1825 // Add actual properties - named properties followed by indexed properties. |
| 1826 var propertyNames = mirror.propertyNames(PropertyKind.Named); |
| 1827 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |
| 1828 var p = new Array(propertyNames.length + propertyIndexes.length); |
| 1829 for (var i = 0; i < propertyNames.length; i++) { |
| 1830 var property_mirror = mirror.property(propertyNames[i]); |
| 1831 p[i] = this.serializeProperty_(property_mirror); |
| 1832 if (details) { |
| 1833 this.add_(property_mirror.value()); |
| 1834 } |
| 1835 } |
| 1836 for (var i = 0; i < propertyIndexes.length; i++) { |
| 1837 var property_mirror = mirror.property(propertyIndexes[i]); |
| 1838 p[propertyNames.length + i] = this.serializeProperty_(property_mirror); |
| 1839 if (details) { |
| 1840 this.add_(property_mirror.value()); |
| 1841 } |
| 1842 } |
| 1843 content.push(MakeJSONPair_('properties', ArrayToJSONArray_(p))); |
| 1844 } |
| 1845 |
| 1846 |
| 1847 /** |
| 1848 * Serialize property information to the following JSON format for building the |
| 1849 * array of properties. |
| 1850 * |
| 1851 * {"name":"<property name>", |
| 1852 * "attributes":<number>, |
| 1853 * "propertyType":<number>, |
| 1854 * "ref":<number>} |
| 1855 * |
| 1856 * If the attribute for the property is PropertyAttribute.None it is not added. |
| 1857 * If the propertyType for the property is PropertyType.Normal it is not added. |
| 1858 * Here are a couple of examples. |
| 1859 * |
| 1860 * {"name":"hello","ref":1} |
| 1861 * {"name":"length","attributes":7,"propertyType":3,"ref":2} |
| 1862 * |
| 1863 * @param {PropertyMirror} property_mirror The property to serialize |
| 1864 * @returns {String} JSON serialization |
| 1865 */ |
| 1866 JSONProtocolSerializer.prototype.serializeProperty_ = function(property_mirror)
{ |
| 1867 var builder = new builtins.StringBuilder(); |
| 1868 builder.add('{"name":'); |
| 1869 builder.add(StringToJSON_(property_mirror.name())); |
| 1870 if (property_mirror.attributes() != PropertyAttribute.None) { |
| 1871 builder.add(',"attributes":'); |
| 1872 builder.add(NumberToJSON_(property_mirror.attributes())); |
| 1873 } |
| 1874 if (property_mirror.propertyType() != PropertyType.Normal) { |
| 1875 builder.add(',"propertyType":'); |
| 1876 builder.add(NumberToJSON_(property_mirror.propertyType())); |
| 1877 } |
| 1878 builder.add(',"ref":'); |
| 1879 builder.add(NumberToJSON_(property_mirror.value().handle())); |
| 1880 builder.add('}'); |
| 1881 return builder.generate(); |
| 1709 } | 1882 } |
| 1710 | 1883 |
| 1711 | 1884 |
| 1712 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { | 1885 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { |
| 1713 content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index()))); | 1886 content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index()))); |
| 1714 content.push(MakeJSONPair_('receiver', | 1887 content.push(MakeJSONPair_('receiver', |
| 1715 mirror.receiver().toJSONProtocol(false))); | 1888 this.serializeReference(mirror.receiver()))); |
| 1716 content.push(MakeJSONPair_('func', mirror.func().toJSONProtocol(false))); | 1889 content.push(MakeJSONPair_('func', this.serializeReference(mirror.func()))); |
| 1717 content.push(MakeJSONPair_('constructCall', | 1890 content.push(MakeJSONPair_('constructCall', |
| 1718 BooleanToJSON_(mirror.isConstructCall()))); | 1891 BooleanToJSON_(mirror.isConstructCall()))); |
| 1719 content.push(MakeJSONPair_('debuggerFrame', | 1892 content.push(MakeJSONPair_('debuggerFrame', |
| 1720 BooleanToJSON_(mirror.isDebuggerFrame()))); | 1893 BooleanToJSON_(mirror.isDebuggerFrame()))); |
| 1721 var x = new Array(mirror.argumentCount()); | 1894 var x = new Array(mirror.argumentCount()); |
| 1722 for (var i = 0; i < mirror.argumentCount(); i++) { | 1895 for (var i = 0; i < mirror.argumentCount(); i++) { |
| 1723 arg = new Array(); | 1896 arg = new Array(); |
| 1724 var argument_name = mirror.argumentName(i) | 1897 var argument_name = mirror.argumentName(i) |
| 1725 if (argument_name) { | 1898 if (argument_name) { |
| 1726 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name))); | 1899 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name))); |
| 1727 } | 1900 } |
| 1728 arg.push(MakeJSONPair_('value', | 1901 arg.push(MakeJSONPair_('value', |
| 1729 mirror.argumentValue(i).toJSONProtocol(false))); | 1902 this.serializeReference(mirror.argumentValue(i)))); |
| 1730 x[i] = ArrayToJSONObject_(arg); | 1903 x[i] = ArrayToJSONObject_(arg); |
| 1731 } | 1904 } |
| 1732 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x))); | 1905 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x))); |
| 1733 var x = new Array(mirror.localCount()); | 1906 var x = new Array(mirror.localCount()); |
| 1734 for (var i = 0; i < mirror.localCount(); i++) { | 1907 for (var i = 0; i < mirror.localCount(); i++) { |
| 1735 var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i))); | 1908 var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i))); |
| 1736 var value = MakeJSONPair_('value', | 1909 var value = MakeJSONPair_('value', |
| 1737 mirror.localValue(i).toJSONProtocol(false)); | 1910 this.serializeReference(mirror.localValue(i))); |
| 1738 x[i] = '{' + name + ',' + value + '}'; | 1911 x[i] = '{' + name + ',' + value + '}'; |
| 1739 } | 1912 } |
| 1740 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x))); | 1913 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x))); |
| 1741 content.push(MakeJSONPair_('position', | 1914 content.push(MakeJSONPair_('position', |
| 1742 NumberToJSON_(mirror.sourcePosition()))); | 1915 NumberToJSON_(mirror.sourcePosition()))); |
| 1743 var line = mirror.sourceLine(); | 1916 var line = mirror.sourceLine(); |
| 1744 if (!IS_UNDEFINED(line)) { | 1917 if (!IS_UNDEFINED(line)) { |
| 1745 content.push(MakeJSONPair_('line', NumberToJSON_(line))); | 1918 content.push(MakeJSONPair_('line', NumberToJSON_(line))); |
| 1746 } | 1919 } |
| 1747 var column = mirror.sourceColumn(); | 1920 var column = mirror.sourceColumn(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1769 function ArrayToJSONArray_(content) { | 1942 function ArrayToJSONArray_(content) { |
| 1770 return '[' + content.join(',') + ']'; | 1943 return '[' + content.join(',') + ']'; |
| 1771 } | 1944 } |
| 1772 | 1945 |
| 1773 | 1946 |
| 1774 function BooleanToJSON_(value) { | 1947 function BooleanToJSON_(value) { |
| 1775 return String(value); | 1948 return String(value); |
| 1776 } | 1949 } |
| 1777 | 1950 |
| 1778 | 1951 |
| 1952 /** |
| 1953 * Convert a number to a JSON string value. For all finite numbers the number |
| 1954 * literal representation is used. For non finite numbers NaN, Infinite and |
| 1955 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" |
| 1956 * (including the quotes) is returned. |
| 1957 * |
| 1958 * @param {number} value The number value to convert to a JSON value |
| 1959 * @returns {String} JSON value |
| 1960 */ |
| 1779 function NumberToJSON_(value) { | 1961 function NumberToJSON_(value) { |
| 1962 if (isNaN(value)) { |
| 1963 return '"NaN"'; |
| 1964 } |
| 1965 if (!isFinite(value)) { |
| 1966 if (value > 0) { |
| 1967 return '"Infinity"'; |
| 1968 } else { |
| 1969 return '"-Infinity"'; |
| 1970 } |
| 1971 } |
| 1780 return String(value); | 1972 return String(value); |
| 1781 } | 1973 } |
| 1782 | 1974 |
| 1783 | 1975 |
| 1784 // Mapping of some control characters to avoid the \uXXXX syntax for most | 1976 // Mapping of some control characters to avoid the \uXXXX syntax for most |
| 1785 // commonly used control cahracters. | 1977 // commonly used control cahracters. |
| 1786 const ctrlCharMap_ = { | 1978 const ctrlCharMap_ = { |
| 1787 '\b': '\\b', | 1979 '\b': '\\b', |
| 1788 '\t': '\\t', | 1980 '\t': '\\t', |
| 1789 '\n': '\\n', | 1981 '\n': '\\n', |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 /** | 2052 /** |
| 1861 * Convert a Date to ISO 8601 format. To avoid depending on the Date object | 2053 * Convert a Date to ISO 8601 format. To avoid depending on the Date object |
| 1862 * this method calls the functions in date.js directly and not through the | 2054 * this method calls the functions in date.js directly and not through the |
| 1863 * value. | 2055 * value. |
| 1864 * @param {Date} value The Date value to format as JSON | 2056 * @param {Date} value The Date value to format as JSON |
| 1865 * @return {string} JSON formatted Date value | 2057 * @return {string} JSON formatted Date value |
| 1866 */ | 2058 */ |
| 1867 function DateToJSON_(value) { | 2059 function DateToJSON_(value) { |
| 1868 return '"' + DateToISO8601_(value) + '"'; | 2060 return '"' + DateToISO8601_(value) + '"'; |
| 1869 } | 2061 } |
| OLD | NEW |