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 26 matching lines...) Expand all Loading... |
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 = serializer.serializeValue(mirror); | 47 var json = JSON.stringify(serializer.serializeValue(mirror)); |
48 var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); | 48 var refs = new MirrorRefCache( |
| 49 JSON.stringify(serializer.serializeReferencedObjects())); |
49 | 50 |
50 // Check the mirror hierachy. | 51 // Check the mirror hierachy. |
51 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy'); | 52 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy'); |
52 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy'); | 53 assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy'); |
53 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy')
; | 54 assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy')
; |
54 | 55 |
55 // Check the mirror properties. | 56 // Check the mirror properties. |
56 assertTrue(mirror.isObject(), 'Unexpected mirror'); | 57 assertTrue(mirror.isObject(), 'Unexpected mirror'); |
57 assertEquals('object', mirror.type(), 'Unexpected mirror type'); | 58 assertEquals('object', mirror.type(), 'Unexpected mirror type'); |
58 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror'); | 59 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror'); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref
).type, 'Unexpected proto object type in JSON'); | 99 assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref
).type, 'Unexpected proto object type in JSON'); |
99 assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref,
'Unexpected prototype object handle in JSON'); | 100 assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref,
'Unexpected prototype object handle in JSON'); |
100 assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeOb
ject.ref).type, 'Unexpected prototype object type in JSON'); | 101 assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeOb
ject.ref).type, 'Unexpected prototype object type in JSON'); |
101 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected
in JSON'); | 102 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected
in JSON'); |
102 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe
cted in JSON'); | 103 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe
cted in JSON'); |
103 | 104 |
104 // Check that the serialization contains all properties. | 105 // Check that the serialization contains all properties. |
105 assertEquals(names.length, fromJSON.properties.length, 'Some properties missin
g in JSON'); | 106 assertEquals(names.length, fromJSON.properties.length, 'Some properties missin
g in JSON'); |
106 for (var i = 0; i < fromJSON.properties.length; i++) { | 107 for (var i = 0; i < fromJSON.properties.length; i++) { |
107 var name = fromJSON.properties[i].name; | 108 var name = fromJSON.properties[i].name; |
108 if (!name) name = fromJSON.properties[i].index; | 109 if (typeof name == 'undefined') name = fromJSON.properties[i].index; |
109 var found = false; | 110 var found = false; |
110 for (var j = 0; j < names.length; j++) { | 111 for (var j = 0; j < names.length; j++) { |
111 if (names[j] == name) { | 112 if (names[j] == name) { |
112 // Check that serialized handle is correct. | 113 // Check that serialized handle is correct. |
113 assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref,
'Unexpected serialized handle'); | 114 assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref,
'Unexpected serialized handle'); |
114 | 115 |
115 // Check that serialized name is correct. | 116 // Check that serialized name is correct. |
116 assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpec
ted serialized name'); | 117 assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpec
ted serialized name'); |
117 | 118 |
118 // If property type is normal property type is not serialized. | 119 // If property type is normal property type is not serialized. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 assertTrue(found, '"' + name + '" not found (' + json + ')'); | 151 assertTrue(found, '"' + name + '" not found (' + json + ')'); |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 | 155 |
155 function Point(x,y) { | 156 function Point(x,y) { |
156 this.x_ = x; | 157 this.x_ = x; |
157 this.y_ = y; | 158 this.y_ = y; |
158 } | 159 } |
159 | 160 |
160 | |
161 // Test a number of different objects. | 161 // Test a number of different objects. |
162 testObjectMirror({}, 'Object', 'Object'); | 162 testObjectMirror({}, 'Object', 'Object'); |
163 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); | 163 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'); | 164 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'); | 165 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); |
166 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties | 166 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties |
167 testObjectMirror(this.__proto__, 'Object', ''); | 167 testObjectMirror(this.__proto__, 'Object', ''); |
168 testObjectMirror([], 'Array', 'Array'); | 168 testObjectMirror([], 'Array', 'Array'); |
169 testObjectMirror([1,2], 'Array', 'Array'); | 169 testObjectMirror([1,2], 'Array', 'Array'); |
170 | 170 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 // Test objects with native accessors. | 219 // Test objects with native accessors. |
220 mirror = debug.MakeMirror(new String('abc')); | 220 mirror = debug.MakeMirror(new String('abc')); |
221 assertTrue(mirror instanceof debug.ObjectMirror); | 221 assertTrue(mirror instanceof debug.ObjectMirror); |
222 assertFalse(mirror.property('length').hasGetter()); | 222 assertFalse(mirror.property('length').hasGetter()); |
223 assertFalse(mirror.property('length').hasSetter()); | 223 assertFalse(mirror.property('length').hasSetter()); |
224 assertTrue(mirror.property('length').isNative()); | 224 assertTrue(mirror.property('length').isNative()); |
225 assertEquals('a', mirror.property(0).value().value()); | 225 assertEquals('a', mirror.property(0).value().value()); |
226 assertEquals('b', mirror.property(1).value().value()); | 226 assertEquals('b', mirror.property(1).value().value()); |
227 assertEquals('c', mirror.property(2).value().value()); | 227 assertEquals('c', mirror.property(2).value().value()); |
OLD | NEW |