| 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 /** |
| 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 Loading... |
| 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 | |
| 134 // - AccessorMirror | |
| 135 // - FrameMirror | 138 // - FrameMirror |
| 136 // - ScriptMirror | 139 // - ScriptMirror |
| 137 | 140 |
| 138 | 141 |
| 139 /** | 142 /** |
| 140 * Base class for all mirror objects. | 143 * Base class for all mirror objects. |
| 141 * @param {string} type The type of the mirror | 144 * @param {string} type The type of the mirror |
| 142 * @constructor | 145 * @constructor |
| 143 */ | 146 */ |
| 144 function Mirror(type) { | 147 function Mirror(type) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 /** | 265 /** |
| 263 * Check whether the mirror reflects a property. | 266 * Check whether the mirror reflects a property. |
| 264 * @returns {boolean} True if the mirror reflects a property | 267 * @returns {boolean} True if the mirror reflects a property |
| 265 */ | 268 */ |
| 266 Mirror.prototype.isProperty = function() { | 269 Mirror.prototype.isProperty = function() { |
| 267 return this instanceof PropertyMirror; | 270 return this instanceof PropertyMirror; |
| 268 } | 271 } |
| 269 | 272 |
| 270 | 273 |
| 271 /** | 274 /** |
| 272 * Check whether the mirror reflects a property from an interceptor. | |
| 273 * @returns {boolean} True if the mirror reflects a property from an | |
| 274 * interceptor | |
| 275 */ | |
| 276 Mirror.prototype.isInterceptorProperty = function() { | |
| 277 return this instanceof InterceptorPropertyMirror; | |
| 278 } | |
| 279 | |
| 280 | |
| 281 /** | |
| 282 * Check whether the mirror reflects an accessor. | |
| 283 * @returns {boolean} True if the mirror reflects an accessor | |
| 284 */ | |
| 285 Mirror.prototype.isAccessor = function() { | |
| 286 return this instanceof AccessorMirror; | |
| 287 } | |
| 288 | |
| 289 | |
| 290 /** | |
| 291 * Check whether the mirror reflects a stack frame. | 275 * Check whether the mirror reflects a stack frame. |
| 292 * @returns {boolean} True if the mirror reflects a stack frame | 276 * @returns {boolean} True if the mirror reflects a stack frame |
| 293 */ | 277 */ |
| 294 Mirror.prototype.isFrame = function() { | 278 Mirror.prototype.isFrame = function() { |
| 295 return this instanceof FrameMirror; | 279 return this instanceof FrameMirror; |
| 296 } | 280 } |
| 297 | 281 |
| 298 | 282 |
| 299 Mirror.prototype.fillJSONType_ = function(content) { | 283 /** |
| 300 content.push(MakeJSONPair_('type', StringToJSON_(this.type()))); | 284 * Check whether the mirror reflects a script. |
| 301 }; | 285 * @returns {boolean} True if the mirror reflects a script |
| 302 | 286 */ |
| 303 | 287 Mirror.prototype.isScript = function() { |
| 304 Mirror.prototype.fillJSON_ = function(content) { | 288 return this instanceof ScriptMirror; |
| 305 this.fillJSONType_(content); | 289 } |
| 306 }; | |
| 307 | 290 |
| 308 | 291 |
| 309 /** | 292 /** |
| 310 * Serialize object in JSON format. For the basic mirrors this includes only | 293 * Serialize object in JSON format. The actual serialization is handled by the |
| 311 * the type in the following format. | 294 * JSONProtocolSerializer. |
| 312 * {"type":"<type name>"} | |
| 313 * For specialized mirrors inheriting from the base Mirror | |
| 314 * @param {boolean} details Indicate level of details to include | 295 * @param {boolean} details Indicate level of details to include |
| 315 * @return {string} JSON serialization | 296 * @return {string} JSON serialization |
| 316 */ | 297 */ |
| 317 Mirror.prototype.toJSONProtocol = function(details, propertiesKind, interceptorP
ropertiesKind) { | 298 Mirror.prototype.toJSONProtocol = function(details) { |
| 318 var content = new Array(); | 299 var serializer = new JSONProtocolSerializer(details) |
| 319 this.fillJSON_(content, details, propertiesKind, interceptorPropertiesKind); | 300 return serializer.serialize(this) |
| 320 content.push(MakeJSONPair_('text', StringToJSON_(this.toText()))); | |
| 321 return ArrayToJSONObject_(content); | |
| 322 } | 301 } |
| 323 | 302 |
| 324 | 303 |
| 325 Mirror.prototype.toText = function() { | 304 Mirror.prototype.toText = function() { |
| 326 // Simpel to text which is used when on specialization in subclass. | 305 // Simpel to text which is used when on specialization in subclass. |
| 327 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; | 306 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; |
| 328 } | 307 } |
| 329 | 308 |
| 330 | 309 |
| 331 /** | 310 /** |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 * @param {boolean} value The boolean value reflected by this mirror | 381 * @param {boolean} value The boolean value reflected by this mirror |
| 403 * @constructor | 382 * @constructor |
| 404 * @extends ValueMirror | 383 * @extends ValueMirror |
| 405 */ | 384 */ |
| 406 function BooleanMirror(value) { | 385 function BooleanMirror(value) { |
| 407 ValueMirror.call(this, BOOLEAN_TYPE, value); | 386 ValueMirror.call(this, BOOLEAN_TYPE, value); |
| 408 } | 387 } |
| 409 inherits(BooleanMirror, ValueMirror); | 388 inherits(BooleanMirror, ValueMirror); |
| 410 | 389 |
| 411 | 390 |
| 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() { | 391 BooleanMirror.prototype.toText = function() { |
| 419 return this.value_ ? 'true' : 'false'; | 392 return this.value_ ? 'true' : 'false'; |
| 420 } | 393 } |
| 421 | 394 |
| 422 | 395 |
| 423 /** | 396 /** |
| 424 * Mirror object for number values. | 397 * Mirror object for number values. |
| 425 * @param {number} value The number value reflected by this mirror | 398 * @param {number} value The number value reflected by this mirror |
| 426 * @constructor | 399 * @constructor |
| 427 * @extends ValueMirror | 400 * @extends ValueMirror |
| 428 */ | 401 */ |
| 429 function NumberMirror(value) { | 402 function NumberMirror(value) { |
| 430 ValueMirror.call(this, NUMBER_TYPE, value); | 403 ValueMirror.call(this, NUMBER_TYPE, value); |
| 431 } | 404 } |
| 432 inherits(NumberMirror, ValueMirror); | 405 inherits(NumberMirror, ValueMirror); |
| 433 | 406 |
| 434 | 407 |
| 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() { | 408 NumberMirror.prototype.toText = function() { |
| 442 return %NumberToString(this.value_); | 409 return %NumberToString(this.value_); |
| 443 } | 410 } |
| 444 | 411 |
| 445 | 412 |
| 446 /** | 413 /** |
| 447 * Mirror object for string values. | 414 * Mirror object for string values. |
| 448 * @param {string} value The string value reflected by this mirror | 415 * @param {string} value The string value reflected by this mirror |
| 449 * @constructor | 416 * @constructor |
| 450 * @extends ValueMirror | 417 * @extends ValueMirror |
| 451 */ | 418 */ |
| 452 function StringMirror(value) { | 419 function StringMirror(value) { |
| 453 ValueMirror.call(this, STRING_TYPE, value); | 420 ValueMirror.call(this, STRING_TYPE, value); |
| 454 } | 421 } |
| 455 inherits(StringMirror, ValueMirror); | 422 inherits(StringMirror, ValueMirror); |
| 456 | 423 |
| 457 | 424 |
| 458 StringMirror.prototype.length = function() { | 425 StringMirror.prototype.length = function() { |
| 459 return this.value_.length; | 426 return this.value_.length; |
| 460 }; | 427 }; |
| 461 | 428 |
| 462 | 429 |
| 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() { | 430 StringMirror.prototype.toText = function() { |
| 479 if (this.length() > kMaxProtocolStringLength) { | 431 if (this.length() > kMaxProtocolStringLength) { |
| 480 return this.value_.substring(0, kMaxProtocolStringLength) + | 432 return this.value_.substring(0, kMaxProtocolStringLength) + |
| 481 '... (length: ' + this.length() + ')'; | 433 '... (length: ' + this.length() + ')'; |
| 482 } else { | 434 } else { |
| 483 return this.value_; | 435 return this.value_; |
| 484 } | 436 } |
| 485 } | 437 } |
| 486 | 438 |
| 487 | 439 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 value | 491 value |
| 540 * @return {Array} Property names for this object | 492 * @return {Array} Property names for this object |
| 541 */ | 493 */ |
| 542 ObjectMirror.prototype.propertyNames = function(kind, limit) { | 494 ObjectMirror.prototype.propertyNames = function(kind, limit) { |
| 543 // Find kind and limit and allocate array for the result | 495 // Find kind and limit and allocate array for the result |
| 544 kind = kind || PropertyKind.Named | PropertyKind.Indexed; | 496 kind = kind || PropertyKind.Named | PropertyKind.Indexed; |
| 545 | 497 |
| 546 var propertyNames; | 498 var propertyNames; |
| 547 var elementNames; | 499 var elementNames; |
| 548 var total = 0; | 500 var total = 0; |
| 501 |
| 502 // Find all the named properties. |
| 549 if (kind & PropertyKind.Named) { | 503 if (kind & PropertyKind.Named) { |
| 504 // Get the local property names. |
| 550 propertyNames = %DebugLocalPropertyNames(this.value_); | 505 propertyNames = %DebugLocalPropertyNames(this.value_); |
| 551 total += propertyNames.length; | 506 total += propertyNames.length; |
| 507 |
| 508 // Get names for named interceptor properties if any. |
| 509 if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) { |
| 510 var namedInterceptorNames = |
| 511 %DebugNamedInterceptorPropertyNames(this.value_); |
| 512 if (namedInterceptorNames) { |
| 513 propertyNames = propertyNames.concat(namedInterceptorNames); |
| 514 total += namedInterceptorNames.length; |
| 515 } |
| 516 } |
| 552 } | 517 } |
| 518 |
| 519 // Find all the indexed properties. |
| 553 if (kind & PropertyKind.Indexed) { | 520 if (kind & PropertyKind.Indexed) { |
| 554 elementNames = %DebugLocalElementNames(this.value_) | 521 // Get the local element names. |
| 522 elementNames = %DebugLocalElementNames(this.value_); |
| 555 total += elementNames.length; | 523 total += elementNames.length; |
| 524 |
| 525 // Get names for indexed interceptor properties. |
| 526 if (this.hasIndexedInterceptor() && (kind & PropertyKind.Indexed)) { |
| 527 var indexedInterceptorNames = |
| 528 %DebugIndexedInterceptorElementNames(this.value_); |
| 529 if (indexedInterceptorNames) { |
| 530 elementNames = elementNames.concat(indexedInterceptorNames); |
| 531 total += indexedInterceptorNames.length; |
| 532 } |
| 533 } |
| 556 } | 534 } |
| 557 limit = Math.min(limit || total, total); | 535 limit = Math.min(limit || total, total); |
| 558 | 536 |
| 559 var names = new Array(limit); | 537 var names = new Array(limit); |
| 560 var index = 0; | 538 var index = 0; |
| 561 | 539 |
| 562 // Copy names for named properties. | 540 // Copy names for named properties. |
| 563 if (kind & PropertyKind.Named) { | 541 if (kind & PropertyKind.Named) { |
| 564 for (var i = 0; index < limit && i < propertyNames.length; i++) { | 542 for (var i = 0; index < limit && i < propertyNames.length; i++) { |
| 565 names[index++] = propertyNames[i]; | 543 names[index++] = propertyNames[i]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 589 var names = this.propertyNames(kind, limit); | 567 var names = this.propertyNames(kind, limit); |
| 590 var properties = new Array(names.length); | 568 var properties = new Array(names.length); |
| 591 for (var i = 0; i < names.length; i++) { | 569 for (var i = 0; i < names.length; i++) { |
| 592 properties[i] = this.property(names[i]); | 570 properties[i] = this.property(names[i]); |
| 593 } | 571 } |
| 594 | 572 |
| 595 return properties; | 573 return properties; |
| 596 }; | 574 }; |
| 597 | 575 |
| 598 | 576 |
| 599 /** | |
| 600 * Return the interceptor property names for this object. | |
| 601 * @param {number} kind Indicate whether named, indexed or both kinds of | |
| 602 * interceptor properties are requested | |
| 603 * @param {number} limit Limit the number of names returend to the specified | |
| 604 value | |
| 605 * @return {Array} interceptor property names for this object | |
| 606 */ | |
| 607 ObjectMirror.prototype.interceptorPropertyNames = function(kind, limit) { | |
| 608 // Find kind. | |
| 609 kind = kind || PropertyKind.Named | PropertyKind.Indexed; | |
| 610 var namedInterceptorNames; | |
| 611 var indexedInterceptorNames; | |
| 612 | |
| 613 // Get names for named interceptor properties. | |
| 614 if (this.hasNamedInterceptor() && kind & PropertyKind.Named) { | |
| 615 namedInterceptorNames = %DebugNamedInterceptorPropertyNames(this.value_); | |
| 616 } | |
| 617 | |
| 618 // Get names for indexed interceptor properties. | |
| 619 if (this.hasIndexedInterceptor() && kind & PropertyKind.Indexed) { | |
| 620 indexedInterceptorNames = %DebugIndexedInterceptorElementNames(this.value_); | |
| 621 } | |
| 622 | |
| 623 // Return either retult or both concattenated. | |
| 624 if (namedInterceptorNames && indexedInterceptorNames) { | |
| 625 return namedInterceptorNames.concat(indexedInterceptorNames); | |
| 626 } else if (namedInterceptorNames) { | |
| 627 return namedInterceptorNames; | |
| 628 } else if (indexedInterceptorNames) { | |
| 629 return indexedInterceptorNames; | |
| 630 } else { | |
| 631 return new Array(0); | |
| 632 } | |
| 633 }; | |
| 634 | |
| 635 | |
| 636 /** | |
| 637 * Return interceptor properties this object. | |
| 638 * @param {number} opt_kind Indicate whether named, indexed or both kinds of | |
| 639 * interceptor properties are requested | |
| 640 * @param {Array} opt_names Limit the number of properties returned to the | |
| 641 specified value | |
| 642 * @return {Array} properties this object as an array of PropertyMirror objects | |
| 643 */ | |
| 644 ObjectMirror.prototype.interceptorProperties = function(opt_kind, opt_names) { | |
| 645 // Find kind. | |
| 646 var kind = opt_kind || PropertyKind.Named | PropertyKind.Indexed; | |
| 647 var namedInterceptorProperties; | |
| 648 var indexedInterceptorProperties; | |
| 649 | |
| 650 // Get values for named interceptor properties. | |
| 651 if (kind & PropertyKind.Named) { | |
| 652 var names = opt_names || this.interceptorPropertyNames(PropertyKind.Named); | |
| 653 namedInterceptorProperties = new Array(names.length); | |
| 654 for (i = 0; i < names.length; i++) { | |
| 655 var value = %DebugNamedInterceptorPropertyValue(this.value_, names[i]); | |
| 656 namedInterceptorProperties[i] = new InterceptorPropertyMirror(this, names[
i], value); | |
| 657 } | |
| 658 } | |
| 659 | |
| 660 // Get values for indexed interceptor properties. | |
| 661 if (kind & PropertyKind.Indexed) { | |
| 662 var names = opt_names || this.interceptorPropertyNames(PropertyKind.Indexed)
; | |
| 663 indexedInterceptorProperties = new Array(names.length); | |
| 664 for (i = 0; i < names.length; i++) { | |
| 665 // Don't try to get the value if the name is not a number. | |
| 666 if (IS_NUMBER(names[i])) { | |
| 667 var value = %DebugIndexedInterceptorElementValue(this.value_, names[i]); | |
| 668 indexedInterceptorProperties[i] = new InterceptorPropertyMirror(this, na
mes[i], value); | |
| 669 } | |
| 670 } | |
| 671 } | |
| 672 | |
| 673 // Return either result or both concattenated. | |
| 674 if (namedInterceptorProperties && indexedInterceptorProperties) { | |
| 675 return namedInterceptorProperties.concat(indexedInterceptorProperties); | |
| 676 } else if (namedInterceptorProperties) { | |
| 677 return namedInterceptorProperties; | |
| 678 } else { | |
| 679 return indexedInterceptorProperties; | |
| 680 } | |
| 681 }; | |
| 682 | |
| 683 | |
| 684 ObjectMirror.prototype.property = function(name) { | 577 ObjectMirror.prototype.property = function(name) { |
| 685 var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); | 578 var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); |
| 686 if (details) { | 579 if (details) { |
| 687 return new PropertyMirror(this, name, details[0], details[1]); | 580 return new PropertyMirror(this, name, details); |
| 688 } | 581 } |
| 689 | 582 |
| 690 // Nothing found. | 583 // Nothing found. |
| 691 return new UndefinedMirror(); | 584 return new UndefinedMirror(); |
| 692 }; | 585 }; |
| 693 | 586 |
| 694 | 587 |
| 695 | 588 |
| 696 /** | 589 /** |
| 697 * Try to find a property from its value. | 590 * Try to find a property from its value. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 624 |
| 732 // Make mirrors for all the instances found. | 625 // Make mirrors for all the instances found. |
| 733 for (var i = 0; i < result.length; i++) { | 626 for (var i = 0; i < result.length; i++) { |
| 734 result[i] = MakeMirror(result[i]); | 627 result[i] = MakeMirror(result[i]); |
| 735 } | 628 } |
| 736 | 629 |
| 737 return result; | 630 return result; |
| 738 }; | 631 }; |
| 739 | 632 |
| 740 | 633 |
| 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() { | 634 ObjectMirror.prototype.toText = function() { |
| 785 var name; | 635 var name; |
| 786 var ctor = this.constructorFunction(); | 636 var ctor = this.constructorFunction(); |
| 787 if (ctor.isUndefined()) { | 637 if (ctor.isUndefined()) { |
| 788 name = this.className(); | 638 name = this.className(); |
| 789 } else { | 639 } else { |
| 790 name = ctor.name(); | 640 name = ctor.name(); |
| 791 if (!name) { | 641 if (!name) { |
| 792 name = this.className(); | 642 name = this.className(); |
| 793 } | 643 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 result[i] = MakeMirror(result[i]); | 727 result[i] = MakeMirror(result[i]); |
| 878 } | 728 } |
| 879 | 729 |
| 880 return result; | 730 return result; |
| 881 } else { | 731 } else { |
| 882 return []; | 732 return []; |
| 883 } | 733 } |
| 884 }; | 734 }; |
| 885 | 735 |
| 886 | 736 |
| 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() { | 737 FunctionMirror.prototype.toText = function() { |
| 903 return this.source(); | 738 return this.source(); |
| 904 } | 739 } |
| 905 | 740 |
| 906 | 741 |
| 907 /** | 742 /** |
| 908 * Mirror object for unresolved functions. | 743 * Mirror object for unresolved functions. |
| 909 * @param {string} value The name for the unresolved function reflected by this | 744 * @param {string} value The name for the unresolved function reflected by this |
| 910 * mirror. | 745 * mirror. |
| 911 * @constructor | 746 * @constructor |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 806 |
| 972 ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_
to_index) { | 807 ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_
to_index) { |
| 973 var from_index = opt_from_index || 0; | 808 var from_index = opt_from_index || 0; |
| 974 var to_index = opt_to_index || this.length() - 1; | 809 var to_index = opt_to_index || this.length() - 1; |
| 975 if (from_index > to_index) return new Array(); | 810 if (from_index > to_index) return new Array(); |
| 976 var values = new Array(to_index - from_index + 1); | 811 var values = new Array(to_index - from_index + 1); |
| 977 for (var i = from_index; i <= to_index; i++) { | 812 for (var i = from_index; i <= to_index; i++) { |
| 978 var details = %DebugGetPropertyDetails(this.value_, %ToString(i)); | 813 var details = %DebugGetPropertyDetails(this.value_, %ToString(i)); |
| 979 var value; | 814 var value; |
| 980 if (details) { | 815 if (details) { |
| 981 value = new PropertyMirror(this, i, details[0], details[1]); | 816 value = new PropertyMirror(this, i, details); |
| 982 } else { | 817 } else { |
| 983 value = new UndefinedMirror(); | 818 value = new UndefinedMirror(); |
| 984 } | 819 } |
| 985 values[i - from_index] = value; | 820 values[i - from_index] = value; |
| 986 } | 821 } |
| 987 return values; | 822 return values; |
| 988 } | 823 } |
| 989 | 824 |
| 990 | 825 |
| 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 /** | 826 /** |
| 1004 * Mirror object for dates. | 827 * Mirror object for dates. |
| 1005 * @param {Date} value The Date object reflected by this mirror | 828 * @param {Date} value The Date object reflected by this mirror |
| 1006 * @constructor | 829 * @constructor |
| 1007 * @extends ObjectMirror | 830 * @extends ObjectMirror |
| 1008 */ | 831 */ |
| 1009 function DateMirror(value) { | 832 function DateMirror(value) { |
| 1010 ObjectMirror.call(this, value); | 833 ObjectMirror.call(this, value); |
| 1011 } | 834 } |
| 1012 inherits(DateMirror, ObjectMirror); | 835 inherits(DateMirror, ObjectMirror); |
| 1013 | 836 |
| 1014 | 837 |
| 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() { | 838 DateMirror.prototype.toText = function() { |
| 1024 return DateToISO8601_(this.value_); | 839 return DateToISO8601_(this.value_); |
| 1025 } | 840 } |
| 1026 | 841 |
| 1027 | 842 |
| 1028 /** | 843 /** |
| 1029 * Mirror object for regular expressions. | 844 * Mirror object for regular expressions. |
| 1030 * @param {RegExp} value The RegExp object reflected by this mirror | 845 * @param {RegExp} value The RegExp object reflected by this mirror |
| 1031 * @constructor | 846 * @constructor |
| 1032 * @extends ObjectMirror | 847 * @extends ObjectMirror |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 | 881 |
| 1067 /** | 882 /** |
| 1068 * Returns whether this regular expression has the multiline (m) flag set. | 883 * Returns whether this regular expression has the multiline (m) flag set. |
| 1069 * @return {boolean} Value of the multiline flag | 884 * @return {boolean} Value of the multiline flag |
| 1070 */ | 885 */ |
| 1071 RegExpMirror.prototype.multiline = function() { | 886 RegExpMirror.prototype.multiline = function() { |
| 1072 return this.value_.multiline; | 887 return this.value_.multiline; |
| 1073 }; | 888 }; |
| 1074 | 889 |
| 1075 | 890 |
| 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() { | 891 RegExpMirror.prototype.toText = function() { |
| 1088 // Simpel to text which is used when on specialization in subclass. | 892 // Simpel to text which is used when on specialization in subclass. |
| 1089 return "/" + this.source() + "/"; | 893 return "/" + this.source() + "/"; |
| 1090 } | 894 } |
| 1091 | 895 |
| 1092 | 896 |
| 1093 /** | 897 /** |
| 1094 * Mirror object for error objects. | 898 * Mirror object for error objects. |
| 1095 * @param {Error} value The error object reflected by this mirror | 899 * @param {Error} value The error object reflected by this mirror |
| 1096 * @constructor | 900 * @constructor |
| 1097 * @extends ObjectMirror | 901 * @extends ObjectMirror |
| 1098 */ | 902 */ |
| 1099 function ErrorMirror(value) { | 903 function ErrorMirror(value) { |
| 1100 ObjectMirror.call(this, value, ERROR_TYPE); | 904 ObjectMirror.call(this, value, ERROR_TYPE); |
| 1101 } | 905 } |
| 1102 inherits(ErrorMirror, ObjectMirror); | 906 inherits(ErrorMirror, ObjectMirror); |
| 1103 | 907 |
| 1104 | 908 |
| 1105 /** | 909 /** |
| 1106 * Returns the message for this eror object. | 910 * Returns the message for this eror object. |
| 1107 * @return {string or undefined} The message for this eror object | 911 * @return {string or undefined} The message for this eror object |
| 1108 */ | 912 */ |
| 1109 ErrorMirror.prototype.message = function() { | 913 ErrorMirror.prototype.message = function() { |
| 1110 return this.value_.message; | 914 return this.value_.message; |
| 1111 }; | 915 }; |
| 1112 | 916 |
| 1113 | 917 |
| 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() { | 918 ErrorMirror.prototype.toText = function() { |
| 1123 // Use the same text representation as in messages.js. | 919 // Use the same text representation as in messages.js. |
| 1124 var text; | 920 var text; |
| 1125 try { | 921 try { |
| 1126 str = builtins.ToDetailString(this.value_); | 922 str = builtins.ToDetailString(this.value_); |
| 1127 } catch (e) { | 923 } catch (e) { |
| 1128 str = '#<an Error>'; | 924 str = '#<an Error>'; |
| 1129 } | 925 } |
| 1130 return str; | 926 return str; |
| 1131 } | 927 } |
| 1132 | 928 |
| 1133 | 929 |
| 1134 /** | 930 /** |
| 1135 * Base mirror object for properties. | 931 * Base mirror object for properties. |
| 1136 * @param {ObjectMirror} mirror The mirror object having this property | 932 * @param {ObjectMirror} mirror The mirror object having this property |
| 1137 * @param {string} name The name of the property | 933 * @param {string} name The name of the property |
| 1138 * @param {Object} value The value of the property | 934 * @param {Array} details Details about the property |
| 1139 * @constructor | 935 * @constructor |
| 1140 * @extends Mirror | 936 * @extends Mirror |
| 1141 */ | 937 */ |
| 1142 function PropertyMirror(mirror, name, value, details) { | 938 function PropertyMirror(mirror, name, details) { |
| 1143 Mirror.call(this, PROPERTY_TYPE); | 939 Mirror.call(this, PROPERTY_TYPE); |
| 1144 this.mirror_ = mirror; | 940 this.mirror_ = mirror; |
| 1145 this.name_ = name; | 941 this.name_ = name; |
| 1146 this.value_ = value; | 942 this.value_ = details[0]; |
| 1147 this.details_ = details; | 943 this.details_ = details[1]; |
| 944 if (details.length > 2) { |
| 945 this.exception_ = details[2] |
| 946 this.getter_ = details[3]; |
| 947 this.setter_ = details[4]; |
| 948 } |
| 1148 } | 949 } |
| 1149 inherits(PropertyMirror, Mirror); | 950 inherits(PropertyMirror, Mirror); |
| 1150 | 951 |
| 1151 | 952 |
| 1152 PropertyMirror.prototype.isReadOnly = function() { | 953 PropertyMirror.prototype.isReadOnly = function() { |
| 1153 return (this.attributes() & PropertyAttribute.ReadOnly) != 0; | 954 return (this.attributes() & PropertyAttribute.ReadOnly) != 0; |
| 1154 } | 955 } |
| 1155 | 956 |
| 1156 | 957 |
| 1157 PropertyMirror.prototype.isEnum = function() { | 958 PropertyMirror.prototype.isEnum = function() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1173 for (var i = 0; i < this.name_.length; i++) { | 974 for (var i = 0; i < this.name_.length; i++) { |
| 1174 if (this.name_[i] < '0' || '9' < this.name_[i]) { | 975 if (this.name_[i] < '0' || '9' < this.name_[i]) { |
| 1175 return false; | 976 return false; |
| 1176 } | 977 } |
| 1177 } | 978 } |
| 1178 return true; | 979 return true; |
| 1179 } | 980 } |
| 1180 | 981 |
| 1181 | 982 |
| 1182 PropertyMirror.prototype.value = function() { | 983 PropertyMirror.prototype.value = function() { |
| 1183 if (this.propertyType() == PropertyType.Callbacks) { | 984 return MakeMirror(this.value_); |
| 1184 // TODO(1242933): AccessorMirror should have getter/setter values. | 985 } |
| 1185 return new AccessorMirror(); | 986 |
| 1186 } else if (this.type() == PropertyType.Interceptor) { | 987 |
| 1187 return new UndefinedMirror(); | 988 /** |
| 1188 } else { | 989 * Returns whether this property value is an exception. |
| 1189 return MakeMirror(this.value_); | 990 * @return {booolean} True if this property value is an exception |
| 1190 } | 991 */ |
| 992 PropertyMirror.prototype.isException = function() { |
| 993 return this.exception_ ? true : false; |
| 1191 } | 994 } |
| 1192 | 995 |
| 1193 | 996 |
| 1194 PropertyMirror.prototype.attributes = function() { | 997 PropertyMirror.prototype.attributes = function() { |
| 1195 return %DebugPropertyAttributesFromDetails(this.details_); | 998 return %DebugPropertyAttributesFromDetails(this.details_); |
| 1196 } | 999 } |
| 1197 | 1000 |
| 1198 | 1001 |
| 1199 PropertyMirror.prototype.propertyType = function() { | 1002 PropertyMirror.prototype.propertyType = function() { |
| 1200 return %DebugPropertyTypeFromDetails(this.details_); | 1003 return %DebugPropertyTypeFromDetails(this.details_); |
| 1201 } | 1004 } |
| 1202 | 1005 |
| 1203 | 1006 |
| 1204 PropertyMirror.prototype.insertionIndex = function() { | 1007 PropertyMirror.prototype.insertionIndex = function() { |
| 1205 return %DebugPropertyIndexFromDetails(this.details_); | 1008 return %DebugPropertyIndexFromDetails(this.details_); |
| 1206 } | 1009 } |
| 1207 | 1010 |
| 1208 | 1011 |
| 1209 PropertyMirror.prototype.fillJSON_ = function(content, details) { | 1012 /** |
| 1210 content.push(MakeJSONPair_('name', StringToJSON_(this.name()))); | 1013 * Returns whether this property has a getter defined through __defineGetter__. |
| 1211 content.push(MakeJSONPair_('value', this.value().toJSONProtocol(details))); | 1014 * @return {booolean} True if this property has a getter |
| 1212 if (this.attributes() != PropertyAttribute.None) { | 1015 */ |
| 1213 content.push(MakeJSONPair_('attributes', NumberToJSON_(this.attributes()))); | 1016 PropertyMirror.prototype.hasGetter = function() { |
| 1214 } | 1017 return this.getter_ ? true : false; |
| 1215 if (this.propertyType() != PropertyType.Normal) { | 1018 } |
| 1216 content.push(MakeJSONPair_('propertyType', NumberToJSON_(this.propertyType()
))); | 1019 |
| 1020 |
| 1021 /** |
| 1022 * Returns whether this property has a setter defined through __defineSetter__. |
| 1023 * @return {booolean} True if this property has a setter |
| 1024 */ |
| 1025 PropertyMirror.prototype.hasSetter = function() { |
| 1026 return this.setter_ ? true : false; |
| 1027 } |
| 1028 |
| 1029 |
| 1030 /** |
| 1031 * Returns the getter for this property defined through __defineGetter__. |
| 1032 * @return {Mirror} FunctionMirror reflecting the getter function or |
| 1033 * UndefinedMirror if there is no getter for this property |
| 1034 */ |
| 1035 PropertyMirror.prototype.getter = function() { |
| 1036 if (this.hasGetter()) { |
| 1037 return MakeMirror(this.getter_); |
| 1038 } else { |
| 1039 return new UndefinedMirror(); |
| 1217 } | 1040 } |
| 1218 } | 1041 } |
| 1219 | 1042 |
| 1220 | 1043 |
| 1221 /** | 1044 /** |
| 1222 * Mirror object for interceptor named properties. | 1045 * Returns the setter for this property defined through __defineSetter__. |
| 1223 * @param {ObjectMirror} mirror The mirror object having this property | 1046 * @return {Mirror} FunctionMirror reflecting the setter function or |
| 1224 * @param {String} name The name of the property | 1047 * UndefinedMirror if there is no setter for this property |
| 1225 * @param {value} value The value of the property | |
| 1226 * @constructor | |
| 1227 * @extends PropertyMirror | |
| 1228 */ | 1048 */ |
| 1229 function InterceptorPropertyMirror(mirror, name, value) { | 1049 PropertyMirror.prototype.setter = function() { |
| 1230 PropertyMirror.call(this, mirror, name, value, PropertyType.Interceptor); | 1050 if (this.hasSetter()) { |
| 1231 } | 1051 return MakeMirror(this.setter_); |
| 1232 inherits(InterceptorPropertyMirror, PropertyMirror); | 1052 } else { |
| 1233 | 1053 return new UndefinedMirror(); |
| 1234 | 1054 } |
| 1235 /** | |
| 1236 * Mirror object for property accessors. | |
| 1237 * @param {Function} getter The getter function for this accessor | |
| 1238 * @param {Function} setter The setter function for this accessor | |
| 1239 * @constructor | |
| 1240 * @extends Mirror | |
| 1241 */ | |
| 1242 function AccessorMirror(getter, setter) { | |
| 1243 Mirror.call(this, ACCESSOR_TYPE); | |
| 1244 this.getter_ = getter; | |
| 1245 this.setter_ = setter; | |
| 1246 } | |
| 1247 inherits(AccessorMirror, Mirror); | |
| 1248 | |
| 1249 | |
| 1250 /** | |
| 1251 * Returns whether this accessor is native or not. A native accessor is either | |
| 1252 * a VM buildin or provided through the API. A non native accessor is defined | |
| 1253 * in JavaScript using the __defineGetter__ and/or __defineGetter__ functions. | |
| 1254 * @return {boolean} True is the accessor is native | |
| 1255 */ | |
| 1256 AccessorMirror.prototype.isNative = function() { | |
| 1257 return IS_UNDEFINED(this.getter_) && IS_UNDEFINED(this.setter_); | |
| 1258 } | 1055 } |
| 1259 | 1056 |
| 1260 | 1057 |
| 1261 /** | 1058 /** |
| 1262 * Returns a mirror for the function of a non native getter. | 1059 * Returns whether this property is natively implemented by the host or a set |
| 1263 * @return {FunctionMirror} Function mirror for the getter set using | 1060 * through JavaScript code. |
| 1264 * __defineGetter__. | 1061 * @return {boolean} True if the property is |
| 1062 * UndefinedMirror if there is no setter for this property |
| 1265 */ | 1063 */ |
| 1266 AccessorMirror.prototype.getter = function(details) { | 1064 PropertyMirror.prototype.isNative = function() { |
| 1267 return MakeMirror(this.getter_); | 1065 return (this.propertyType() == PropertyType.Interceptor) || |
| 1268 } | 1066 ((this.propertyType() == PropertyType.Callbacks) && |
| 1269 | 1067 !this.hasGetter() && !this.hasSetter()); |
| 1270 | |
| 1271 /** | |
| 1272 * Returns a mirror for the function of a non native setter. | |
| 1273 * @return {FunctionMirror} Function mirror for the getter set using | |
| 1274 * __defineSetter__. | |
| 1275 */ | |
| 1276 AccessorMirror.prototype.setter = function(details) { | |
| 1277 return MakeMirror(this.setter_); | |
| 1278 } | |
| 1279 | |
| 1280 | |
| 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 } | 1068 } |
| 1301 | 1069 |
| 1302 | 1070 |
| 1303 const kFrameDetailsFrameIdIndex = 0; | 1071 const kFrameDetailsFrameIdIndex = 0; |
| 1304 const kFrameDetailsReceiverIndex = 1; | 1072 const kFrameDetailsReceiverIndex = 1; |
| 1305 const kFrameDetailsFunctionIndex = 2; | 1073 const kFrameDetailsFunctionIndex = 2; |
| 1306 const kFrameDetailsArgumentCountIndex = 3; | 1074 const kFrameDetailsArgumentCountIndex = 3; |
| 1307 const kFrameDetailsLocalCountIndex = 4; | 1075 const kFrameDetailsLocalCountIndex = 4; |
| 1308 const kFrameDetailsSourcePositionIndex = 5; | 1076 const kFrameDetailsSourcePositionIndex = 5; |
| 1309 const kFrameDetailsConstructCallIndex = 6; | 1077 const kFrameDetailsConstructCallIndex = 6; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 }; | 1319 }; |
| 1552 | 1320 |
| 1553 | 1321 |
| 1554 FrameMirror.prototype.evaluate = function(source, disable_break) { | 1322 FrameMirror.prototype.evaluate = function(source, disable_break) { |
| 1555 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), | 1323 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), |
| 1556 source, Boolean(disable_break)); | 1324 source, Boolean(disable_break)); |
| 1557 return MakeMirror(result); | 1325 return MakeMirror(result); |
| 1558 }; | 1326 }; |
| 1559 | 1327 |
| 1560 | 1328 |
| 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() { | 1329 FrameMirror.prototype.invocationText = function() { |
| 1603 // Format frame invoaction (receiver, function and arguments). | 1330 // Format frame invoaction (receiver, function and arguments). |
| 1604 var result = ''; | 1331 var result = ''; |
| 1605 var func = this.func(); | 1332 var func = this.func(); |
| 1606 var receiver = this.receiver(); | 1333 var receiver = this.receiver(); |
| 1607 if (this.isConstructCall()) { | 1334 if (this.isConstructCall()) { |
| 1608 // For constructor frames display new followed by the function name. | 1335 // For constructor frames display new followed by the function name. |
| 1609 result += 'new '; | 1336 result += 'new '; |
| 1610 result += func.name() ? func.name() : '[anonymous]'; | 1337 result += func.name() ? func.name() : '[anonymous]'; |
| 1611 } else if (this.isDebuggerFrame()) { | 1338 } else if (this.isDebuggerFrame()) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 ScriptMirror.prototype.locationFromPosition = function(position) { | 1503 ScriptMirror.prototype.locationFromPosition = function(position) { |
| 1777 return this.script_.locationFromPosition(position); | 1504 return this.script_.locationFromPosition(position); |
| 1778 } | 1505 } |
| 1779 | 1506 |
| 1780 | 1507 |
| 1781 ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) { | 1508 ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) { |
| 1782 return this.script_.sourceSlice(opt_from_line, opt_to_line); | 1509 return this.script_.sourceSlice(opt_from_line, opt_to_line); |
| 1783 } | 1510 } |
| 1784 | 1511 |
| 1785 | 1512 |
| 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() { | 1513 ScriptMirror.prototype.toText = function() { |
| 1799 var result = ''; | 1514 var result = ''; |
| 1800 result += this.name(); | 1515 result += this.name(); |
| 1801 result += ' (lines: '; | 1516 result += ' (lines: '; |
| 1802 if (this.lineOffset() > 0) { | 1517 if (this.lineOffset() > 0) { |
| 1803 result += this.lineOffset(); | 1518 result += this.lineOffset(); |
| 1804 result += '-'; | 1519 result += '-'; |
| 1805 result += this.lineOffset() + this.lineCount() - 1; | 1520 result += this.lineOffset() + this.lineCount() - 1; |
| 1806 } else { | 1521 } else { |
| 1807 result += this.lineCount(); | 1522 result += this.lineCount(); |
| 1808 } | 1523 } |
| 1809 result += ')'; | 1524 result += ')'; |
| 1810 return result; | 1525 return result; |
| 1811 } | 1526 } |
| 1812 | 1527 |
| 1813 | 1528 |
| 1529 function JSONProtocolSerializer(details) { |
| 1530 this.details_ = details; |
| 1531 } |
| 1532 |
| 1533 |
| 1534 JSONProtocolSerializer.prototype.serialize = function(mirror) { |
| 1535 // Collect the JSON property/value pairs in a array. |
| 1536 var content = new Array(); |
| 1537 |
| 1538 // Always add the type |
| 1539 content.push(MakeJSONPair_('type', StringToJSON_(mirror.type()))); |
| 1540 |
| 1541 switch (mirror.type()) { |
| 1542 case UNDEFINED_TYPE: |
| 1543 case NULL_TYPE: |
| 1544 // Undefined and null are represented just by their type. |
| 1545 break; |
| 1546 |
| 1547 case BOOLEAN_TYPE: |
| 1548 // Boolean values are simply represented by their value. |
| 1549 content.push(MakeJSONPair_('value', BooleanToJSON_(mirror.value()))); |
| 1550 break; |
| 1551 |
| 1552 case NUMBER_TYPE: |
| 1553 // Number values are simply represented by their value. |
| 1554 content.push(MakeJSONPair_('value', NumberToJSON_(mirror.value()))); |
| 1555 break; |
| 1556 |
| 1557 case STRING_TYPE: |
| 1558 // String values might have their value cropped to keep down size. |
| 1559 if (mirror.length() > kMaxProtocolStringLength) { |
| 1560 var str = mirror.value().substring(0, kMaxProtocolStringLength); |
| 1561 content.push(MakeJSONPair_('value', StringToJSON_(str))); |
| 1562 content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0))); |
| 1563 content.push(MakeJSONPair_('toIndex', |
| 1564 NumberToJSON_(kMaxProtocolStringLength))); |
| 1565 } else { |
| 1566 content.push(MakeJSONPair_('value', StringToJSON_(mirror.value()))); |
| 1567 } |
| 1568 content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length()))); |
| 1569 break; |
| 1570 |
| 1571 case OBJECT_TYPE: |
| 1572 case FUNCTION_TYPE: |
| 1573 case ERROR_TYPE: |
| 1574 case REGEXP_TYPE: |
| 1575 // Add object representation. |
| 1576 this.serializeObject_(mirror, content); |
| 1577 break; |
| 1578 |
| 1579 case PROPERTY_TYPE: |
| 1580 // Properties are represented by name, value, attributes and type. |
| 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; |
| 1606 |
| 1607 case FRAME_TYPE: |
| 1608 // Add object representation. |
| 1609 this.serializeFrame_(mirror, content); |
| 1610 break; |
| 1611 |
| 1612 case SCRIPT_TYPE: |
| 1613 // Script is represented by name and source attributes. |
| 1614 if (mirror.name()) { |
| 1615 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); |
| 1616 } |
| 1617 content.push(MakeJSONPair_('lineOffset', |
| 1618 NumberToJSON_(mirror.lineOffset()))); |
| 1619 content.push(MakeJSONPair_('columnOffset', |
| 1620 NumberToJSON_(mirror.columnOffset()))); |
| 1621 content.push(MakeJSONPair_('lineCount', |
| 1622 NumberToJSON_(mirror.lineCount()))); |
| 1623 content.push(MakeJSONPair_('scriptType', |
| 1624 NumberToJSON_(mirror.scriptType()))); |
| 1625 break; |
| 1626 |
| 1627 } |
| 1628 |
| 1629 // Always add the text representation. |
| 1630 content.push(MakeJSONPair_('text', StringToJSON_(mirror.toText()))); |
| 1631 |
| 1632 // Create and return the JSON string. |
| 1633 return ArrayToJSONObject_(content); |
| 1634 } |
| 1635 |
| 1636 |
| 1637 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content) { |
| 1638 content.push(MakeJSONPair_('className', |
| 1639 StringToJSON_(mirror.className()))); |
| 1640 |
| 1641 if (this.details_) { |
| 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()) { |
| 1677 content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true))); |
| 1678 } |
| 1679 |
| 1680 if (mirror.hasIndexedInterceptor()) { |
| 1681 content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true))); |
| 1682 } |
| 1683 |
| 1684 if (mirror.isFunction()) { |
| 1685 // Add function specific properties. |
| 1686 content.push(MakeJSONPair_('name', StringToJSON_(mirror.name()))); |
| 1687 content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved()))); |
| 1688 if (this.details_ && mirror.resolved()) { |
| 1689 content.push(MakeJSONPair_('source', StringToJSON_(mirror.source()))); |
| 1690 } |
| 1691 if (mirror.script()) { |
| 1692 content.push(MakeJSONPair_('script', mirror.script().toJSONProtocol())); |
| 1693 } |
| 1694 } else if (mirror.isDate()) { |
| 1695 // Add date specific properties. |
| 1696 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 } |
| 1709 } |
| 1710 |
| 1711 |
| 1712 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { |
| 1713 content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index()))); |
| 1714 content.push(MakeJSONPair_('receiver', |
| 1715 mirror.receiver().toJSONProtocol(false))); |
| 1716 content.push(MakeJSONPair_('func', mirror.func().toJSONProtocol(false))); |
| 1717 content.push(MakeJSONPair_('constructCall', |
| 1718 BooleanToJSON_(mirror.isConstructCall()))); |
| 1719 content.push(MakeJSONPair_('debuggerFrame', |
| 1720 BooleanToJSON_(mirror.isDebuggerFrame()))); |
| 1721 var x = new Array(mirror.argumentCount()); |
| 1722 for (var i = 0; i < mirror.argumentCount(); i++) { |
| 1723 arg = new Array(); |
| 1724 var argument_name = mirror.argumentName(i) |
| 1725 if (argument_name) { |
| 1726 arg.push(MakeJSONPair_('name', StringToJSON_(argument_name))); |
| 1727 } |
| 1728 arg.push(MakeJSONPair_('value', |
| 1729 mirror.argumentValue(i).toJSONProtocol(false))); |
| 1730 x[i] = ArrayToJSONObject_(arg); |
| 1731 } |
| 1732 content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x))); |
| 1733 var x = new Array(mirror.localCount()); |
| 1734 for (var i = 0; i < mirror.localCount(); i++) { |
| 1735 var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i))); |
| 1736 var value = MakeJSONPair_('value', |
| 1737 mirror.localValue(i).toJSONProtocol(false)); |
| 1738 x[i] = '{' + name + ',' + value + '}'; |
| 1739 } |
| 1740 content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x))); |
| 1741 content.push(MakeJSONPair_('position', |
| 1742 NumberToJSON_(mirror.sourcePosition()))); |
| 1743 var line = mirror.sourceLine(); |
| 1744 if (!IS_UNDEFINED(line)) { |
| 1745 content.push(MakeJSONPair_('line', NumberToJSON_(line))); |
| 1746 } |
| 1747 var column = mirror.sourceColumn(); |
| 1748 if (!IS_UNDEFINED(column)) { |
| 1749 content.push(MakeJSONPair_('column', NumberToJSON_(column))); |
| 1750 } |
| 1751 var source_line_text = mirror.sourceLineText(); |
| 1752 if (!IS_UNDEFINED(source_line_text)) { |
| 1753 content.push(MakeJSONPair_('sourceLineText', |
| 1754 StringToJSON_(source_line_text))); |
| 1755 } |
| 1756 } |
| 1757 |
| 1758 |
| 1814 function MakeJSONPair_(name, value) { | 1759 function MakeJSONPair_(name, value) { |
| 1815 return '"' + name + '":' + value; | 1760 return '"' + name + '":' + value; |
| 1816 } | 1761 } |
| 1817 | 1762 |
| 1818 | 1763 |
| 1819 function ArrayToJSONObject_(content) { | 1764 function ArrayToJSONObject_(content) { |
| 1820 return '{' + content.join(',') + '}'; | 1765 return '{' + content.join(',') + '}'; |
| 1821 } | 1766 } |
| 1822 | 1767 |
| 1823 | 1768 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 /** | 1860 /** |
| 1916 * Convert a Date to ISO 8601 format. To avoid depending on the Date object | 1861 * 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 | 1862 * this method calls the functions in date.js directly and not through the |
| 1918 * value. | 1863 * value. |
| 1919 * @param {Date} value The Date value to format as JSON | 1864 * @param {Date} value The Date value to format as JSON |
| 1920 * @return {string} JSON formatted Date value | 1865 * @return {string} JSON formatted Date value |
| 1921 */ | 1866 */ |
| 1922 function DateToJSON_(value) { | 1867 function DateToJSON_(value) { |
| 1923 return '"' + DateToISO8601_(value) + '"'; | 1868 return '"' + DateToISO8601_(value) + '"'; |
| 1924 } | 1869 } |
| OLD | NEW |