OLD | NEW |
---|---|
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 20 matching lines...) Expand all Loading... | |
31 function MirrorRefCache(json_refs) { | 31 function MirrorRefCache(json_refs) { |
32 var tmp = eval('(' + json_refs + ')'); | 32 var tmp = eval('(' + json_refs + ')'); |
33 this.refs_ = []; | 33 this.refs_ = []; |
34 for (var i = 0; i < tmp.length; i++) { | 34 for (var i = 0; i < tmp.length; i++) { |
35 this.refs_[tmp[i].handle] = tmp[i]; | 35 this.refs_[tmp[i].handle] = tmp[i]; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 MirrorRefCache.prototype.lookup = function(handle) { | 39 MirrorRefCache.prototype.lookup = function(handle) { |
40 return this.refs_[handle]; | 40 return this.refs_[handle]; |
41 } | 41 }; |
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 hierachy'); |
53 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy'); | 53 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy'); |
54 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy') ; | 54 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy') ; |
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 hierachy'); |
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 erachy'); |
64 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro r hierachy'); | 64 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro r hierachy'); |
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 hierach y'); |
73 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy'); | 73 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy'); |
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 for (var p in obj) { | 78 for (var p in obj) { |
79 var property_mirror = mirror.property(p); | 79 var property_mirror = mirror.property(p); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' , 'Unexpected serialized property type'); | 123 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' , 'Unexpected serialized property type'); |
124 } | 124 } |
125 | 125 |
126 // If there are no attributes attributes are not serialized. | 126 // If there are no attributes attributes are not serialized. |
127 if (properties[i].attributes() != debug.PropertyAttribute.None) { | 127 if (properties[i].attributes() != debug.PropertyAttribute.None) { |
128 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes, 'Unexpected serialized attributes'); | 128 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes, 'Unexpected serialized attributes'); |
129 } else { | 129 } else { |
130 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes'); | 130 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes'); |
131 } | 131 } |
132 | 132 |
133 // Lookup the serialized object from the handle reference. | 133 // Lookup the serialized object from the handle reference. |
134 var o = refs.lookup(fromJSON.properties[i].ref); | 134 var o = refs.lookup(fromJSON.properties[i].ref); |
135 assertTrue(o != void 0, 'Referenced object is not serialized'); | 135 assertTrue(o != void 0, 'Referenced object is not serialized'); |
136 | 136 |
137 assertEquals(properties[i].value().type(), o.type, 'Unexpected serialize d property type for ' + name); | 137 assertEquals(properties[i].value().type(), o.type, 'Unexpected serialize d property type for ' + name); |
138 if (properties[i].value().isPrimitive()) { | 138 if (properties[i].value().isPrimitive()) { |
139 // Special check for NaN as NaN == NaN is false. | 139 if (!properties[i].value().type() == "null" && |
140 if (properties[i].value().isNumber() && isNaN(properties[i].value().va lue())) { | 140 !properties[i].value().type() == "undefined") { |
141 assertEquals('NaN', o.value, 'Unexpected serialized property value f or ' + name); | 141 // Null and undefined has no value property. |
142 } else { | |
143 assertEquals(properties[i].value().value(), o.value, 'Unexpected ser ialized property value for ' + name); | 142 assertEquals(properties[i].value().value(), o.value, 'Unexpected ser ialized property value for ' + name); |
144 } | 143 } |
Søren Thygesen Gjesse
2011/04/15 10:20:51
Should we test that there actually is no value pro
Lasse Reichstein
2011/04/15 11:33:54
let's.
Also, it seems I need to handle that NaN an
| |
145 } else if (properties[i].value().isFunction()) { | 144 } else if (properties[i].value().isFunction()) { |
146 assertEquals(properties[i].value().source(), o.source, 'Unexpected ser ialized property value for ' + name); | 145 assertEquals(properties[i].value().source(), o.source, 'Unexpected ser ialized property value for ' + name); |
147 } | 146 } |
148 found = true; | 147 found = true; |
149 } | 148 } |
150 } | 149 } |
151 assertTrue(found, '"' + name + '" not found (' + json + ')'); | 150 assertTrue(found, '"' + name + '" not found (' + json + ')'); |
152 } | 151 } |
153 } | 152 } |
154 | 153 |
155 | 154 |
156 function Point(x,y) { | 155 function Point(x,y) { |
157 this.x_ = x; | 156 this.x_ = x; |
158 this.y_ = y; | 157 this.y_ = y; |
159 } | 158 }1 |
Søren Thygesen Gjesse
2011/04/15 10:20:51
1 -> ;
Lasse Reichstein
2011/04/15 11:33:54
Removed the spurious "1".
| |
160 | 159 |
161 // Test a number of different objects. | 160 // Test a number of different objects. |
162 testObjectMirror({}, 'Object', 'Object'); | 161 testObjectMirror({}, 'Object', 'Object'); |
163 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); | 162 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); |
164 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object'); | 163 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object'); |
165 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); | 164 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); |
166 testObjectMirror(this, 'global', '', true); // Global object has special proper ties | 165 testObjectMirror(this, 'global', '', true); // Global object has special proper ties |
167 testObjectMirror(this.__proto__, 'Object', ''); | 166 testObjectMirror(this.__proto__, 'Object', ''); |
168 testObjectMirror([], 'Array', 'Array'); | 167 testObjectMirror([], 'Array', 'Array'); |
169 testObjectMirror([1,2], 'Array', 'Array'); | 168 testObjectMirror([1,2], 'Array', 'Array'); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 217 |
219 // Test objects with native accessors. | 218 // Test objects with native accessors. |
220 mirror = debug.MakeMirror(new String('abc')); | 219 mirror = debug.MakeMirror(new String('abc')); |
221 assertTrue(mirror instanceof debug.ObjectMirror); | 220 assertTrue(mirror instanceof debug.ObjectMirror); |
222 assertFalse(mirror.property('length').hasGetter()); | 221 assertFalse(mirror.property('length').hasGetter()); |
223 assertFalse(mirror.property('length').hasSetter()); | 222 assertFalse(mirror.property('length').hasSetter()); |
224 assertTrue(mirror.property('length').isNative()); | 223 assertTrue(mirror.property('length').isNative()); |
225 assertEquals('a', mirror.property(0).value().value()); | 224 assertEquals('a', mirror.property(0).value().value()); |
226 assertEquals('b', mirror.property(1).value().value()); | 225 assertEquals('b', mirror.property(1).value().value()); |
227 assertEquals('c', mirror.property(2).value().value()); | 226 assertEquals('c', mirror.property(2).value().value()); |
OLD | NEW |