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

Side by Side Diff: test/mjsunit/mirror-array.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/debug-backtrace.js ('k') | test/mjsunit/mirror-boolean.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 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
31 function testArrayMirror(a, names) { 43 function testArrayMirror(a, names) {
32 // Create mirror and JSON representation. 44 // Create mirror and JSON representation.
33 var mirror = debug.MakeMirror(a); 45 var mirror = debug.MakeMirror(a);
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 assertTrue(mirror instanceof debug.ArrayMirror); 54 assertTrue(mirror instanceof debug.ArrayMirror, 'Unexpected mirror hierachy');
41 55
42 // Check the mirror properties. 56 // Check the mirror properties.
43 assertTrue(mirror.isArray()); 57 assertTrue(mirror.isArray(), 'Unexpected mirror');
44 assertEquals('object', mirror.type()); 58 assertEquals('object', mirror.type(), 'Unexpected mirror type');
45 assertFalse(mirror.isPrimitive()); 59 assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
46 assertEquals('Array', mirror.className()); 60 assertEquals('Array', mirror.className(), 'Unexpected mirror class name');
47 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); 61 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpe cted mirror hierachy');
48 assertTrue(mirror.protoObject() instanceof debug.Mirror); 62 assertEquals('Array', mirror.constructorFunction().name(), 'Unexpected constru ctor function name');
49 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); 63 assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hi erachy');
64 assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirro r hierachy');
50 assertEquals(mirror.length(), a.length, "Length mismatch"); 65 assertEquals(mirror.length(), a.length, "Length mismatch");
51 66
52 var indexedValueMirrors = mirror.indexedPropertiesFromRange(); 67 var indexedProperties = mirror.indexedPropertiesFromRange();
53 assertEquals(indexedValueMirrors.length, a.length); 68 assertEquals(indexedProperties.length, a.length);
54 for (var i = 0; i < indexedValueMirrors.length; i++) { 69 for (var i = 0; i < indexedProperties.length; i++) {
55 assertTrue(indexedValueMirrors[i] instanceof debug.Mirror); 70 assertTrue(indexedProperties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
56 if (a[i]) { 71 assertTrue(indexedProperties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
57 assertTrue(indexedValueMirrors[i] instanceof debug.PropertyMirror);
58 }
59 } 72 }
60 73
61 // Parse JSON representation and check. 74 // Parse JSON representation and check.
62 var fromJSON = eval('(' + json + ')'); 75 var fromJSON = eval('(' + json + ')');
63 assertEquals('object', fromJSON.type); 76 assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
64 assertEquals('Array', fromJSON.className); 77 assertEquals('Array', fromJSON.className, 'Unexpected mirror class name in JSO N');
65 assertEquals('function', fromJSON.constructorFunction.type); 78 assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFuncti on.ref, 'Unexpected constructor function handle in JSON');
66 assertEquals('Array', fromJSON.constructorFunction.name); 79 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, ' Unexpected constructor function type in JSON');
67 assertEquals(a.length, fromJSON.length, "Length mismatch in parsed JSON"); 80 assertEquals('Array', refs.lookup(fromJSON.constructorFunction.ref).name, 'Une xpected constructor function name in JSON');
81 assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
82 assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expe cted in JSON');
68 83
69 // Check that the serialization contains all indexed properties. 84 // Check that the serialization contains all indexed properties and the length property.
70 for (var i = 0; i < fromJSON.indexedProperties.length; i++) { 85 var length_found = false;
71 var index = fromJSON.indexedProperties[i].name; 86 for (var i = 0; i < fromJSON.properties.length; i++) {
72 assertEquals(indexedValueMirrors[index].name(), index); 87 if (fromJSON.properties[i].name == 'length') {
73 assertEquals(indexedValueMirrors[index].value().type(), fromJSON.indexedProp erties[i].value.type, index); 88 length_found = true;
89 assertEquals('number', refs.lookup(fromJSON.properties[i].ref).type, "Unex pected type of the length property");
90 assertEquals(a.length, refs.lookup(fromJSON.properties[i].ref).value, "Len gth mismatch in parsed JSON");
91 } else {
92 var index = parseInt(fromJSON.properties[i].name);
93 print(index);
94 if (!isNaN(index)) {
95 print(index);
96 // This test assumes that the order of the indexeed properties is in the
97 // same order in the serialization as returned from
98 // indexedPropertiesFromRange()
99 assertEquals(indexedProperties[index].name(), index);
100 assertEquals(indexedProperties[index].value().type(), refs.lookup(fromJS ON.properties[i].ref).type, 'Unexpected serialized type');
101 }
102 }
74 } 103 }
104 assertTrue(length_found, 'Property length not found');
75 105
76 // Check that the serialization contains all names properties. 106 // Check that the serialization contains all names properties.
77 if (names) { 107 if (names) {
78 for (var i = 0; i < names.length; i++) { 108 for (var i = 0; i < names.length; i++) {
79 var found = false; 109 var found = false;
80 for (var j = 0; j < fromJSON.properties.length; j++) { 110 for (var j = 0; j < fromJSON.properties.length; j++) {
81 if (names[i] == fromJSON.properties[j].name) { 111 if (names[i] == fromJSON.properties[j].name) {
82 found = true; 112 found = true;
83 } 113 }
84 } 114 }
85 assertTrue(found, names[i]) 115 assertTrue(found, names[i])
86 } 116 }
87 } else {
88 assertEquals(1, fromJSON.properties.length)
89 } 117 }
90 } 118 }
91 119
92 120
93 // Test a number of different arrays. 121 // Test a number of different arrays.
94 testArrayMirror([]); 122 testArrayMirror([]);
95 testArrayMirror([1]); 123 testArrayMirror([1]);
96 testArrayMirror([1,2]); 124 testArrayMirror([1,2]);
97 testArrayMirror(["a", function(){}, [1,2], 2, /[ab]/]); 125 testArrayMirror(["a", function(){}, [1,2], 2, /[ab]/]);
98 126
99 a=[1]; 127 a=[1];
100 a[100]=7; 128 a[100]=7;
101 testArrayMirror(a); 129 testArrayMirror(a);
102 130
103 a=[1,2,3]; 131 a=[1,2,3];
104 a.x=2.2; 132 a.x=2.2;
105 a.y=function(){return null;} 133 a.y=function(){return null;}
106 testArrayMirror(a, ['x','y']); 134 testArrayMirror(a, ['x','y']);
107 135
108 var a = []; a.push(a); 136 var a = []; a.push(a);
109 testArrayMirror(a); 137 testArrayMirror(a);
OLDNEW
« no previous file with comments | « test/mjsunit/debug-backtrace.js ('k') | test/mjsunit/mirror-boolean.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698