Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/mirror-object.js

Issue 18092: Added handles to the mirror objects. When a mirror for an object is created... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/mirror-number.js ('k') | test/mjsunit/mirror-regexp.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --expose-debug-as debug 28 // Flags: --expose-debug-as debug
29 // Test the mirror object for objects 29 // Test the mirror object for objects
30 30
31 function testObjectMirror(o, cls_name, ctor_name, hasSpecialProperties) { 31 function MirrorRefCache(json_refs) {
32 var tmp = eval('(' + json_refs + ')');
33 this.refs_ = [];
34 for (var i = 0; i < tmp.length; i++) {
35 this.refs_[tmp[i].handle] = tmp[i];
36 }
37 }
38
39 MirrorRefCache.prototype.lookup = function(handle) {
40 return this.refs_[handle];
41 }
42
43 function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
32 // Create mirror and JSON representation. 44 // Create mirror and JSON representation.
33 var mirror = debug.MakeMirror(o); 45 var mirror = debug.MakeMirror(obj);
34 var json = mirror.toJSONProtocol(true); 46 var serializer = debug.MakeMirrorSerializer();
47 var json = serializer.serializeValue(mirror);
48 var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
35 49
36 // Check the mirror hierachy. 50 // Check the mirror hierachy.
37 assertTrue(mirror instanceof debug.Mirror); 51 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
38 assertTrue(mirror instanceof debug.ValueMirror); 52 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
39 assertTrue(mirror instanceof debug.ObjectMirror); 53 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy') ;
40 54
41 // Check the mirror properties. 55 // Check the mirror properties.
42 assertTrue(mirror.isObject()); 56 assertTrue(mirror.isObject(), 'Unexpected mirror');
43 assertEquals('object', mirror.type()); 57 assertEquals('object', mirror.type(), 'Unexpected mirror type');
44 assertFalse(mirror.isPrimitive()); 58 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
45 assertEquals(cls_name, mirror.className()); 59 assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name');
46 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); 60 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpe cted mirror hierachy');
47 assertTrue(mirror.protoObject() instanceof debug.Mirror); 61 assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected const ructor function name');
48 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); 62 assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hi erachy');
49 assertFalse(mirror.hasNamedInterceptor(), "hasNamedInterceptor()"); 63 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro r hierachy');
50 assertFalse(mirror.hasIndexedInterceptor(), "hasIndexedInterceptor()"); 64 assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected');
65 assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected') ;
51 66
52 var names = mirror.propertyNames(); 67 var names = mirror.propertyNames();
53 var properties = mirror.properties() 68 var properties = mirror.properties()
54 assertEquals(names.length, properties.length); 69 assertEquals(names.length, properties.length);
55 for (var i = 0; i < properties.length; i++) { 70 for (var i = 0; i < properties.length; i++) {
56 assertTrue(properties[i] instanceof debug.Mirror); 71 assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierach y');
57 assertTrue(properties[i] instanceof debug.PropertyMirror); 72 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
58 assertEquals('property', properties[i].type()); 73 assertEquals('property', properties[i].type(), 'Unexpected mirror type');
59 assertEquals(names[i], properties[i].name()); 74 assertEquals(names[i], properties[i].name(), 'Unexpected property name');
60 } 75 }
61 76
62 for (var p in o) { 77 for (var p in obj) {
63 var property_mirror = mirror.property(p); 78 var property_mirror = mirror.property(p);
64 assertTrue(property_mirror instanceof debug.PropertyMirror); 79 assertTrue(property_mirror instanceof debug.PropertyMirror);
65 assertEquals(p, property_mirror.name()); 80 assertEquals(p, property_mirror.name());
66 // If the object has some special properties don't test for these. 81 // If the object has some special properties don't test for these.
67 if (!hasSpecialProperties) { 82 if (!hasSpecialProperties) {
68 assertEquals(0, property_mirror.attributes(), property_mirror.name()); 83 assertEquals(0, property_mirror.attributes(), property_mirror.name());
69 assertFalse(property_mirror.isReadOnly()); 84 assertFalse(property_mirror.isReadOnly());
70 assertTrue(property_mirror.isEnum()); 85 assertTrue(property_mirror.isEnum());
71 assertTrue(property_mirror.canDelete()); 86 assertTrue(property_mirror.canDelete());
72 } 87 }
73 } 88 }
74 89
75 // Parse JSON representation and check. 90 // Parse JSON representation and check.
76 var fromJSON = eval('(' + json + ')'); 91 var fromJSON = eval('(' + json + ')');
77 assertEquals('object', fromJSON.type); 92 assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
78 assertEquals(cls_name, fromJSON.className); 93 assertEquals(cls_name, fromJSON.className, 'Unexpected mirror class name in JS ON');
79 assertEquals('function', fromJSON.constructorFunction.type); 94 assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFuncti on.ref, 'Unexpected constructor function handle in JSON');
80 if (ctor_name !== undefined) 95 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, ' Unexpected constructor function type in JSON');
81 assertEquals(ctor_name, fromJSON.constructorFunction.name); 96 assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'U nexpected constructor function name in JSON');
82 assertEquals(void 0, fromJSON.namedInterceptor); 97 assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpec ted proto object handle in JSON');
83 assertEquals(void 0, fromJSON.indexedInterceptor); 98 assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref ).type, 'Unexpected proto object type in JSON');
84 99 assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');
85 // For array the index properties are seperate from named properties. 100 assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeOb ject.ref).type, 'Unexpected prototype object type in JSON');
86 if (!cls_name == 'Array') { 101 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
87 assertEquals(names.length, fromJSON.properties.length, 'Some properties miss ing in JSON'); 102 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe cted in JSON');
88 }
89 103
90 // Check that the serialization contains all properties. 104 // Check that the serialization contains all properties.
105 assertEquals(names.length, fromJSON.properties.length, 'Some properties missin g in JSON');
91 for (var i = 0; i < fromJSON.properties.length; i++) { 106 for (var i = 0; i < fromJSON.properties.length; i++) {
92 var name = fromJSON.properties[i].name; 107 var name = fromJSON.properties[i].name;
93 if (!name) name = fromJSON.properties[i].index; 108 if (!name) name = fromJSON.properties[i].index;
94 var found = false; 109 var found = false;
95 for (var j = 0; j < names.length; j++) { 110 for (var j = 0; j < names.length; j++) {
96 if (names[j] == name) { 111 if (names[j] == name) {
97 assertEquals(properties[i].value().type(), fromJSON.properties[i].value. type); 112 // Check that serialized handle is correct.
98 // If property type is normal nothing is serialized. 113 assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref, 'Unexpected serialized handle');
114
115 // Check that serialized name is correct.
116 assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpec ted serialized name');
117
118 // If property type is normal property type is not serialized.
99 if (properties[i].propertyType() != debug.PropertyType.Normal) { 119 if (properties[i].propertyType() != debug.PropertyType.Normal) {
100 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop ertyType); 120 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop ertyType, 'Unexpected serialized property type');
101 } else { 121 } else {
102 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' ); 122 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' , 'Unexpected serialized property type');
103 } 123 }
104 // If there are no attributes nothing is serialized. 124
125 // If there are no attributes attributes are not serialized.
105 if (properties[i].attributes() != debug.PropertyAttribute.None) { 126 if (properties[i].attributes() != debug.PropertyAttribute.None) {
106 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes); 127 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes, 'Unexpected serialized attributes');
107 } else { 128 } else {
108 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined'); 129 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');
109 } 130 }
110 if (!properties[i].value().isPrimitive()) { 131
111 // NaN is not equal to NaN. 132 // Lookup the serialized object from the handle reference.
112 if (isNaN(properties[i].value().value())) { 133 var o = refs.lookup(fromJSON.properties[i].ref);
113 assertTrue(isNaN(fromJSON.properties[i].value.value)); 134 assertTrue(o != void 0, 'Referenced object is not serialized');
114 } else { 135
115 assertEquals(properties[i].value().value(), fromJSON.properties[i].v alue.value); 136 assertEquals(properties[i].value().type(), o.type, 'Unexpected serialize d property type for ' + name);
116 } 137 if (properties[i].value().isPrimitive()) {
138 assertEquals(properties[i].value().value(), o.value, 'Unexpected seria lized property value for ' + name);
139 } else if (properties[i].value().isFunction()) {
140 assertEquals(properties[i].value().source(), o.source, 'Unexpected ser ialized property value for ' + name);
117 } 141 }
118 found = true; 142 found = true;
119 } 143 }
120 } 144 }
121 assertTrue(found, '"' + name + '" not found (' + json + ')'); 145 assertTrue(found, '"' + name + '" not found (' + json + ')');
122 } 146 }
123 } 147 }
124 148
125 149
126 function Point(x,y) { 150 function Point(x,y) {
127 this.x_ = x; 151 this.x_ = x;
128 this.y_ = y; 152 this.y_ = y;
129 } 153 }
130 154
131 155
132 // Test a number of different objects. 156 // Test a number of different objects.
133 testObjectMirror({}, 'Object', 'Object'); 157 testObjectMirror({}, 'Object', 'Object');
134 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); 158 testObjectMirror({'a':1,'b':2}, 'Object', 'Object');
135 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object'); 159 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object');
136 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); 160 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');
137 testObjectMirror(this, 'global', undefined, true); // Global object has special properties 161 testObjectMirror(this, 'global', '', true); // Global object has special proper ties
138 testObjectMirror([], 'Array', 'Array'); 162 testObjectMirror([], 'Array', 'Array');
139 testObjectMirror([1,2], 'Array', 'Array'); 163 testObjectMirror([1,2], 'Array', 'Array');
140 164
141 // Test circular references. 165 // Test circular references.
142 o = {}; 166 o = {};
143 o.o = o; 167 o.o = o;
144 testObjectMirror(o, 'Object', 'Object'); 168 testObjectMirror(o, 'Object', 'Object');
145 169
146 // Test that non enumerable properties are part of the mirror 170 // Test that non enumerable properties are part of the mirror
147 global_mirror = debug.MakeMirror(this); 171 global_mirror = debug.MakeMirror(this);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 216
193 // Test objects with native accessors. 217 // Test objects with native accessors.
194 mirror = debug.MakeMirror(new String('abc')); 218 mirror = debug.MakeMirror(new String('abc'));
195 assertTrue(mirror instanceof debug.ObjectMirror); 219 assertTrue(mirror instanceof debug.ObjectMirror);
196 assertFalse(mirror.property('length').hasGetter()); 220 assertFalse(mirror.property('length').hasGetter());
197 assertFalse(mirror.property('length').hasSetter()); 221 assertFalse(mirror.property('length').hasSetter());
198 assertTrue(mirror.property('length').isNative()); 222 assertTrue(mirror.property('length').isNative());
199 assertEquals('a', mirror.property(0).value().value()); 223 assertEquals('a', mirror.property(0).value().value());
200 assertEquals('b', mirror.property(1).value().value()); 224 assertEquals('b', mirror.property(1).value().value());
201 assertEquals('c', mirror.property(2).value().value()); 225 assertEquals('c', mirror.property(2).value().value());
OLDNEW
« no previous file with comments | « test/mjsunit/mirror-number.js ('k') | test/mjsunit/mirror-regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698