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 assertFalse("value" in o, 'Unexpected value property for ' + name); |
| 143 } else if (properties[i].value().type() == "number" && |
| 144 !isFinite(properties[i].value().value())) { |
| 145 assertEquals(String(properties[i].value().value()), o.value, |
| 146 'Unexpected serialized property value for ' + name); |
142 } else { | 147 } else { |
143 assertEquals(properties[i].value().value(), o.value, 'Unexpected ser
ialized property value for ' + name); | 148 assertEquals(properties[i].value().value(), o.value, 'Unexpected ser
ialized property value for ' + name); |
144 } | 149 } |
145 } else if (properties[i].value().isFunction()) { | 150 } else if (properties[i].value().isFunction()) { |
146 assertEquals(properties[i].value().source(), o.source, 'Unexpected ser
ialized property value for ' + name); | 151 assertEquals(properties[i].value().source(), o.source, 'Unexpected ser
ialized property value for ' + name); |
147 } | 152 } |
148 found = true; | 153 found = true; |
149 } | 154 } |
150 } | 155 } |
151 assertTrue(found, '"' + name + '" not found (' + json + ')'); | 156 assertTrue(found, '"' + name + '" not found (' + json + ')'); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 223 |
219 // Test objects with native accessors. | 224 // Test objects with native accessors. |
220 mirror = debug.MakeMirror(new String('abc')); | 225 mirror = debug.MakeMirror(new String('abc')); |
221 assertTrue(mirror instanceof debug.ObjectMirror); | 226 assertTrue(mirror instanceof debug.ObjectMirror); |
222 assertFalse(mirror.property('length').hasGetter()); | 227 assertFalse(mirror.property('length').hasGetter()); |
223 assertFalse(mirror.property('length').hasSetter()); | 228 assertFalse(mirror.property('length').hasSetter()); |
224 assertTrue(mirror.property('length').isNative()); | 229 assertTrue(mirror.property('length').isNative()); |
225 assertEquals('a', mirror.property(0).value().value()); | 230 assertEquals('a', mirror.property(0).value().value()); |
226 assertEquals('b', mirror.property(1).value().value()); | 231 assertEquals('b', mirror.property(1).value().value()); |
227 assertEquals('c', mirror.property(2).value().value()); | 232 assertEquals('c', mirror.property(2).value().value()); |
OLD | NEW |