OLD | NEW |
1 // Copyright 2012 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 |
(...skipping 22 matching lines...) Expand all Loading... |
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 isName(val) { |
| 44 return typeof val === 'string' || typeof val === 'symbol'; |
| 45 } |
| 46 |
43 function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { | 47 function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) { |
44 // Create mirror and JSON representation. | 48 // Create mirror and JSON representation. |
45 var mirror = debug.MakeMirror(obj); | 49 var mirror = debug.MakeMirror(obj); |
46 var serializer = debug.MakeMirrorSerializer(); | 50 var serializer = debug.MakeMirrorSerializer(); |
47 var json = JSON.stringify(serializer.serializeValue(mirror)); | 51 var json = JSON.stringify(serializer.serializeValue(mirror)); |
48 var refs = new MirrorRefCache( | 52 var refs = new MirrorRefCache( |
49 JSON.stringify(serializer.serializeReferencedObjects())); | 53 JSON.stringify(serializer.serializeReferencedObjects())); |
50 | 54 |
51 // Check the mirror hierachy. | 55 // Check the mirror hierachy. |
52 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierarchy'); | 56 assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierarchy'); |
(...skipping 12 matching lines...) Expand all Loading... |
65 assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected'); | 69 assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected'); |
66 assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected')
; | 70 assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected')
; |
67 | 71 |
68 var names = mirror.propertyNames(); | 72 var names = mirror.propertyNames(); |
69 var properties = mirror.properties(); | 73 var properties = mirror.properties(); |
70 assertEquals(names.length, properties.length); | 74 assertEquals(names.length, properties.length); |
71 for (var i = 0; i < properties.length; i++) { | 75 for (var i = 0; i < properties.length; i++) { |
72 assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierarc
hy'); | 76 assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierarc
hy'); |
73 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror
hierarchy'); | 77 assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror
hierarchy'); |
74 assertEquals('property', properties[i].type(), 'Unexpected mirror type'); | 78 assertEquals('property', properties[i].type(), 'Unexpected mirror type'); |
| 79 assertTrue(isName(names[i]), "Expected string or symbol property name"); |
75 assertEquals(names[i], properties[i].name(), 'Unexpected property name'); | 80 assertEquals(names[i], properties[i].name(), 'Unexpected property name'); |
76 } | 81 } |
77 | 82 |
78 var internalProperties = mirror.internalProperties(); | 83 var internalProperties = mirror.internalProperties(); |
79 for (var i = 0; i < internalProperties.length; i++) { | 84 for (var i = 0; i < internalProperties.length; i++) { |
80 assertTrue(internalProperties[i] instanceof debug.Mirror, 'Unexpected mirror
hierarchy'); | 85 assertTrue(internalProperties[i] instanceof debug.Mirror, 'Unexpected mirror
hierarchy'); |
81 assertTrue(internalProperties[i] instanceof debug.InternalPropertyMirror, 'U
nexpected mirror hierarchy'); | 86 assertTrue(internalProperties[i] instanceof debug.InternalPropertyMirror, 'U
nexpected mirror hierarchy'); |
82 assertEquals('internalProperty', internalProperties[i].type(), 'Unexpected m
irror type'); | 87 assertEquals('internalProperty', internalProperties[i].type(), 'Unexpected m
irror type'); |
83 } | 88 } |
84 | 89 |
(...skipping 19 matching lines...) Expand all Loading... |
104 assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'U
nexpected constructor function name in JSON'); | 109 assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'U
nexpected constructor function name in JSON'); |
105 assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpec
ted proto object handle in JSON'); | 110 assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpec
ted proto object handle in JSON'); |
106 assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref
).type, 'Unexpected proto object type in JSON'); | 111 assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref
).type, 'Unexpected proto object type in JSON'); |
107 assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref,
'Unexpected prototype object handle in JSON'); | 112 assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref,
'Unexpected prototype object handle in JSON'); |
108 assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeOb
ject.ref).type, 'Unexpected prototype object type in JSON'); | 113 assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeOb
ject.ref).type, 'Unexpected prototype object type in JSON'); |
109 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected
in JSON'); | 114 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected
in JSON'); |
110 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe
cted in JSON'); | 115 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe
cted in JSON'); |
111 | 116 |
112 // Check that the serialization contains all properties. | 117 // Check that the serialization contains all properties. |
113 assertEquals(names.length, fromJSON.properties.length, 'Some properties missin
g in JSON'); | 118 assertEquals(names.length, fromJSON.properties.length, 'Some properties missin
g in JSON'); |
114 for (var i = 0; i < fromJSON.properties.length; i++) { | 119 for (var j = 0; j < names.length; j++) { |
115 var name = fromJSON.properties[i].name; | 120 var name = names[j]; |
116 if (typeof name == 'undefined') name = fromJSON.properties[i].index; | 121 // Serialization of symbol-named properties to JSON doesn't really |
| 122 // work currently, as they don't get a {name: ...} entry. |
| 123 if (typeof name === 'symbol') continue; |
117 var found = false; | 124 var found = false; |
118 for (var j = 0; j < names.length; j++) { | 125 for (var i = 0; i < fromJSON.properties.length; i++) { |
119 if (names[j] == name) { | 126 if (fromJSON.properties[i].name == name) { |
120 // Check that serialized handle is correct. | 127 // Check that serialized handle is correct. |
121 assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref,
'Unexpected serialized handle'); | 128 assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref,
'Unexpected serialized handle'); |
122 | 129 |
123 // Check that serialized name is correct. | 130 // Check that serialized name is correct. |
124 assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpec
ted serialized name'); | 131 assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpec
ted serialized name'); |
125 | 132 |
126 // If property type is normal property type is not serialized. | 133 // If property type is normal property type is not serialized. |
127 if (properties[i].propertyType() != debug.PropertyType.Normal) { | 134 if (properties[i].propertyType() != debug.PropertyType.Normal) { |
128 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop
ertyType, 'Unexpected serialized property type'); | 135 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop
ertyType, 'Unexpected serialized property type'); |
129 } else { | 136 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 assertTrue(found, '"' + name + '" not found (' + json + ')'); | 170 assertTrue(found, '"' + name + '" not found (' + json + ')'); |
164 } | 171 } |
165 } | 172 } |
166 | 173 |
167 | 174 |
168 function Point(x,y) { | 175 function Point(x,y) { |
169 this.x_ = x; | 176 this.x_ = x; |
170 this.y_ = y; | 177 this.y_ = y; |
171 } | 178 } |
172 | 179 |
| 180 var object_with_symbol = {}; |
| 181 object_with_symbol[Symbol.iterator] = 42; |
| 182 |
173 // Test a number of different objects. | 183 // Test a number of different objects. |
174 testObjectMirror({}, 'Object', 'Object'); | 184 testObjectMirror({}, 'Object', 'Object'); |
175 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); | 185 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); |
176 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y)
;}}, 'Object', 'Object'); | 186 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y)
;}}, 'Object', 'Object'); |
177 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); | 187 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); |
178 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties | 188 testObjectMirror(this, 'global', '', true); // Global object has special proper
ties |
179 testObjectMirror(this.__proto__, 'Object', ''); | 189 testObjectMirror(this.__proto__, 'Object', ''); |
180 testObjectMirror([], 'Array', 'Array'); | 190 testObjectMirror([], 'Array', 'Array'); |
181 testObjectMirror([1,2], 'Array', 'Array'); | 191 testObjectMirror([1,2], 'Array', 'Array'); |
182 testObjectMirror(Object(17), 'Number', 'Number'); | 192 testObjectMirror(Object(17), 'Number', 'Number'); |
| 193 testObjectMirror(object_with_symbol, 'Object', 'Object'); |
183 | 194 |
184 // Test circular references. | 195 // Test circular references. |
185 o = {}; | 196 o = {}; |
186 o.o = o; | 197 o.o = o; |
187 testObjectMirror(o, 'Object', 'Object'); | 198 testObjectMirror(o, 'Object', 'Object'); |
188 | 199 |
189 // Test that non enumerable properties are part of the mirror | 200 // Test that non enumerable properties are part of the mirror |
190 global_mirror = debug.MakeMirror(this); | 201 global_mirror = debug.MakeMirror(this); |
191 assertEquals('property', global_mirror.property("Math").type()); | 202 assertEquals('property', global_mirror.property("Math").type()); |
192 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob
al_mirror.property("Math").attributes()); | 203 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob
al_mirror.property("Math").attributes()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 268 } |
258 assertTrue("[[BoundThis]]" in property_map); | 269 assertTrue("[[BoundThis]]" in property_map); |
259 assertEquals("function", property_map["[[BoundThis]]"].value().type()); | 270 assertEquals("function", property_map["[[BoundThis]]"].value().type()); |
260 assertEquals(Array, property_map["[[BoundThis]]"].value().value()); | 271 assertEquals(Array, property_map["[[BoundThis]]"].value().value()); |
261 assertTrue("[[TargetFunction]]" in property_map); | 272 assertTrue("[[TargetFunction]]" in property_map); |
262 assertEquals("function", property_map["[[TargetFunction]]"].value().type()); | 273 assertEquals("function", property_map["[[TargetFunction]]"].value().type()); |
263 assertEquals(Number, property_map["[[TargetFunction]]"].value().value()); | 274 assertEquals(Number, property_map["[[TargetFunction]]"].value().value()); |
264 assertTrue("[[BoundArgs]]" in property_map); | 275 assertTrue("[[BoundArgs]]" in property_map); |
265 assertEquals("object", property_map["[[BoundArgs]]"].value().type()); | 276 assertEquals("object", property_map["[[BoundArgs]]"].value().type()); |
266 assertEquals(1, property_map["[[BoundArgs]]"].value().value().length); | 277 assertEquals(1, property_map["[[BoundArgs]]"].value().value().length); |
OLD | NEW |