mirrors.js 60.2 KB
Newer Older
1
// Copyright 2006-2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5

(function(global, utils) {
6
"use strict";
7

8 9 10 11 12 13
// ----------------------------------------------------------------------------
// Imports

var GlobalArray = global.Array;
var IsNaN = global.isNaN;
var JSONStringify = global.JSON.stringify;
14 15 16 17
var MapEntries = global.Map.prototype.entries;
var MapIteratorNext = (new global.Map).entries().next;
var SetIteratorNext = (new global.Set).values().next;
var SetValues = global.Set.prototype.values;
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

// ----------------------------------------------------------------------------

// Mirror hierarchy:
// - Mirror
//   - ValueMirror
//     - UndefinedMirror
//     - NullMirror
//     - BooleanMirror
//     - NumberMirror
//     - StringMirror
//     - SymbolMirror
//     - ObjectMirror
//       - FunctionMirror
//         - UnresolvedFunctionMirror
//       - ArrayMirror
//       - DateMirror
//       - RegExpMirror
//       - ErrorMirror
//       - PromiseMirror
//       - MapMirror
//       - SetMirror
//       - IteratorMirror
//       - GeneratorMirror
//   - PropertyMirror
//   - InternalPropertyMirror
//   - FrameMirror
//   - ScriptMirror
//   - ScopeMirror

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
macro IS_BOOLEAN(arg)
(typeof(arg) === 'boolean')
endmacro

macro IS_DATE(arg)
(%IsDate(arg))
endmacro

macro IS_ERROR(arg)
(%_ClassOf(arg) === 'Error')
endmacro

macro IS_GENERATOR(arg)
(%_ClassOf(arg) === 'Generator')
endmacro

macro IS_MAP(arg)
(%_IsJSMap(arg))
endmacro

macro IS_MAP_ITERATOR(arg)
(%_ClassOf(arg) === 'Map Iterator')
endmacro

macro IS_SCRIPT(arg)
(%_ClassOf(arg) === 'Script')
endmacro

macro IS_SET(arg)
(%_IsJSSet(arg))
endmacro

macro IS_SET_ITERATOR(arg)
(%_ClassOf(arg) === 'Set Iterator')
endmacro

// Must match PropertyFilter in property-details.h
define PROPERTY_FILTER_NONE = 0;

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
// Type names of the different mirrors.
var MirrorType = {
  UNDEFINED_TYPE : 'undefined',
  NULL_TYPE : 'null',
  BOOLEAN_TYPE : 'boolean',
  NUMBER_TYPE : 'number',
  STRING_TYPE : 'string',
  SYMBOL_TYPE : 'symbol',
  OBJECT_TYPE : 'object',
  FUNCTION_TYPE : 'function',
  REGEXP_TYPE : 'regexp',
  ERROR_TYPE : 'error',
  PROPERTY_TYPE : 'property',
  INTERNAL_PROPERTY_TYPE : 'internalProperty',
  FRAME_TYPE : 'frame',
  SCRIPT_TYPE : 'script',
  CONTEXT_TYPE : 'context',
  SCOPE_TYPE : 'scope',
  PROMISE_TYPE : 'promise',
  MAP_TYPE : 'map',
  SET_TYPE : 'set',
  ITERATOR_TYPE : 'iterator',
  GENERATOR_TYPE : 'generator',
}

112 113 114
/**
 * Returns the mirror for a specified value or object.
 *
115
 * @param {value or Object} value the value or object to retrieve the mirror for
116 117
 * @returns {Mirror} the mirror reflects the passed value or object
 */
118
function MakeMirror(value) {
119
  var mirror;
120

121 122 123 124 125 126 127 128 129 130
  if (IS_UNDEFINED(value)) {
    mirror = new UndefinedMirror();
  } else if (IS_NULL(value)) {
    mirror = new NullMirror();
  } else if (IS_BOOLEAN(value)) {
    mirror = new BooleanMirror(value);
  } else if (IS_NUMBER(value)) {
    mirror = new NumberMirror(value);
  } else if (IS_STRING(value)) {
    mirror = new StringMirror(value);
131 132
  } else if (IS_SYMBOL(value)) {
    mirror = new SymbolMirror(value);
133 134 135 136 137 138
  } else if (IS_ARRAY(value)) {
    mirror = new ArrayMirror(value);
  } else if (IS_DATE(value)) {
    mirror = new DateMirror(value);
  } else if (IS_FUNCTION(value)) {
    mirror = new FunctionMirror(value);
139
  } else if (%IsRegExp(value)) {
140 141 142
    mirror = new RegExpMirror(value);
  } else if (IS_ERROR(value)) {
    mirror = new ErrorMirror(value);
143 144
  } else if (IS_SCRIPT(value)) {
    mirror = new ScriptMirror(value);
145 146
  } else if (IS_MAP(value) || IS_WEAKMAP(value)) {
    mirror = new MapMirror(value);
147 148
  } else if (IS_SET(value) || IS_WEAKSET(value)) {
    mirror = new SetMirror(value);
149 150
  } else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) {
    mirror = new IteratorMirror(value);
gsathya's avatar
gsathya committed
151
  } else if (%is_promise(value)) {
152
    mirror = new PromiseMirror(value);
153 154
  } else if (IS_GENERATOR(value)) {
    mirror = new GeneratorMirror(value);
155
  } else {
156
    mirror = new ObjectMirror(value, MirrorType.OBJECT_TYPE);
157 158 159 160 161 162 163 164 165 166 167 168
  }

  return mirror;
}


/**
 * Returns the mirror for the undefined value.
 *
 * @returns {Mirror} the mirror reflects the undefined value
 */
function GetUndefinedMirror() {
169
  return MakeMirror(UNDEFINED);
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
}


/**
 * Inherit the prototype methods from one constructor into another.
 *
 * The Function.prototype.inherits from lang.js rewritten as a standalone
 * function (not on Function.prototype). NOTE: If this file is to be loaded
 * during bootstrapping this function needs to be revritten using some native
 * functions as prototype setup using normal JavaScript does not work as
 * expected during bootstrapping (see mirror.js in r114903).
 *
 * @param {function} ctor Constructor function which needs to inherit the
 *     prototype
 * @param {function} superCtor Constructor function to inherit prototype from
 */
function inherits(ctor, superCtor) {
  var tempCtor = function(){};
  tempCtor.prototype = superCtor.prototype;
  ctor.super_ = superCtor.prototype;
  ctor.prototype = new tempCtor();
  ctor.prototype.constructor = ctor;
}

// Maximum length when sending strings through the JSON protocol.
195
var kMaxProtocolStringLength = 80;
196 197


198
// A copy of the PropertyKind enum from property-details.h
199
var PropertyType = {};
200 201
PropertyType.Data     = 0;
PropertyType.Accessor = 1;
202

203 204

// Different attributes for a property.
205
var PropertyAttribute = {};
206 207 208 209 210 211
PropertyAttribute.None       = NONE;
PropertyAttribute.ReadOnly   = READ_ONLY;
PropertyAttribute.DontEnum   = DONT_ENUM;
PropertyAttribute.DontDelete = DONT_DELETE;


212 213 214
// A copy of the scope types from runtime-debug.cc.
// NOTE: these constants should be backward-compatible, so
// add new ones to the end of this list.
215 216 217
var ScopeType = { Global:  0,
                  Local:   1,
                  With:    2,
218
                  Closure: 3,
219 220 221 222
                  Catch:   4,
                  Block:   5,
                  Script:  6,
                  Eval:    7,
223
                  Module:  8,
224
                };
225

226 227 228 229 230 231 232
/**
 * Base class for all mirror objects.
 * @param {string} type The type of the mirror
 * @constructor
 */
function Mirror(type) {
  this.type_ = type;
233
}
234 235 236 237 238 239 240


Mirror.prototype.type = function() {
  return this.type_;
};


241 242 243 244 245 246
/**
 * Check whether the mirror reflects a value.
 * @returns {boolean} True if the mirror reflects a value.
 */
Mirror.prototype.isValue = function() {
  return this instanceof ValueMirror;
247
};
248 249


250 251 252 253 254 255
/**
 * Check whether the mirror reflects the undefined value.
 * @returns {boolean} True if the mirror reflects the undefined value.
 */
Mirror.prototype.isUndefined = function() {
  return this instanceof UndefinedMirror;
256
};
257 258 259 260 261 262 263 264


/**
 * Check whether the mirror reflects the null value.
 * @returns {boolean} True if the mirror reflects the null value
 */
Mirror.prototype.isNull = function() {
  return this instanceof NullMirror;
265
};
266 267 268 269 270 271 272 273


/**
 * Check whether the mirror reflects a boolean value.
 * @returns {boolean} True if the mirror reflects a boolean value
 */
Mirror.prototype.isBoolean = function() {
  return this instanceof BooleanMirror;
274
};
275 276 277 278 279 280 281 282


/**
 * Check whether the mirror reflects a number value.
 * @returns {boolean} True if the mirror reflects a number value
 */
Mirror.prototype.isNumber = function() {
  return this instanceof NumberMirror;
283
};
284 285 286 287 288 289 290 291


/**
 * Check whether the mirror reflects a string value.
 * @returns {boolean} True if the mirror reflects a string value
 */
Mirror.prototype.isString = function() {
  return this instanceof StringMirror;
292
};
293 294


295 296 297 298 299 300 301 302 303
/**
 * Check whether the mirror reflects a symbol.
 * @returns {boolean} True if the mirror reflects a symbol
 */
Mirror.prototype.isSymbol = function() {
  return this instanceof SymbolMirror;
};


304 305 306 307 308 309
/**
 * Check whether the mirror reflects an object.
 * @returns {boolean} True if the mirror reflects an object
 */
Mirror.prototype.isObject = function() {
  return this instanceof ObjectMirror;
310
};
311 312 313 314 315 316 317 318


/**
 * Check whether the mirror reflects a function.
 * @returns {boolean} True if the mirror reflects a function
 */
Mirror.prototype.isFunction = function() {
  return this instanceof FunctionMirror;
319
};
320 321 322 323 324 325 326 327


/**
 * Check whether the mirror reflects an unresolved function.
 * @returns {boolean} True if the mirror reflects an unresolved function
 */
Mirror.prototype.isUnresolvedFunction = function() {
  return this instanceof UnresolvedFunctionMirror;
328
};
329 330 331 332 333 334 335 336


/**
 * Check whether the mirror reflects an array.
 * @returns {boolean} True if the mirror reflects an array
 */
Mirror.prototype.isArray = function() {
  return this instanceof ArrayMirror;
337
};
338 339 340 341 342 343 344 345


/**
 * Check whether the mirror reflects a date.
 * @returns {boolean} True if the mirror reflects a date
 */
Mirror.prototype.isDate = function() {
  return this instanceof DateMirror;
346
};
347 348 349 350 351 352 353 354


/**
 * Check whether the mirror reflects a regular expression.
 * @returns {boolean} True if the mirror reflects a regular expression
 */
Mirror.prototype.isRegExp = function() {
  return this instanceof RegExpMirror;
355
};
356 357 358 359 360 361 362 363


/**
 * Check whether the mirror reflects an error.
 * @returns {boolean} True if the mirror reflects an error
 */
Mirror.prototype.isError = function() {
  return this instanceof ErrorMirror;
364
};
365 366


367 368 369 370 371 372 373 374 375
/**
 * Check whether the mirror reflects a promise.
 * @returns {boolean} True if the mirror reflects a promise
 */
Mirror.prototype.isPromise = function() {
  return this instanceof PromiseMirror;
};


376 377 378 379 380 381 382 383 384
/**
 * Check whether the mirror reflects a generator object.
 * @returns {boolean} True if the mirror reflects a generator object
 */
Mirror.prototype.isGenerator = function() {
  return this instanceof GeneratorMirror;
};


385 386 387 388 389 390
/**
 * Check whether the mirror reflects a property.
 * @returns {boolean} True if the mirror reflects a property
 */
Mirror.prototype.isProperty = function() {
  return this instanceof PropertyMirror;
391
};
392 393


394 395 396 397 398 399 400 401 402
/**
 * Check whether the mirror reflects an internal property.
 * @returns {boolean} True if the mirror reflects an internal property
 */
Mirror.prototype.isInternalProperty = function() {
  return this instanceof InternalPropertyMirror;
};


403 404 405 406 407 408
/**
 * Check whether the mirror reflects a stack frame.
 * @returns {boolean} True if the mirror reflects a stack frame
 */
Mirror.prototype.isFrame = function() {
  return this instanceof FrameMirror;
409
};
410 411


412 413 414 415 416 417
/**
 * Check whether the mirror reflects a script.
 * @returns {boolean} True if the mirror reflects a script
 */
Mirror.prototype.isScript = function() {
  return this instanceof ScriptMirror;
418
};
419 420


421 422 423 424 425 426
/**
 * Check whether the mirror reflects a context.
 * @returns {boolean} True if the mirror reflects a context
 */
Mirror.prototype.isContext = function() {
  return this instanceof ContextMirror;
427
};
428 429


430 431 432 433 434 435
/**
 * Check whether the mirror reflects a scope.
 * @returns {boolean} True if the mirror reflects a scope
 */
Mirror.prototype.isScope = function() {
  return this instanceof ScopeMirror;
436
};
437 438


439 440 441 442 443 444 445 446 447
/**
 * Check whether the mirror reflects a map.
 * @returns {boolean} True if the mirror reflects a map
 */
Mirror.prototype.isMap = function() {
  return this instanceof MapMirror;
};


448 449 450 451 452 453 454 455 456
/**
 * Check whether the mirror reflects a set.
 * @returns {boolean} True if the mirror reflects a set
 */
Mirror.prototype.isSet = function() {
  return this instanceof SetMirror;
};


457 458 459 460 461 462 463 464 465
/**
 * Check whether the mirror reflects an iterator.
 * @returns {boolean} True if the mirror reflects an iterator
 */
Mirror.prototype.isIterator = function() {
  return this instanceof IteratorMirror;
};


466 467
Mirror.prototype.toText = function() {
  // Simpel to text which is used when on specialization in subclass.
468
  return "#<" + this.constructor.name + ">";
469
};
470 471 472 473 474 475 476 477 478


/**
 * Base class for all value mirror objects.
 * @param {string} type The type of the mirror
 * @param {value} value The value reflected by this mirror
 * @constructor
 * @extends Mirror
 */
479
function ValueMirror(type, value) {
480
  %_Call(Mirror, this, type);
481
  this.value_ = value;
482
}
483 484 485 486 487 488 489 490 491 492 493 494 495
inherits(ValueMirror, Mirror);


/**
 * Check whether this is a primitive value.
 * @return {boolean} True if the mirror reflects a primitive value
 */
ValueMirror.prototype.isPrimitive = function() {
  var type = this.type();
  return type === 'undefined' ||
         type === 'null' ||
         type === 'boolean' ||
         type === 'number' ||
496 497
         type === 'string' ||
         type === 'symbol';
498 499 500
};


501
/**
502 503 504 505 506 507 508 509 510 511 512 513 514 515
 * Get the actual value reflected by this mirror.
 * @return {value} The value reflected by this mirror
 */
ValueMirror.prototype.value = function() {
  return this.value_;
};


/**
 * Mirror object for Undefined.
 * @constructor
 * @extends ValueMirror
 */
function UndefinedMirror() {
516
  %_Call(ValueMirror, this, MirrorType.UNDEFINED_TYPE, UNDEFINED);
517
}
518 519 520 521 522
inherits(UndefinedMirror, ValueMirror);


UndefinedMirror.prototype.toText = function() {
  return 'undefined';
523
};
524 525 526 527 528 529 530 531


/**
 * Mirror object for null.
 * @constructor
 * @extends ValueMirror
 */
function NullMirror() {
532
  %_Call(ValueMirror, this, MirrorType.NULL_TYPE, null);
533
}
534 535 536 537 538
inherits(NullMirror, ValueMirror);


NullMirror.prototype.toText = function() {
  return 'null';
539
};
540 541 542 543 544 545 546 547 548


/**
 * Mirror object for boolean values.
 * @param {boolean} value The boolean value reflected by this mirror
 * @constructor
 * @extends ValueMirror
 */
function BooleanMirror(value) {
549
  %_Call(ValueMirror, this, MirrorType.BOOLEAN_TYPE, value);
550
}
551 552 553 554 555
inherits(BooleanMirror, ValueMirror);


BooleanMirror.prototype.toText = function() {
  return this.value_ ? 'true' : 'false';
556
};
557 558 559 560 561 562 563 564 565


/**
 * Mirror object for number values.
 * @param {number} value The number value reflected by this mirror
 * @constructor
 * @extends ValueMirror
 */
function NumberMirror(value) {
566
  %_Call(ValueMirror, this, MirrorType.NUMBER_TYPE, value);
567
}
568 569 570 571
inherits(NumberMirror, ValueMirror);


NumberMirror.prototype.toText = function() {
572
  return %NumberToString(this.value_);
573
};
574 575 576 577 578 579 580 581 582


/**
 * Mirror object for string values.
 * @param {string} value The string value reflected by this mirror
 * @constructor
 * @extends ValueMirror
 */
function StringMirror(value) {
583
  %_Call(ValueMirror, this, MirrorType.STRING_TYPE, value);
584
}
585 586 587 588 589 590 591
inherits(StringMirror, ValueMirror);


StringMirror.prototype.length = function() {
  return this.value_.length;
};

592 593 594
StringMirror.prototype.getTruncatedValue = function(maxLength) {
  if (maxLength != -1 && this.length() > maxLength) {
    return this.value_.substring(0, maxLength) +
595 596
           '... (length: ' + this.length() + ')';
  }
597
  return this.value_;
598
};
599 600 601

StringMirror.prototype.toText = function() {
  return this.getTruncatedValue(kMaxProtocolStringLength);
602
};
603 604


605 606 607 608 609 610 611
/**
 * Mirror object for a Symbol
 * @param {Object} value The Symbol
 * @constructor
 * @extends Mirror
 */
function SymbolMirror(value) {
612
  %_Call(ValueMirror, this, MirrorType.SYMBOL_TYPE, value);
613 614 615 616 617
}
inherits(SymbolMirror, ValueMirror);


SymbolMirror.prototype.description = function() {
618
  return %SymbolDescription(%ValueOf(this.value_));
619 620 621 622
}


SymbolMirror.prototype.toText = function() {
623
  return %SymbolDescriptiveString(%ValueOf(this.value_));
624 625 626
}


627 628 629 630 631 632
/**
 * Mirror object for objects.
 * @param {object} value The object reflected by this mirror
 * @constructor
 * @extends ValueMirror
 */
633
function ObjectMirror(value, type) {
634
  type = type || MirrorType.OBJECT_TYPE;
635
  %_Call(ValueMirror, this, type, value);
636
}
637 638 639 640
inherits(ObjectMirror, ValueMirror);


ObjectMirror.prototype.className = function() {
641
  return %_ClassOf(this.value_);
642 643 644 645 646 647 648 649 650 651 652 653 654 655
};


ObjectMirror.prototype.constructorFunction = function() {
  return MakeMirror(%DebugGetProperty(this.value_, 'constructor'));
};


ObjectMirror.prototype.prototypeObject = function() {
  return MakeMirror(%DebugGetProperty(this.value_, 'prototype'));
};


ObjectMirror.prototype.protoObject = function() {
656
  return MakeMirror(%DebugGetPrototype(this.value_));
657 658 659 660 661
};


ObjectMirror.prototype.hasNamedInterceptor = function() {
  // Get information on interceptors for this object.
662
  var x = %GetInterceptorInfo(this.value_);
663 664 665 666 667 668
  return (x & 2) != 0;
};


ObjectMirror.prototype.hasIndexedInterceptor = function() {
  // Get information on interceptors for this object.
669
  var x = %GetInterceptorInfo(this.value_);
670 671 672 673 674 675 676 677 678 679 680 681
  return (x & 1) != 0;
};


/**
 * Return the property names for this object.
 * @param {number} kind Indicate whether named, indexed or both kinds of
 *     properties are requested
 * @param {number} limit Limit the number of names returend to the specified
       value
 * @return {Array} Property names for this object
 */
682 683
ObjectMirror.prototype.propertyNames = function() {
  return %GetOwnPropertyKeys(this.value_, PROPERTY_FILTER_NONE);
684 685 686 687 688 689 690
};


/**
 * Return the properties for this object as an array of PropertyMirror objects.
 * @param {number} kind Indicate whether named, indexed or both kinds of
 *     properties are requested
691
 * @param {number} limit Limit the number of properties returned to the
692 693 694
       specified value
 * @return {Array} Property mirrors for this object
 */
695 696
ObjectMirror.prototype.properties = function() {
  var names = this.propertyNames();
697
  var properties = new GlobalArray(names.length);
698 699 700 701 702 703 704 705
  for (var i = 0; i < names.length; i++) {
    properties[i] = this.property(names[i]);
  }

  return properties;
};


706 707 708 709 710 711 712 713 714 715
/**
 * Return the internal properties for this object as an array of
 * InternalPropertyMirror objects.
 * @return {Array} Property mirrors for this object
 */
ObjectMirror.prototype.internalProperties = function() {
  return ObjectMirror.GetInternalProperties(this.value_);
}


716
ObjectMirror.prototype.property = function(name) {
717
  var details = %DebugGetPropertyDetails(this.value_, name);
718
  if (details) {
719
    return new PropertyMirror(this, name, details);
720 721 722
  }

  // Nothing found.
723
  return GetUndefinedMirror();
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
};



/**
 * Try to find a property from its value.
 * @param {Mirror} value The property value to look for
 * @return {PropertyMirror} The property with the specified value. If no
 *     property was found with the specified value UndefinedMirror is returned
 */
ObjectMirror.prototype.lookupProperty = function(value) {
  var properties = this.properties();

  // Look for property value in properties.
  for (var i = 0; i < properties.length; i++) {

740
    // Skip properties which are defined through accessors.
741
    var property = properties[i];
742
    if (property.propertyType() == PropertyType.Data) {
743
      if (property.value_ === value.value_) {
744 745 746 747 748 749
        return property;
      }
    }
  }

  // Nothing found.
750
  return GetUndefinedMirror();
751 752 753 754 755
};


/**
 * Returns objects which has direct references to this object
756 757
 * @param {number} opt_max_objects Optional parameter specifying the maximum
 *     number of referencing objects to return.
758 759
 * @return {Array} The objects which has direct references to this object.
 */
760 761 762 763
ObjectMirror.prototype.referencedBy = function(opt_max_objects) {
  // Find all objects with direct references to this object.
  var result = %DebugReferencedBy(this.value_,
                                  Mirror.prototype, opt_max_objects || 0);
764

765
  // Make mirrors for all the references found.
766 767 768
  for (var i = 0; i < result.length; i++) {
    result[i] = MakeMirror(result[i]);
  }
769

770 771 772 773 774 775 776
  return result;
};


ObjectMirror.prototype.toText = function() {
  var name;
  var ctor = this.constructorFunction();
777
  if (!ctor.isFunction()) {
778 779 780 781 782 783 784
    name = this.className();
  } else {
    name = ctor.name();
    if (!name) {
      name = this.className();
    }
  }
785
  return '#<' + name + '>';
786 787 788
};


789 790
/**
 * Return the internal properties of the value, such as [[PrimitiveValue]] of
791 792
 * scalar wrapper objects, properties of the bound function and properties of
 * the promise.
793 794 795 796 797
 * This method is done static to be accessible from Debug API with the bare
 * values without mirrors.
 * @return {Array} array (possibly empty) of InternalProperty instances
 */
ObjectMirror.GetInternalProperties = function(value) {
798 799 800 801
  var properties = %DebugGetInternalProperties(value);
  var result = [];
  for (var i = 0; i < properties.length; i += 2) {
    result.push(new InternalPropertyMirror(properties[i], properties[i + 1]));
802
  }
803
  return result;
804 805 806
}


807 808 809 810 811 812 813
/**
 * Mirror object for functions.
 * @param {function} value The function object reflected by this mirror.
 * @constructor
 * @extends ObjectMirror
 */
function FunctionMirror(value) {
814
  %_Call(ObjectMirror, this, value, MirrorType.FUNCTION_TYPE);
815
  this.resolved_ = true;
816
}
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
inherits(FunctionMirror, ObjectMirror);


/**
 * Returns whether the function is resolved.
 * @return {boolean} True if the function is resolved. Unresolved functions can
 *     only originate as functions from stack frames
 */
FunctionMirror.prototype.resolved = function() {
  return this.resolved_;
};


/**
 * Returns the name of the function.
 * @return {string} Name of the function
 */
FunctionMirror.prototype.name = function() {
  return %FunctionGetName(this.value_);
};


839 840 841 842 843 844 845 846 847 848
/**
 * Returns the displayName if it is set, otherwise name, otherwise inferred
 * name.
 * @return {string} Name of the function
 */
FunctionMirror.prototype.debugName = function() {
  return %FunctionGetDebugName(this.value_);
}


849 850 851 852 853 854 855 856 857
/**
 * Returns the inferred name of the function.
 * @return {string} Name of the function
 */
FunctionMirror.prototype.inferredName = function() {
  return %FunctionGetInferredName(this.value_);
};


858 859 860 861 862 863 864 865 866
/**
 * Returns the source code for the function.
 * @return {string or undefined} The source code for the function. If the
 *     function is not resolved undefined will be returned.
 */
FunctionMirror.prototype.source = function() {
  // Return source if function is resolved. Otherwise just fall through to
  // return undefined.
  if (this.resolved()) {
867
    return %FunctionToString(this.value_);
868 869 870 871 872 873 874 875 876 877 878 879 880
  }
};


/**
 * Returns the script object for the function.
 * @return {ScriptMirror or undefined} Script object for the function or
 *     undefined if the function has no script
 */
FunctionMirror.prototype.script = function() {
  // Return script if function is resolved. Otherwise just fall through
  // to return undefined.
  if (this.resolved()) {
881 882 883
    if (this.script_) {
      return this.script_;
    }
884 885
    var script = %FunctionGetScript(this.value_);
    if (script) {
886
      return this.script_ = MakeMirror(script);
887 888 889 890 891
    }
  }
};


892 893 894 895 896 897
/**
 * Returns the script source position for the function. Only makes sense
 * for functions which has a script defined.
 * @return {Number or undefined} in-script position for the function
 */
FunctionMirror.prototype.sourcePosition_ = function() {
898 899
  // Return position if function is resolved. Otherwise just fall
  // through to return undefined.
900 901 902 903 904 905 906 907 908 909 910 911
  if (this.resolved()) {
    return %FunctionGetScriptSourcePosition(this.value_);
  }
};


/**
 * Returns the script source location object for the function. Only makes sense
 * for functions which has a script defined.
 * @return {Location or undefined} in-script location for the function begin
 */
FunctionMirror.prototype.sourceLocation = function() {
912 913 914 915 916
  if (this.resolved()) {
    var script = this.script();
    if (script) {
      return script.locationFromPosition(this.sourcePosition_(), true);
    }
917 918 919 920
  }
};


921 922 923 924 925 926 927 928 929 930
/**
 * Returns objects constructed by this function.
 * @param {number} opt_max_instances Optional parameter specifying the maximum
 *     number of instances to return.
 * @return {Array or undefined} The objects constructed by this function.
 */
FunctionMirror.prototype.constructedBy = function(opt_max_instances) {
  if (this.resolved()) {
    // Find all objects constructed from this function.
    var result = %DebugConstructedBy(this.value_, opt_max_instances || 0);
931

932 933 934 935
    // Make mirrors for all the instances found.
    for (var i = 0; i < result.length; i++) {
      result[i] = MakeMirror(result[i]);
    }
936

937 938 939 940 941 942 943
    return result;
  } else {
    return [];
  }
};


944 945
FunctionMirror.prototype.scopeCount = function() {
  if (this.resolved()) {
946 947 948 949
    if (IS_UNDEFINED(this.scopeCount_)) {
      this.scopeCount_ = %GetFunctionScopeCount(this.value());
    }
    return this.scopeCount_;
950 951 952 953 954 955 956 957
  } else {
    return 0;
  }
};


FunctionMirror.prototype.scope = function(index) {
  if (this.resolved()) {
958
    return new ScopeMirror(UNDEFINED, this, UNDEFINED, index);
959 960 961 962
  }
};


963 964
FunctionMirror.prototype.toText = function() {
  return this.source();
965
};
966 967


968 969 970 971 972 973 974 975 976
FunctionMirror.prototype.context = function() {
  if (this.resolved()) {
    if (!this._context)
      this._context = new ContextMirror(%FunctionGetContextData(this.value_));
    return this._context;
  }
};


977 978 979 980 981 982 983 984 985 986
/**
 * Mirror object for unresolved functions.
 * @param {string} value The name for the unresolved function reflected by this
 *     mirror.
 * @constructor
 * @extends ObjectMirror
 */
function UnresolvedFunctionMirror(value) {
  // Construct this using the ValueMirror as an unresolved function is not a
  // real object but just a string.
987
  %_Call(ValueMirror, this, MirrorType.FUNCTION_TYPE, value);
988 989 990
  this.propertyCount_ = 0;
  this.elementCount_ = 0;
  this.resolved_ = false;
991
}
992 993 994 995 996 997 998 999 1000
inherits(UnresolvedFunctionMirror, FunctionMirror);


UnresolvedFunctionMirror.prototype.className = function() {
  return 'Function';
};


UnresolvedFunctionMirror.prototype.constructorFunction = function() {
1001
  return GetUndefinedMirror();
1002 1003 1004 1005
};


UnresolvedFunctionMirror.prototype.prototypeObject = function() {
1006
  return GetUndefinedMirror();
1007 1008 1009 1010
};


UnresolvedFunctionMirror.prototype.protoObject = function() {
1011
  return GetUndefinedMirror();
1012 1013 1014 1015 1016 1017 1018 1019
};


UnresolvedFunctionMirror.prototype.name = function() {
  return this.value_;
};


1020 1021 1022 1023 1024
UnresolvedFunctionMirror.prototype.debugName = function() {
  return this.value_;
};


1025
UnresolvedFunctionMirror.prototype.inferredName = function() {
1026
  return UNDEFINED;
1027 1028 1029
};


1030 1031
UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) {
  return [];
1032
};
1033 1034 1035 1036 1037 1038 1039 1040 1041


/**
 * Mirror object for arrays.
 * @param {Array} value The Array object reflected by this mirror
 * @constructor
 * @extends ObjectMirror
 */
function ArrayMirror(value) {
1042
  %_Call(ObjectMirror, this, value);
1043
}
1044 1045 1046 1047 1048 1049 1050 1051
inherits(ArrayMirror, ObjectMirror);


ArrayMirror.prototype.length = function() {
  return this.value_.length;
};


1052 1053
ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index,
                                                            opt_to_index) {
1054 1055
  var from_index = opt_from_index || 0;
  var to_index = opt_to_index || this.length() - 1;
1056 1057
  if (from_index > to_index) return new GlobalArray();
  var values = new GlobalArray(to_index - from_index + 1);
1058
  for (var i = from_index; i <= to_index; i++) {
1059
    var details = %DebugGetPropertyDetails(this.value_, TO_STRING(i));
1060 1061
    var value;
    if (details) {
1062
      value = new PropertyMirror(this, i, details);
1063
    } else {
1064
      value = GetUndefinedMirror();
1065 1066 1067 1068
    }
    values[i - from_index] = value;
  }
  return values;
1069
};
1070 1071 1072 1073 1074 1075 1076 1077 1078


/**
 * Mirror object for dates.
 * @param {Date} value The Date object reflected by this mirror
 * @constructor
 * @extends ObjectMirror
 */
function DateMirror(value) {
1079
  %_Call(ObjectMirror, this, value);
1080
}
1081 1082 1083 1084
inherits(DateMirror, ObjectMirror);


DateMirror.prototype.toText = function() {
1085
  var s = JSONStringify(this.value_);
1086
  return s.substring(1, s.length - 1);  // cut quotes
1087
};
1088 1089 1090 1091 1092 1093 1094 1095 1096


/**
 * Mirror object for regular expressions.
 * @param {RegExp} value The RegExp object reflected by this mirror
 * @constructor
 * @extends ObjectMirror
 */
function RegExpMirror(value) {
1097
  %_Call(ObjectMirror, this, value, MirrorType.REGEXP_TYPE);
1098
}
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
inherits(RegExpMirror, ObjectMirror);


/**
 * Returns the source to the regular expression.
 * @return {string or undefined} The source to the regular expression
 */
RegExpMirror.prototype.source = function() {
  return this.value_.source;
};


/**
 * Returns whether this regular expression has the global (g) flag set.
 * @return {boolean} Value of the global flag
 */
RegExpMirror.prototype.global = function() {
  return this.value_.global;
};


/**
 * Returns whether this regular expression has the ignore case (i) flag set.
 * @return {boolean} Value of the ignore case flag
 */
RegExpMirror.prototype.ignoreCase = function() {
  return this.value_.ignoreCase;
};


/**
 * Returns whether this regular expression has the multiline (m) flag set.
 * @return {boolean} Value of the multiline flag
 */
RegExpMirror.prototype.multiline = function() {
  return this.value_.multiline;
};


1138 1139 1140 1141 1142 1143 1144 1145 1146
/**
 * Returns whether this regular expression has the sticky (y) flag set.
 * @return {boolean} Value of the sticky flag
 */
RegExpMirror.prototype.sticky = function() {
  return this.value_.sticky;
};


1147 1148 1149 1150 1151 1152 1153 1154 1155
/**
 * Returns whether this regular expression has the unicode (u) flag set.
 * @return {boolean} Value of the unicode flag
 */
RegExpMirror.prototype.unicode = function() {
  return this.value_.unicode;
};


1156 1157 1158
RegExpMirror.prototype.toText = function() {
  // Simpel to text which is used when on specialization in subclass.
  return "/" + this.source() + "/";
1159
};
1160 1161 1162 1163 1164 1165 1166 1167 1168


/**
 * Mirror object for error objects.
 * @param {Error} value The error object reflected by this mirror
 * @constructor
 * @extends ObjectMirror
 */
function ErrorMirror(value) {
1169
  %_Call(ObjectMirror, this, value, MirrorType.ERROR_TYPE);
1170
}
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
inherits(ErrorMirror, ObjectMirror);


/**
 * Returns the message for this eror object.
 * @return {string or undefined} The message for this eror object
 */
ErrorMirror.prototype.message = function() {
  return this.value_.message;
};


ErrorMirror.prototype.toText = function() {
  // Use the same text representation as in messages.js.
  var text;
  try {
1187
    text = %ErrorToString(this.value_);
1188
  } catch (e) {
1189
    text = '#<Error>';
1190
  }
1191
  return text;
1192
};
1193 1194


1195 1196
/**
 * Mirror object for a Promise object.
1197
 * @param {Object} value The Promise object
1198
 * @constructor
1199
 * @extends ObjectMirror
1200 1201
 */
function PromiseMirror(value) {
1202
  %_Call(ObjectMirror, this, value, MirrorType.PROMISE_TYPE);
1203 1204 1205 1206
}
inherits(PromiseMirror, ObjectMirror);


1207
function PromiseGetStatus_(value) {
1208
  var status = %PromiseStatus(value);
1209 1210 1211
  if (status == 0) return "pending";
  if (status == 1) return "resolved";
  return "rejected";
1212 1213 1214 1215
}


function PromiseGetValue_(value) {
1216
  return %PromiseResult(value);
1217 1218 1219 1220 1221
}


PromiseMirror.prototype.status = function() {
  return PromiseGetStatus_(this.value_);
1222 1223 1224
};


1225
PromiseMirror.prototype.promiseValue = function() {
1226
  return MakeMirror(PromiseGetValue_(this.value_));
1227 1228 1229
};


1230
function MapMirror(value) {
1231
  %_Call(ObjectMirror, this, value, MirrorType.MAP_TYPE);
1232 1233 1234 1235 1236 1237 1238 1239
}
inherits(MapMirror, ObjectMirror);


/**
 * Returns an array of key/value pairs of a map.
 * This will keep keys alive for WeakMaps.
 *
1240
 * @param {number=} opt_limit Max elements to return.
1241 1242
 * @returns {Array.<Object>} Array of key/value pairs of a map.
 */
1243
MapMirror.prototype.entries = function(opt_limit) {
1244 1245 1246
  var result = [];

  if (IS_WEAKMAP(this.value_)) {
1247
    var entries = %GetWeakMapEntries(this.value_, opt_limit || 0);
1248 1249 1250 1251 1252 1253 1254 1255 1256
    for (var i = 0; i < entries.length; i += 2) {
      result.push({
        key: entries[i],
        value: entries[i + 1]
      });
    }
    return result;
  }

1257
  var iter = %_Call(MapEntries, this.value_);
1258
  var next;
1259 1260
  while ((!opt_limit || result.length < opt_limit) &&
         !(next = iter.next()).done) {
1261 1262 1263 1264 1265 1266 1267 1268 1269
    result.push({
      key: next.value[0],
      value: next.value[1]
    });
  }
  return result;
};


1270
function SetMirror(value) {
1271
  %_Call(ObjectMirror, this, value, MirrorType.SET_TYPE);
1272 1273 1274 1275
}
inherits(SetMirror, ObjectMirror);


1276
function IteratorGetValues_(iter, next_function, opt_limit) {
1277 1278
  var result = [];
  var next;
1279
  while ((!opt_limit || result.length < opt_limit) &&
1280
         !(next = %_Call(next_function, iter)).done) {
1281 1282 1283 1284 1285 1286
    result.push(next.value);
  }
  return result;
}


1287 1288 1289 1290
/**
 * Returns an array of elements of a set.
 * This will keep elements alive for WeakSets.
 *
1291
 * @param {number=} opt_limit Max elements to return.
1292 1293
 * @returns {Array.<Object>} Array of elements of a set.
 */
1294
SetMirror.prototype.values = function(opt_limit) {
1295
  if (IS_WEAKSET(this.value_)) {
1296
    return %GetWeakSetValues(this.value_, opt_limit || 0);
1297 1298
  }

1299
  var iter = %_Call(SetValues, this.value_);
1300
  return IteratorGetValues_(iter, SetIteratorNext, opt_limit);
1301 1302 1303 1304
};


function IteratorMirror(value) {
1305
  %_Call(ObjectMirror, this, value, MirrorType.ITERATOR_TYPE);
1306 1307 1308 1309 1310 1311 1312 1313
}
inherits(IteratorMirror, ObjectMirror);


/**
 * Returns a preview of elements of an iterator.
 * Does not change the backing iterator state.
 *
1314
 * @param {number=} opt_limit Max elements to return.
1315 1316
 * @returns {Array.<Object>} Array of elements of an iterator.
 */
1317
IteratorMirror.prototype.preview = function(opt_limit) {
1318 1319
  if (IS_MAP_ITERATOR(this.value_)) {
    return IteratorGetValues_(%MapIteratorClone(this.value_),
1320
                              MapIteratorNext,
1321
                              opt_limit);
1322 1323
  } else if (IS_SET_ITERATOR(this.value_)) {
    return IteratorGetValues_(%SetIteratorClone(this.value_),
1324
                              SetIteratorNext,
1325
                              opt_limit);
1326 1327 1328 1329
  }
};


1330 1331 1332 1333 1334 1335 1336
/**
 * Mirror object for a Generator object.
 * @param {Object} data The Generator object
 * @constructor
 * @extends Mirror
 */
function GeneratorMirror(value) {
1337
  %_Call(ObjectMirror, this, value, MirrorType.GENERATOR_TYPE);
1338 1339 1340 1341
}
inherits(GeneratorMirror, ObjectMirror);


1342 1343
function GeneratorGetStatus_(value) {
  var continuation = %GeneratorGetContinuation(value);
1344 1345
  if (continuation < -1) return "running";
  if (continuation == -1) return "closed";
1346
  return "suspended";
1347 1348 1349 1350 1351
}


GeneratorMirror.prototype.status = function() {
  return GeneratorGetStatus_(this.value_);
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
};


GeneratorMirror.prototype.sourcePosition_ = function() {
  return %GeneratorGetSourcePosition(this.value_);
};


GeneratorMirror.prototype.sourceLocation = function() {
  var pos = this.sourcePosition_();
  if (!IS_UNDEFINED(pos)) {
    var script = this.func().script();
    if (script) {
      return script.locationFromPosition(pos, true);
    }
  }
};


GeneratorMirror.prototype.func = function() {
  if (!this.func_) {
    this.func_ = MakeMirror(%GeneratorGetFunction(this.value_));
  }
  return this.func_;
};


GeneratorMirror.prototype.receiver = function() {
  if (!this.receiver_) {
    this.receiver_ = MakeMirror(%GeneratorGetReceiver(this.value_));
  }
  return this.receiver_;
};


1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
GeneratorMirror.prototype.scopeCount = function() {
  // This value can change over time as the underlying generator is suspended
  // at different locations.
  return %GetGeneratorScopeCount(this.value());
};


GeneratorMirror.prototype.scope = function(index) {
  return new ScopeMirror(UNDEFINED, UNDEFINED, this, index);
};


GeneratorMirror.prototype.allScopes = function() {
  var scopes = [];
  for (let i = 0; i < this.scopeCount(); i++) {
    scopes.push(this.scope(i));
  }
  return scopes;
};


1408 1409 1410 1411
/**
 * Base mirror object for properties.
 * @param {ObjectMirror} mirror The mirror object having this property
 * @param {string} name The name of the property
1412
 * @param {Array} details Details about the property
1413 1414 1415
 * @constructor
 * @extends Mirror
 */
1416
function PropertyMirror(mirror, name, details) {
1417
  %_Call(Mirror, this, MirrorType.PROPERTY_TYPE);
1418 1419
  this.mirror_ = mirror;
  this.name_ = name;
1420 1421
  this.value_ = details[0];
  this.details_ = details[1];
1422 1423 1424 1425 1426
  this.is_interceptor_ = details[2];
  if (details.length > 3) {
    this.exception_ = details[3];
    this.getter_ = details[4];
    this.setter_ = details[5];
1427
  }
1428
}
1429 1430 1431 1432 1433
inherits(PropertyMirror, Mirror);


PropertyMirror.prototype.isReadOnly = function() {
  return (this.attributes() & PropertyAttribute.ReadOnly) != 0;
1434
};
1435 1436 1437 1438


PropertyMirror.prototype.isEnum = function() {
  return (this.attributes() & PropertyAttribute.DontEnum) == 0;
1439
};
1440 1441 1442 1443


PropertyMirror.prototype.canDelete = function() {
  return (this.attributes() & PropertyAttribute.DontDelete) == 0;
1444
};
1445 1446 1447 1448


PropertyMirror.prototype.name = function() {
  return this.name_;
1449
};
1450 1451


1452 1453 1454 1455 1456 1457
PropertyMirror.prototype.toText = function() {
  if (IS_SYMBOL(this.name_)) return %SymbolDescriptiveString(this.name_);
  return this.name_;
};


1458 1459 1460 1461 1462 1463 1464
PropertyMirror.prototype.isIndexed = function() {
  for (var i = 0; i < this.name_.length; i++) {
    if (this.name_[i] < '0' || '9' < this.name_[i]) {
      return false;
    }
  }
  return true;
1465
};
1466 1467 1468


PropertyMirror.prototype.value = function() {
1469
  return MakeMirror(this.value_, false);
1470
};
1471 1472 1473 1474


/**
 * Returns whether this property value is an exception.
1475
 * @return {boolean} True if this property value is an exception
1476 1477 1478
 */
PropertyMirror.prototype.isException = function() {
  return this.exception_ ? true : false;
1479
};
1480 1481 1482 1483


PropertyMirror.prototype.attributes = function() {
  return %DebugPropertyAttributesFromDetails(this.details_);
1484
};
1485 1486 1487


PropertyMirror.prototype.propertyType = function() {
1488
  return %DebugPropertyKindFromDetails(this.details_);
1489
};
1490 1491 1492


/**
1493
 * Returns whether this property has a getter defined through __defineGetter__.
1494
 * @return {boolean} True if this property has a getter
1495
 */
1496 1497
PropertyMirror.prototype.hasGetter = function() {
  return this.getter_ ? true : false;
1498
};
1499 1500 1501


/**
1502
 * Returns whether this property has a setter defined through __defineSetter__.
1503
 * @return {boolean} True if this property has a setter
1504
 */
1505 1506
PropertyMirror.prototype.hasSetter = function() {
  return this.setter_ ? true : false;
1507
};
1508 1509 1510


/**
1511 1512 1513
 * Returns the getter for this property defined through __defineGetter__.
 * @return {Mirror} FunctionMirror reflecting the getter function or
 *     UndefinedMirror if there is no getter for this property
1514
 */
1515 1516 1517 1518
PropertyMirror.prototype.getter = function() {
  if (this.hasGetter()) {
    return MakeMirror(this.getter_);
  } else {
1519
    return GetUndefinedMirror();
1520
  }
1521
};
1522 1523 1524


/**
1525 1526 1527
 * Returns the setter for this property defined through __defineSetter__.
 * @return {Mirror} FunctionMirror reflecting the setter function or
 *     UndefinedMirror if there is no setter for this property
1528
 */
1529 1530 1531 1532
PropertyMirror.prototype.setter = function() {
  if (this.hasSetter()) {
    return MakeMirror(this.setter_);
  } else {
1533
    return GetUndefinedMirror();
1534
  }
1535
};
1536 1537 1538


/**
1539 1540
 * Returns whether this property is natively implemented by the host or a set
 * through JavaScript code.
1541
 * @return {boolean} True if the property is
1542
 *     UndefinedMirror if there is no setter for this property
1543
 */
1544
PropertyMirror.prototype.isNative = function() {
1545
  return this.is_interceptor_ ||
1546
         ((this.propertyType() == PropertyType.Accessor) &&
1547
          !this.hasGetter() && !this.hasSetter());
1548
};
1549 1550


1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
/**
 * Mirror object for internal properties. Internal property reflects properties
 * not accessible from user code such as [[BoundThis]] in bound function.
 * Their names are merely symbolic.
 * @param {string} name The name of the property
 * @param {value} property value
 * @constructor
 * @extends Mirror
 */
function InternalPropertyMirror(name, value) {
1561
  %_Call(Mirror, this, MirrorType.INTERNAL_PROPERTY_TYPE);
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
  this.name_ = name;
  this.value_ = value;
}
inherits(InternalPropertyMirror, Mirror);


InternalPropertyMirror.prototype.name = function() {
  return this.name_;
};


InternalPropertyMirror.prototype.value = function() {
  return MakeMirror(this.value_, false);
};


1578 1579 1580
var kFrameDetailsFrameIdIndex = 0;
var kFrameDetailsReceiverIndex = 1;
var kFrameDetailsFunctionIndex = 2;
1581 1582 1583 1584 1585 1586 1587 1588
var kFrameDetailsScriptIndex = 3;
var kFrameDetailsArgumentCountIndex = 4;
var kFrameDetailsLocalCountIndex = 5;
var kFrameDetailsSourcePositionIndex = 6;
var kFrameDetailsConstructCallIndex = 7;
var kFrameDetailsAtReturnIndex = 8;
var kFrameDetailsFlagsIndex = 9;
var kFrameDetailsFirstDynamicIndex = 10;
1589

1590 1591 1592
var kFrameDetailsNameIndex = 0;
var kFrameDetailsValueIndex = 1;
var kFrameDetailsNameValueSize = 2;
1593

1594 1595 1596
var kFrameDetailsFlagDebuggerFrameMask = 1 << 0;
var kFrameDetailsFlagOptimizedFrameMask = 1 << 1;
var kFrameDetailsFlagInlinedFrameIndexMask = 7 << 2;
1597

1598 1599 1600 1601 1602 1603 1604
/**
 * Wrapper for the frame details information retreived from the VM. The frame
 * details from the VM is an array with the following content. See runtime.cc
 * Runtime_GetFrameDetails.
 *     0: Id
 *     1: Receiver
 *     2: Function
1605 1606 1607 1608 1609 1610 1611
 *     3: Script
 *     4: Argument count
 *     5: Local count
 *     6: Source position
 *     7: Construct call
 *     8: Is at return
 *     9: Flags (debugger frame, optimized frame, inlined frame index)
1612 1613
 *     Arguments name, value
 *     Locals name, value
1614
 *     Return value if any
1615 1616 1617 1618 1619 1620 1621
 * @param {number} break_id Current break id
 * @param {number} index Frame number
 * @constructor
 */
function FrameDetails(break_id, index) {
  this.break_id_ = break_id;
  this.details_ = %GetFrameDetails(break_id, index);
1622
}
1623 1624 1625 1626 1627


FrameDetails.prototype.frameId = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsFrameIdIndex];
1628
};
1629 1630 1631 1632 1633


FrameDetails.prototype.receiver = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsReceiverIndex];
1634
};
1635 1636 1637 1638 1639


FrameDetails.prototype.func = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsFunctionIndex];
1640
};
1641 1642


1643 1644 1645 1646 1647 1648
FrameDetails.prototype.script = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsScriptIndex];
};


1649 1650 1651
FrameDetails.prototype.isConstructCall = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsConstructCallIndex];
1652
};
1653 1654


1655 1656 1657
FrameDetails.prototype.isAtReturn = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsAtReturnIndex];
1658
};
1659 1660


1661 1662
FrameDetails.prototype.isDebuggerFrame = function() {
  %CheckExecutionState(this.break_id_);
1663
  var f = kFrameDetailsFlagDebuggerFrameMask;
1664
  return (this.details_[kFrameDetailsFlagsIndex] & f) == f;
1665
};
1666 1667 1668 1669


FrameDetails.prototype.isOptimizedFrame = function() {
  %CheckExecutionState(this.break_id_);
1670
  var f = kFrameDetailsFlagOptimizedFrameMask;
1671
  return (this.details_[kFrameDetailsFlagsIndex] & f) == f;
1672
};
1673 1674 1675


FrameDetails.prototype.isInlinedFrame = function() {
1676
  return this.inlinedFrameIndex() > 0;
1677
};
1678 1679 1680


FrameDetails.prototype.inlinedFrameIndex = function() {
1681
  %CheckExecutionState(this.break_id_);
1682
  var f = kFrameDetailsFlagInlinedFrameIndexMask;
1683 1684
  return (this.details_[kFrameDetailsFlagsIndex] & f) >> 2;
};
1685 1686 1687 1688 1689


FrameDetails.prototype.argumentCount = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsArgumentCountIndex];
1690
};
1691 1692 1693 1694 1695 1696 1697


FrameDetails.prototype.argumentName = function(index) {
  %CheckExecutionState(this.break_id_);
  if (index >= 0 && index < this.argumentCount()) {
    return this.details_[kFrameDetailsFirstDynamicIndex +
                         index * kFrameDetailsNameValueSize +
1698
                         kFrameDetailsNameIndex];
1699
  }
1700
};
1701 1702 1703 1704 1705 1706 1707


FrameDetails.prototype.argumentValue = function(index) {
  %CheckExecutionState(this.break_id_);
  if (index >= 0 && index < this.argumentCount()) {
    return this.details_[kFrameDetailsFirstDynamicIndex +
                         index * kFrameDetailsNameValueSize +
1708
                         kFrameDetailsValueIndex];
1709
  }
1710
};
1711 1712 1713 1714 1715


FrameDetails.prototype.localCount = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsLocalCountIndex];
1716
};
1717 1718 1719 1720 1721


FrameDetails.prototype.sourcePosition = function() {
  %CheckExecutionState(this.break_id_);
  return this.details_[kFrameDetailsSourcePositionIndex];
1722
};
1723 1724 1725 1726 1727


FrameDetails.prototype.localName = function(index) {
  %CheckExecutionState(this.break_id_);
  if (index >= 0 && index < this.localCount()) {
1728
    var locals_offset = kFrameDetailsFirstDynamicIndex +
1729
                        this.argumentCount() * kFrameDetailsNameValueSize;
1730 1731
    return this.details_[locals_offset +
                         index * kFrameDetailsNameValueSize +
1732
                         kFrameDetailsNameIndex];
1733
  }
1734
};
1735 1736 1737 1738 1739


FrameDetails.prototype.localValue = function(index) {
  %CheckExecutionState(this.break_id_);
  if (index >= 0 && index < this.localCount()) {
1740
    var locals_offset = kFrameDetailsFirstDynamicIndex +
1741
                        this.argumentCount() * kFrameDetailsNameValueSize;
1742 1743
    return this.details_[locals_offset +
                         index * kFrameDetailsNameValueSize +
1744
                         kFrameDetailsValueIndex];
1745
  }
1746
};
1747 1748


1749 1750 1751 1752 1753 1754 1755 1756
FrameDetails.prototype.returnValue = function() {
  %CheckExecutionState(this.break_id_);
  var return_value_offset =
      kFrameDetailsFirstDynamicIndex +
      (this.argumentCount() + this.localCount()) * kFrameDetailsNameValueSize;
  if (this.details_[kFrameDetailsAtReturnIndex]) {
    return this.details_[return_value_offset];
  }
1757
};
1758 1759


1760
FrameDetails.prototype.scopeCount = function() {
1761 1762 1763 1764
  if (IS_UNDEFINED(this.scopeCount_)) {
    this.scopeCount_ = %GetScopeCount(this.break_id_, this.frameId());
  }
  return this.scopeCount_;
1765
};
1766 1767


1768 1769 1770 1771 1772 1773 1774 1775 1776
/**
 * Mirror object for stack frames.
 * @param {number} break_id The break id in the VM for which this frame is
       valid
 * @param {number} index The frame index (top frame is index 0)
 * @constructor
 * @extends Mirror
 */
function FrameMirror(break_id, index) {
1777
  %_Call(Mirror, this, MirrorType.FRAME_TYPE);
1778 1779 1780
  this.break_id_ = break_id;
  this.index_ = index;
  this.details_ = new FrameDetails(break_id, index);
1781
}
1782 1783 1784
inherits(FrameMirror, Mirror);


1785 1786 1787 1788 1789
FrameMirror.prototype.details = function() {
  return this.details_;
};


1790 1791 1792 1793 1794 1795
FrameMirror.prototype.index = function() {
  return this.index_;
};


FrameMirror.prototype.func = function() {
1796 1797 1798 1799
  if (this.func_) {
    return this.func_;
  }

1800 1801
  // Get the function for this frame from the VM.
  var f = this.details_.func();
1802

1803 1804 1805 1806
  // Create a function mirror. NOTE: MakeMirror cannot be used here as the
  // value returned from the VM might be a string if the function for the
  // frame is unresolved.
  if (IS_FUNCTION(f)) {
1807
    return this.func_ = MakeMirror(f);
1808 1809 1810 1811 1812 1813
  } else {
    return new UnresolvedFunctionMirror(f);
  }
};


1814 1815 1816 1817 1818 1819 1820 1821 1822
FrameMirror.prototype.script = function() {
  if (!this.script_) {
    this.script_ = MakeMirror(this.details_.script());
  }

  return this.script_;
}


1823 1824 1825 1826 1827 1828 1829 1830 1831 1832
FrameMirror.prototype.receiver = function() {
  return MakeMirror(this.details_.receiver());
};


FrameMirror.prototype.isConstructCall = function() {
  return this.details_.isConstructCall();
};


1833 1834 1835 1836 1837
FrameMirror.prototype.isAtReturn = function() {
  return this.details_.isAtReturn();
};


1838 1839 1840 1841 1842
FrameMirror.prototype.isDebuggerFrame = function() {
  return this.details_.isDebuggerFrame();
};


1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
FrameMirror.prototype.isOptimizedFrame = function() {
  return this.details_.isOptimizedFrame();
};


FrameMirror.prototype.isInlinedFrame = function() {
  return this.details_.isInlinedFrame();
};


1853 1854 1855 1856 1857
FrameMirror.prototype.inlinedFrameIndex = function() {
  return this.details_.inlinedFrameIndex();
};


1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
FrameMirror.prototype.argumentCount = function() {
  return this.details_.argumentCount();
};


FrameMirror.prototype.argumentName = function(index) {
  return this.details_.argumentName(index);
};


FrameMirror.prototype.argumentValue = function(index) {
  return MakeMirror(this.details_.argumentValue(index));
};


FrameMirror.prototype.localCount = function() {
  return this.details_.localCount();
};


FrameMirror.prototype.localName = function(index) {
  return this.details_.localName(index);
};


FrameMirror.prototype.localValue = function(index) {
  return MakeMirror(this.details_.localValue(index));
};


1888 1889 1890 1891 1892
FrameMirror.prototype.returnValue = function() {
  return MakeMirror(this.details_.returnValue());
};


1893 1894 1895 1896 1897 1898
FrameMirror.prototype.sourcePosition = function() {
  return this.details_.sourcePosition();
};


FrameMirror.prototype.sourceLocation = function() {
1899 1900 1901
  var script = this.script();
  if (script) {
    return script.locationFromPosition(this.sourcePosition(), true);
1902 1903 1904 1905 1906
  }
};


FrameMirror.prototype.sourceLine = function() {
1907 1908 1909
  var location = this.sourceLocation();
  if (location) {
    return location.line;
1910 1911 1912 1913 1914
  }
};


FrameMirror.prototype.sourceColumn = function() {
1915 1916 1917
  var location = this.sourceLocation();
  if (location) {
    return location.column;
1918 1919 1920 1921 1922
  }
};


FrameMirror.prototype.sourceLineText = function() {
1923 1924
  var location = this.sourceLocation();
  if (location) {
1925
    return location.sourceText;
1926 1927 1928 1929
  }
};


1930 1931 1932 1933 1934 1935
FrameMirror.prototype.scopeCount = function() {
  return this.details_.scopeCount();
};


FrameMirror.prototype.scope = function(index) {
1936
  return new ScopeMirror(this, UNDEFINED, UNDEFINED, index);
1937 1938 1939
};


1940
FrameMirror.prototype.allScopes = function(opt_ignore_nested_scopes) {
1941 1942
  var scopeDetails = %GetAllScopesDetails(this.break_id_,
                                          this.details_.frameId(),
1943 1944
                                          this.details_.inlinedFrameIndex(),
                                          !!opt_ignore_nested_scopes);
1945 1946
  var result = [];
  for (var i = 0; i < scopeDetails.length; ++i) {
1947 1948
    result.push(new ScopeMirror(this, UNDEFINED, UNDEFINED, i,
                                scopeDetails[i]));
1949 1950 1951 1952 1953
  }
  return result;
};


1954
FrameMirror.prototype.evaluate = function(source, throw_on_side_effect = false) {
1955 1956 1957
  return MakeMirror(%DebugEvaluate(this.break_id_,
                                   this.details_.frameId(),
                                   this.details_.inlinedFrameIndex(),
1958 1959
                                   source,
                                   throw_on_side_effect));
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
};


FrameMirror.prototype.invocationText = function() {
  // Format frame invoaction (receiver, function and arguments).
  var result = '';
  var func = this.func();
  var receiver = this.receiver();
  if (this.isConstructCall()) {
    // For constructor frames display new followed by the function name.
    result += 'new ';
    result += func.name() ? func.name() : '[anonymous]';
1972
  } else if (this.isDebuggerFrame()) {
1973 1974 1975
    result += '[debugger]';
  } else {
    // If the receiver has a className which is 'global' don't display it.
1976 1977
    var display_receiver =
      !receiver.className || (receiver.className() != 'global');
1978 1979 1980 1981 1982
    if (display_receiver) {
      result += receiver.toText();
    }
    // Try to find the function as a property in the receiver. Include the
    // prototype chain in the lookup.
1983
    var property = GetUndefinedMirror();
1984 1985 1986 1987
    if (receiver.isObject()) {
      for (var r = receiver;
           !r.isNull() && property.isUndefined();
           r = r.protoObject()) {
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
        property = r.lookupProperty(func);
      }
    }
    if (!property.isUndefined()) {
      // The function invoked was found on the receiver. Use the property name
      // for the backtrace.
      if (!property.isIndexed()) {
        if (display_receiver) {
          result += '.';
        }
1998
        result += property.toText();
1999 2000
      } else {
        result += '[';
2001
        result += property.toText();
2002 2003 2004 2005 2006 2007
        result += ']';
      }
      // Also known as - if the name in the function doesn't match the name
      // under which it was looked up.
      if (func.name() && func.name() != property.name()) {
        result += '(aka ' + func.name() + ')';
2008
      }
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
    } else {
      // The function invoked was not found on the receiver. Use the function
      // name if available for the backtrace.
      if (display_receiver) {
        result += '.';
      }
      result += func.name() ? func.name() : '[anonymous]';
    }
  }

  // Render arguments for normal frames.
  if (!this.isDebuggerFrame()) {
    result += '(';
    for (var i = 0; i < this.argumentCount(); i++) {
      if (i != 0) result += ', ';
      if (this.argumentName(i)) {
        result += this.argumentName(i);
        result += '=';
      }
      result += this.argumentValue(i).toText();
    }
    result += ')';
  }
2032

2033 2034 2035 2036
  if (this.isAtReturn()) {
    result += ' returning ';
    result += this.returnValue().toText();
  }
2037

2038
  return result;
2039
};
2040 2041 2042 2043 2044 2045 2046


FrameMirror.prototype.sourceAndPositionText = function() {
  // Format source and position.
  var result = '';
  var func = this.func();
  if (func.resolved()) {
2047 2048 2049 2050
    var script = func.script();
    if (script) {
      if (script.name()) {
        result += script.name();
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071
      } else {
        result += '[unnamed]';
      }
      if (!this.isDebuggerFrame()) {
        var location = this.sourceLocation();
        result += ' line ';
        result += !IS_UNDEFINED(location) ? (location.line + 1) : '?';
        result += ' column ';
        result += !IS_UNDEFINED(location) ? (location.column + 1) : '?';
        if (!IS_UNDEFINED(this.sourcePosition())) {
          result += ' (position ' + (this.sourcePosition() + 1) + ')';
        }
      }
    } else {
      result += '[no source]';
    }
  } else {
    result += '[unresolved]';
  }

  return result;
2072
};
2073 2074 2075 2076 2077


FrameMirror.prototype.localsText = function() {
  // Format local variables.
  var result = '';
2078
  var locals_count = this.localCount();
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089
  if (locals_count > 0) {
    for (var i = 0; i < locals_count; ++i) {
      result += '      var ';
      result += this.localName(i);
      result += ' = ';
      result += this.localValue(i).toText();
      if (i < locals_count - 1) result += '\n';
    }
  }

  return result;
2090
};
2091 2092


2093 2094 2095 2096 2097 2098 2099 2100 2101
FrameMirror.prototype.restart = function() {
  var result = %LiveEditRestartFrame(this.break_id_, this.index_);
  if (IS_UNDEFINED(result)) {
    result = "Failed to find requested frame";
  }
  return result;
};


2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
FrameMirror.prototype.toText = function(opt_locals) {
  var result = '';
  result += '#' + (this.index() <= 9 ? '0' : '') + this.index();
  result += ' ';
  result += this.invocationText();
  result += ' ';
  result += this.sourceAndPositionText();
  if (opt_locals) {
    result += '\n';
    result += this.localsText();
  }
  return result;
2114
};
2115 2116


2117
// This indexes correspond definitions in debug-scopes.h.
2118 2119
var kScopeDetailsTypeIndex = 0;
var kScopeDetailsObjectIndex = 1;
2120
var kScopeDetailsNameIndex = 2;
2121 2122 2123
var kScopeDetailsStartPositionIndex = 3;
var kScopeDetailsEndPositionIndex = 4;
var kScopeDetailsFunctionIndex = 5;
2124

2125
function ScopeDetails(frame, fun, gen, index, opt_details) {
2126 2127
  if (frame) {
    this.break_id_ = frame.break_id_;
2128 2129
    this.details_ = opt_details ||
                    %GetScopeDetails(frame.break_id_,
2130 2131 2132
                                     frame.details_.frameId(),
                                     frame.details_.inlinedFrameIndex(),
                                     index);
2133 2134
    this.frame_id_ = frame.details_.frameId();
    this.inlined_frame_id_ = frame.details_.inlinedFrameIndex();
2135
  } else if (fun) {
2136
    this.details_ = opt_details || %GetFunctionScopeDetails(fun.value(), index);
2137
    this.fun_value_ = fun.value();
2138
    this.break_id_ = UNDEFINED;
2139 2140 2141 2142 2143
  } else {
    this.details_ =
      opt_details || %GetGeneratorScopeDetails(gen.value(), index);
    this.gen_value_ = gen.value();
    this.break_id_ = UNDEFINED;
2144
  }
2145
  this.index_ = index;
2146 2147 2148 2149
}


ScopeDetails.prototype.type = function() {
2150 2151 2152
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
2153
  return this.details_[kScopeDetailsTypeIndex];
2154
};
2155 2156 2157


ScopeDetails.prototype.object = function() {
2158 2159 2160
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
2161
  return this.details_[kScopeDetailsObjectIndex];
2162
};
2163 2164


2165 2166 2167 2168 2169 2170 2171 2172
ScopeDetails.prototype.name = function() {
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
  return this.details_[kScopeDetailsNameIndex];
};


2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
ScopeDetails.prototype.startPosition = function() {
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
  return this.details_[kScopeDetailsStartPositionIndex];
}


ScopeDetails.prototype.endPosition = function() {
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
  return this.details_[kScopeDetailsEndPositionIndex];
}

ScopeDetails.prototype.func = function() {
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
  }
  return this.details_[kScopeDetailsFunctionIndex];
}


2196 2197 2198 2199 2200 2201
ScopeDetails.prototype.setVariableValueImpl = function(name, new_value) {
  var raw_res;
  if (!IS_UNDEFINED(this.break_id_)) {
    %CheckExecutionState(this.break_id_);
    raw_res = %SetScopeVariableValue(this.break_id_, this.frame_id_,
        this.inlined_frame_id_, this.index_, name, new_value);
2202
  } else if (!IS_UNDEFINED(this.fun_value_)) {
2203 2204
    raw_res = %SetScopeVariableValue(this.fun_value_, null, null, this.index_,
        name, new_value);
2205 2206 2207
  } else {
    raw_res = %SetScopeVariableValue(this.gen_value_, null, null, this.index_,
        name, new_value);
2208
  }
2209
  if (!raw_res) throw %make_error(kDebugger, "Failed to set variable value");
2210 2211 2212
};


2213
/**
2214 2215
 * Mirror object for scope of frame or function. Either frame or function must
 * be specified.
2216
 * @param {FrameMirror} frame The frame this scope is a part of
2217
 * @param {FunctionMirror} function The function this scope is a part of
2218
 * @param {GeneratorMirror} gen The generator this scope is a part of
2219
 * @param {number} index The scope index in the frame
2220
 * @param {Array=} opt_details Raw scope details data
2221 2222 2223
 * @constructor
 * @extends Mirror
 */
2224
function ScopeMirror(frame, fun, gen, index, opt_details) {
2225
  %_Call(Mirror, this, MirrorType.SCOPE_TYPE);
2226 2227 2228
  if (frame) {
    this.frame_index_ = frame.index_;
  } else {
2229
    this.frame_index_ = UNDEFINED;
2230
  }
2231
  this.scope_index_ = index;
2232
  this.details_ = new ScopeDetails(frame, fun, gen, index, opt_details);
2233 2234 2235 2236
}
inherits(ScopeMirror, Mirror);


2237 2238 2239 2240 2241
ScopeMirror.prototype.details = function() {
  return this.details_;
};


2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257
ScopeMirror.prototype.frameIndex = function() {
  return this.frame_index_;
};


ScopeMirror.prototype.scopeIndex = function() {
  return this.scope_index_;
};


ScopeMirror.prototype.scopeType = function() {
  return this.details_.type();
};


ScopeMirror.prototype.scopeObject = function() {
2258
  // For local, closure and script scopes create a mirror
2259 2260
  // as these objects are created on the fly materializing the local
  // or closure scopes and therefore will not preserve identity.
2261
  return MakeMirror(this.details_.object());
2262 2263 2264
};


2265 2266 2267 2268 2269
ScopeMirror.prototype.setVariableValue = function(name, new_value) {
  this.details_.setVariableValueImpl(name, new_value);
};


2270 2271 2272 2273 2274 2275 2276
/**
 * Mirror object for script source.
 * @param {Script} script The script object
 * @constructor
 * @extends Mirror
 */
function ScriptMirror(script) {
2277
  %_Call(Mirror, this, MirrorType.SCRIPT_TYPE);
2278
  this.script_ = script;
2279
  this.context_ = new ContextMirror(script.context_data);
2280
}
2281 2282 2283
inherits(ScriptMirror, Mirror);


2284 2285 2286 2287 2288
ScriptMirror.prototype.value = function() {
  return this.script_;
};


2289
ScriptMirror.prototype.name = function() {
2290
  return this.script_.name || this.script_.nameOrSourceURL();
2291 2292 2293
};


2294 2295 2296 2297 2298
ScriptMirror.prototype.id = function() {
  return this.script_.id;
};


2299 2300 2301 2302 2303
ScriptMirror.prototype.source = function() {
  return this.script_.source;
};


2304
ScriptMirror.prototype.setSource = function(source) {
2305
  if (!IS_STRING(source)) throw %make_error(kDebugger, "Source is not a string");
2306 2307 2308 2309
  %DebugSetScriptSource(this.script_, source);
};


2310 2311 2312 2313 2314 2315 2316 2317 2318 2319
ScriptMirror.prototype.lineOffset = function() {
  return this.script_.line_offset;
};


ScriptMirror.prototype.columnOffset = function() {
  return this.script_.column_offset;
};


2320 2321 2322 2323 2324
ScriptMirror.prototype.data = function() {
  return this.script_.data;
};


2325 2326 2327 2328 2329
ScriptMirror.prototype.scriptType = function() {
  return this.script_.type;
};


2330 2331 2332 2333 2334
ScriptMirror.prototype.compilationType = function() {
  return this.script_.compilation_type;
};


2335
ScriptMirror.prototype.lineCount = function() {
2336
  return %ScriptLineCount(this.script_);
2337 2338 2339
};


2340 2341 2342
ScriptMirror.prototype.locationFromPosition = function(
    position, include_resource_offset) {
  return this.script_.locationFromPosition(position, include_resource_offset);
2343
};
2344 2345


2346 2347 2348 2349 2350
ScriptMirror.prototype.context = function() {
  return this.context_;
};


2351 2352 2353 2354 2355 2356 2357
ScriptMirror.prototype.evalFromScript = function() {
  return MakeMirror(this.script_.eval_from_script);
};


ScriptMirror.prototype.evalFromFunctionName = function() {
  return MakeMirror(this.script_.eval_from_function_name);
2358 2359 2360 2361
};


ScriptMirror.prototype.evalFromLocation = function() {
2362 2363 2364 2365
  var eval_from_script = this.evalFromScript();
  if (!eval_from_script.isUndefined()) {
    var position = this.script_.eval_from_script_position;
    return eval_from_script.locationFromPosition(position, true);
2366 2367 2368 2369
  }
};


2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382
ScriptMirror.prototype.toText = function() {
  var result = '';
  result += this.name();
  result += ' (lines: ';
  if (this.lineOffset() > 0) {
    result += this.lineOffset();
    result += '-';
    result += this.lineOffset() + this.lineCount() - 1;
  } else {
    result += this.lineCount();
  }
  result += ')';
  return result;
2383
};
2384 2385


2386 2387 2388 2389 2390 2391 2392
/**
 * Mirror object for context.
 * @param {Object} data The context data
 * @constructor
 * @extends Mirror
 */
function ContextMirror(data) {
2393
  %_Call(Mirror, this, MirrorType.CONTEXT_TYPE);
2394 2395 2396 2397 2398 2399 2400 2401 2402
  this.data_ = data;
}
inherits(ContextMirror, Mirror);


ContextMirror.prototype.data = function() {
  return this.data_;
};

2403 2404 2405 2406
// ----------------------------------------------------------------------------
// Exports

utils.InstallConstants(global, [
2407
  "MakeMirror", MakeMirror,
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
  "ScopeType", ScopeType,
  "PropertyType", PropertyType,
  "PropertyAttribute", PropertyAttribute,
  "Mirror", Mirror,
  "ValueMirror", ValueMirror,
  "UndefinedMirror", UndefinedMirror,
  "NullMirror", NullMirror,
  "BooleanMirror", BooleanMirror,
  "NumberMirror", NumberMirror,
  "StringMirror", StringMirror,
  "SymbolMirror", SymbolMirror,
  "ObjectMirror", ObjectMirror,
  "FunctionMirror", FunctionMirror,
  "UnresolvedFunctionMirror", UnresolvedFunctionMirror,
  "ArrayMirror", ArrayMirror,
  "DateMirror", DateMirror,
  "RegExpMirror", RegExpMirror,
  "ErrorMirror", ErrorMirror,
  "PromiseMirror", PromiseMirror,
  "MapMirror", MapMirror,
  "SetMirror", SetMirror,
  "IteratorMirror", IteratorMirror,
  "GeneratorMirror", GeneratorMirror,
  "PropertyMirror", PropertyMirror,
  "InternalPropertyMirror", InternalPropertyMirror,
  "FrameMirror", FrameMirror,
  "ScriptMirror", ScriptMirror,
  "ScopeMirror", ScopeMirror,
  "FrameDetails", FrameDetails,
]);

})