1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2008 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Flags: --expose-debug-as debug
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test the mirror object for objects
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction MirrorRefCache(json_refs) {
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var tmp = eval('(' + json_refs + ')');
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.refs_ = [];
34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  for (var i = 0; i < tmp.length; i++) {
35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    this.refs_[tmp[i].handle] = tmp[i];
36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockMirrorRefCache.prototype.lookup = function(handle) {
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return this.refs_[handle];
41257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch};
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Create mirror and JSON representation.
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var mirror = debug.MakeMirror(obj);
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var serializer = debug.MakeMirrorSerializer();
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var json = JSON.stringify(serializer.serializeValue(mirror));
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var refs = new MirrorRefCache(
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      JSON.stringify(serializer.serializeReferencedObjects()));
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check the mirror hierachy.
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check the mirror properties.
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror.isObject(), 'Unexpected mirror');
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals('object', mirror.type(), 'Unexpected mirror type');
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name');
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected constructor function name');
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected');
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected');
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var names = mirror.propertyNames();
69257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  var properties = mirror.properties();
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(names.length, properties.length);
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  for (var i = 0; i < properties.length; i++) {
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertEquals('property', properties[i].type(), 'Unexpected mirror type');
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertEquals(names[i], properties[i].name(), 'Unexpected property name');
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
77b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  for (var p in obj) {
79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    var property_mirror = mirror.property(p);
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertTrue(property_mirror instanceof debug.PropertyMirror);
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertEquals(p, property_mirror.name());
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // If the object has some special properties don't test for these.
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (!hasSpecialProperties) {
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      assertEquals(0, property_mirror.attributes(), property_mirror.name());
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      assertFalse(property_mirror.isReadOnly());
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      assertTrue(property_mirror.isEnum());
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      assertTrue(property_mirror.canDelete());
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Parse JSON representation and check.
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var fromJSON = eval('(' + json + ')');
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(cls_name, fromJSON.className, 'Unexpected mirror class name in JSON');
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref).type, 'Unexpected proto object type in JSON');
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check that the serialization contains all properties.
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON');
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  for (var i = 0; i < fromJSON.properties.length; i++) {
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    var name = fromJSON.properties[i].name;
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (typeof name == 'undefined') name = fromJSON.properties[i].index;
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    var found = false;
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    for (var j = 0; j < names.length; j++) {
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      if (names[j] == name) {
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        // Check that serialized handle is correct.
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref, 'Unexpected serialized handle');
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        // Check that serialized name is correct.
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpected serialized name');
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        // If property type is normal property type is not serialized.
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        if (properties[i].propertyType() != debug.PropertyType.Normal) {
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType, 'Unexpected serialized property type');
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        } else {
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined', 'Unexpected serialized property type');
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        }
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        // If there are no attributes attributes are not serialized.
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        if (properties[i].attributes() != debug.PropertyAttribute.None) {
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes, 'Unexpected serialized attributes');
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        } else {
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        }
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
133257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch        // Lookup the serialized object from the handle reference.
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        var o = refs.lookup(fromJSON.properties[i].ref);
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        assertTrue(o != void 0, 'Referenced object is not serialized');
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        if (properties[i].value().isPrimitive()) {
139257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch          if (properties[i].value().type() == "null" ||
140257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch              properties[i].value().type() == "undefined") {
141257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch            // Null and undefined has no value property.
142257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch            assertFalse("value" in o, 'Unexpected value property for ' + name);
143257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch          } else if (properties[i].value().type() == "number" &&
144257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                     !isFinite(properties[i].value().value())) {
145257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch            assertEquals(String(properties[i].value().value()), o.value,
146257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch                         'Unexpected serialized property value for ' + name);
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          } else {
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block            assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name);
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          }
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        } else if (properties[i].value().isFunction()) {
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block          assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name);
152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        }
153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        found = true;
154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      }
155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    assertTrue(found, '"' + name + '" not found (' + json + ')');
157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction Point(x,y) {
162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x_ = x;
163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y_ = y;
164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test a number of different objects.
167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror({}, 'Object', 'Object');
168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror({'a':1,'b':2}, 'Object', 'Object');
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y);}}, 'Object', 'Object');
170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror(this, 'global', '', true);  // Global object has special properties
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror(this.__proto__, 'Object', '');
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror([], 'Array', 'Array');
174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror([1,2], 'Array', 'Array');
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test circular references.
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = {};
178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko.o = o;
179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror(o, 'Object', 'Object');
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test that non enumerable properties are part of the mirror
182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockglobal_mirror = debug.MakeMirror(this);
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('property', global_mirror.property("Math").type());
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + global_mirror.property("Math").attributes());
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockmath_mirror = global_mirror.property("Math").value();
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('property', math_mirror.property("E").type());
188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(math_mirror.property("E").isEnum(), "Math.E is enumerable");
189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(math_mirror.property("E").isReadOnly());
190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(math_mirror.property("E").canDelete());
191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test objects with JavaScript accessors.
193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = {}
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko.__defineGetter__('a', function(){return 'a';});
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko.__defineSetter__('b', function(){});
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko.__defineGetter__('c', function(){throw 'c';});
197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko.__defineSetter__('c', function(){throw 'c';});
198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlocktestObjectMirror(o, 'Object', 'Object');
199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockmirror = debug.MakeMirror(o);
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a has getter but no setter.
201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror.property('a').hasGetter());
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(mirror.property('a').hasSetter());
203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(debug.PropertyType.Callbacks, mirror.property('a').propertyType());
204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function', mirror.property('a').getter().type());
205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('undefined', mirror.property('a').setter().type());
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function (){return \'a\';}', mirror.property('a').getter().source());
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// b has setter but no getter.
208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(mirror.property('b').hasGetter());
209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror.property('b').hasSetter());
210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(debug.PropertyType.Callbacks, mirror.property('b').propertyType());
211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('undefined', mirror.property('b').getter().type());
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function', mirror.property('b').setter().type());
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function (){}', mirror.property('b').setter().source());
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(mirror.property('b').isException());
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// c has both getter and setter. The getter throws an exception.
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror.property('c').hasGetter());
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror.property('c').hasSetter());
218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(debug.PropertyType.Callbacks, mirror.property('c').propertyType());
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function', mirror.property('c').getter().type());
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function', mirror.property('c').setter().type());
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function (){throw \'c\';}', mirror.property('c').getter().source());
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('function (){throw \'c\';}', mirror.property('c').setter().source());
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Test objects with native accessors.
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockmirror = debug.MakeMirror(new String('abc'));
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror instanceof debug.ObjectMirror);
227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(mirror.property('length').hasGetter());
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertFalse(mirror.property('length').hasSetter());
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertTrue(mirror.property('length').isNative());
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('a', mirror.property(0).value().value());
231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('b', mirror.property(1).value().value());
232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals('c', mirror.property(2).value().value());
233