OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 30 matching lines...) Expand all Loading... |
42 | 42 |
43 function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { | 43 function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { |
44 // Create mirror and JSON representation. | 44 // Create mirror and JSON representation. |
45 var mirror = debug.MakeMirror(obj); | 45 var mirror = debug.MakeMirror(obj); |
46 var serializer = debug.MakeMirrorSerializer(); | 46 var serializer = debug.MakeMirrorSerializer(); |
47 var json = JSON.stringify(serializer.serializeValue(mirror)); | 47 var json = JSON.stringify(serializer.serializeValue(mirror)); |
48 var refs = new MirrorRefCache( | 48 var refs = new MirrorRefCache( |
49 JSON.stringify(serializer.serializeReferencedObjects())); | 49 JSON.stringify(serializer.serializeReferencedObjects())); |
50 | 50 |
51 // Check the mirror hierachy. | 51 // Check the mirror hierachy. |
52 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy'); | 52 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierarchy'); |
53 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy'); | 53 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierarchy')
; |
54 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy')
; | 54 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierarchy'
); |
55 | 55 |
56 // Check the mirror properties. | 56 // Check the mirror properties. |
57 assertTrue(mirror.isObject(), 'Unexpected mirror'); | 57 assertTrue(mirror.isObject(), 'Unexpected mirror'); |
58 assertEquals('object', mirror.type(), 'Unexpected mirror type'); | 58 assertEquals('object', mirror.type(), 'Unexpected mirror type'); |
59 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror'); | 59 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror'); |
60 assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name'); | 60 assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name'); |
61 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpe
cted mirror hierachy'); | 61 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpe
cted mirror hierarchy'); |
62 assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected const
ructor function name'); | 62 assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected const
ructor function name'); |
63 assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hi
erachy'); | 63 assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hi
erarchy'); |
64 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro
r hierachy'); | 64 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro
r hierarchy'); |
65 assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected'); | 65 assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected'); |
66 assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected')
; | 66 assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected')
; |
67 | 67 |
68 var names = mirror.propertyNames(); | 68 var names = mirror.propertyNames(); |
69 var properties = mirror.properties(); | 69 var properties = mirror.properties(); |
70 assertEquals(names.length, properties.length); | 70 assertEquals(names.length, properties.length); |
71 for (var i = 0; i < properties.length; i++) { | 71 for (var i = 0; i < properties.length; i++) { |
72 assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierach
y'); | 72 assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierarc
hy'); |
73 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror
hierachy'); | 73 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror
hierarchy'); |
74 assertEquals('property', properties[i].type(), 'Unexpected mirror type'); | 74 assertEquals('property', properties[i].type(), 'Unexpected mirror type'); |
75 assertEquals(names[i], properties[i].name(), 'Unexpected property name'); | 75 assertEquals(names[i], properties[i].name(), 'Unexpected property name'); |
76 } | 76 } |
77 | 77 |
| 78 var internalProperties = mirror.internalProperties(); |
| 79 for (var i = 0; i < internalProperties.length; i++) { |
| 80 assertTrue(internalProperties[i] instanceof debug.Mirror, 'Unexpected mirror
hierarchy'); |
| 81 assertTrue(internalProperties[i] instanceof debug.InternalPropertyMirror, 'U
nexpected mirror hierarchy'); |
| 82 assertEquals('internalProperty', internalProperties[i].type(), 'Unexpected m
irror type'); |
| 83 } |
| 84 |
78 for (var p in obj) { | 85 for (var p in obj) { |
79 var property_mirror = mirror.property(p); | 86 var property_mirror = mirror.property(p); |
80 assertTrue(property_mirror instanceof debug.PropertyMirror); | 87 assertTrue(property_mirror instanceof debug.PropertyMirror); |
81 assertEquals(p, property_mirror.name()); | 88 assertEquals(p, property_mirror.name()); |
82 // If the object has some special properties don't test for these. | 89 // If the object has some special properties don't test for these. |
83 if (!hasSpecialProperties) { | 90 if (!hasSpecialProperties) { |
84 assertEquals(0, property_mirror.attributes(), property_mirror.name()); | 91 assertEquals(0, property_mirror.attributes(), property_mirror.name()); |
85 assertFalse(property_mirror.isReadOnly()); | 92 assertFalse(property_mirror.isReadOnly()); |
86 assertTrue(property_mirror.isEnum()); | 93 assertTrue(property_mirror.isEnum()); |
87 assertTrue(property_mirror.canDelete()); | 94 assertTrue(property_mirror.canDelete()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 172 |
166 // Test a number of different objects. | 173 // Test a number of different objects. |
167 testObjectMirror({}, 'Object', 'Object'); | 174 testObjectMirror({}, 'Object', 'Object'); |
168 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); | 175 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); |
169 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y)
;}}, 'Object', 'Object'); | 176 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y)
;}}, 'Object', 'Object'); |
170 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); | 177 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); |
171 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties | 178 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties |
172 testObjectMirror(this.__proto__, 'Object', ''); | 179 testObjectMirror(this.__proto__, 'Object', ''); |
173 testObjectMirror([], 'Array', 'Array'); | 180 testObjectMirror([], 'Array', 'Array'); |
174 testObjectMirror([1,2], 'Array', 'Array'); | 181 testObjectMirror([1,2], 'Array', 'Array'); |
| 182 testObjectMirror(Object(17), 'Number', 'Number'); |
175 | 183 |
176 // Test circular references. | 184 // Test circular references. |
177 o = {}; | 185 o = {}; |
178 o.o = o; | 186 o.o = o; |
179 testObjectMirror(o, 'Object', 'Object'); | 187 testObjectMirror(o, 'Object', 'Object'); |
180 | 188 |
181 // Test that non enumerable properties are part of the mirror | 189 // Test that non enumerable properties are part of the mirror |
182 global_mirror = debug.MakeMirror(this); | 190 global_mirror = debug.MakeMirror(this); |
183 assertEquals('property', global_mirror.property("Math").type()); | 191 assertEquals('property', global_mirror.property("Math").type()); |
184 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob
al_mirror.property("Math").attributes()); | 192 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob
al_mirror.property("Math").attributes()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 231 |
224 // Test objects with native accessors. | 232 // Test objects with native accessors. |
225 mirror = debug.MakeMirror(new String('abc')); | 233 mirror = debug.MakeMirror(new String('abc')); |
226 assertTrue(mirror instanceof debug.ObjectMirror); | 234 assertTrue(mirror instanceof debug.ObjectMirror); |
227 assertFalse(mirror.property('length').hasGetter()); | 235 assertFalse(mirror.property('length').hasGetter()); |
228 assertFalse(mirror.property('length').hasSetter()); | 236 assertFalse(mirror.property('length').hasSetter()); |
229 assertTrue(mirror.property('length').isNative()); | 237 assertTrue(mirror.property('length').isNative()); |
230 assertEquals('a', mirror.property(0).value().value()); | 238 assertEquals('a', mirror.property(0).value().value()); |
231 assertEquals('b', mirror.property(1).value().value()); | 239 assertEquals('b', mirror.property(1).value().value()); |
232 assertEquals('c', mirror.property(2).value().value()); | 240 assertEquals('c', mirror.property(2).value().value()); |
| 241 |
| 242 // Test value wrapper internal properties. |
| 243 mirror = debug.MakeMirror(Object("Capybara")); |
| 244 var ip = mirror.internalProperties(); |
| 245 /* |
| 246 assertEquals(1, ip.length); |
| 247 assertEquals("[[PrimitiveValue]]", ip[0].name()); |
| 248 assertEquals("string", ip[0].value().type()); |
| 249 assertEquals("Capybara", ip[0].value().value()); |
| 250 */ |
| 251 |
| 252 // Test bound function internal properties. |
| 253 mirror = debug.MakeMirror(Number.bind(Array, 2)); |
| 254 ip = mirror.internalProperties(); |
| 255 var property_map = {}; |
| 256 for (var i = 0; i < ip.length; i++) { |
| 257 property_map[ip[i].name()] = ip[i]; |
| 258 } |
| 259 /* |
| 260 assertEquals(3, ip.length); |
| 261 assertTrue("[[BoundThis]]" in property_map); |
| 262 assertEquals("function", property_map["[[BoundThis]]"].value().type()); |
| 263 assertEquals(Array, property_map["[[BoundThis]]"].value().value()); |
| 264 assertTrue("[[TargetFunction]]" in property_map); |
| 265 assertEquals("function", property_map["[[TargetFunction]]"].value().type()); |
| 266 assertEquals(Number, property_map["[[TargetFunction]]"].value().value()); |
| 267 assertTrue("[[BoundArgs]]" in property_map); |
| 268 assertEquals("object", property_map["[[BoundArgs]]"].value().type()); |
| 269 assertEquals(1, property_map["[[BoundArgs]]"].value().value().length); |
| 270 */ |
OLD | NEW |