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

Side by Side Diff: test/mjsunit/mirror-object.js

Issue 18096: Experimental: merge from bleeding_edge. Merge up to and including... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
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/mirror-function.js ('k') | test/mjsunit/mirror-string.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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop ertyType); 100 assertEquals(properties[i].propertyType(), fromJSON.properties[i].prop ertyType);
101 } else { 101 } else {
102 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' ); 102 assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined' );
103 } 103 }
104 // If there are no attributes nothing is serialized. 104 // If there are no attributes nothing is serialized.
105 if (properties[i].attributes() != debug.PropertyAttribute.None) { 105 if (properties[i].attributes() != debug.PropertyAttribute.None) {
106 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes); 106 assertEquals(properties[i].attributes(), fromJSON.properties[i].attrib utes);
107 } else { 107 } else {
108 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined'); 108 assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined');
109 } 109 }
110 if (!properties[i].value() instanceof debug.AccessorMirror && 110 if (!properties[i].value().isPrimitive()) {
111 properties[i].value().isPrimitive()) {
112 // NaN is not equal to NaN. 111 // NaN is not equal to NaN.
113 if (isNaN(properties[i].value().value())) { 112 if (isNaN(properties[i].value().value())) {
114 assertTrue(isNaN(fromJSON.properties[i].value.value)); 113 assertTrue(isNaN(fromJSON.properties[i].value.value));
115 } else { 114 } else {
116 assertEquals(properties[i].value().value(), fromJSON.properties[i].v alue.value); 115 assertEquals(properties[i].value().value(), fromJSON.properties[i].v alue.value);
117 } 116 }
118 } 117 }
119 found = true; 118 found = true;
120 } 119 }
121 } 120 }
122 assertTrue(found, '"' + name + '" not found'); 121 assertTrue(found, '"' + name + '" not found (' + json + ')');
123 } 122 }
124 } 123 }
125 124
126 125
127 function Point(x,y) { 126 function Point(x,y) {
128 this.x_ = x; 127 this.x_ = x;
129 this.y_ = y; 128 this.y_ = y;
130 } 129 }
131 130
132 131
133 // Test a number of different objects. 132 // Test a number of different objects.
134 testObjectMirror({}, 'Object', 'Object'); 133 testObjectMirror({}, 'Object', 'Object');
135 testObjectMirror({'a':1,'b':2}, 'Object', 'Object'); 134 testObjectMirror({'a':1,'b':2}, 'Object', 'Object');
136 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object'); 135 testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y) ;}}, 'Object', 'Object');
137 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point'); 136 testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');
138 testObjectMirror(this, 'global', undefined, true); // Global object has special properties 137 testObjectMirror(this, 'global', undefined, true); // Global object has special properties
139 testObjectMirror([], 'Array', 'Array'); 138 testObjectMirror([], 'Array', 'Array');
140 testObjectMirror([1,2], 'Array', 'Array'); 139 testObjectMirror([1,2], 'Array', 'Array');
141 140
141 // Test circular references.
142 o = {};
143 o.o = o;
144 testObjectMirror(o, 'Object', 'Object');
145
142 // Test that non enumerable properties are part of the mirror 146 // Test that non enumerable properties are part of the mirror
143 global_mirror = debug.MakeMirror(this); 147 global_mirror = debug.MakeMirror(this);
144 assertEquals('property', global_mirror.property("Math").type()); 148 assertEquals('property', global_mirror.property("Math").type());
145 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob al_mirror.property("Math").attributes()); 149 assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + glob al_mirror.property("Math").attributes());
146 150
147 math_mirror = global_mirror.property("Math").value(); 151 math_mirror = global_mirror.property("Math").value();
148 assertEquals('property', math_mirror.property("E").type()); 152 assertEquals('property', math_mirror.property("E").type());
149 assertFalse(math_mirror.property("E").isEnum(), "Math.E is enumerable"); 153 assertFalse(math_mirror.property("E").isEnum(), "Math.E is enumerable");
150 assertTrue(math_mirror.property("E").isReadOnly()); 154 assertTrue(math_mirror.property("E").isReadOnly());
151 assertFalse(math_mirror.property("E").canDelete()); 155 assertFalse(math_mirror.property("E").canDelete());
152 156
153 // Test objects with JavaScript accessors. 157 // Test objects with JavaScript accessors.
154 o = {} 158 o = {}
155 o.__defineGetter__('a', function(){throw 'a';}) 159 o.__defineGetter__('a', function(){return 'a';});
156 o.__defineSetter__('b', function(){throw 'b';}) 160 o.__defineSetter__('b', function(){});
157 o.__defineGetter__('c', function(){throw 'c';}) 161 o.__defineGetter__('c', function(){throw 'c';});
158 o.__defineSetter__('c', function(){throw 'c';}) 162 o.__defineSetter__('c', function(){throw 'c';});
159 testObjectMirror(o, 'Object', 'Object'); 163 testObjectMirror(o, 'Object', 'Object');
160 mirror = debug.MakeMirror(o); 164 mirror = debug.MakeMirror(o);
161 // a has getter but no setter. 165 // a has getter but no setter.
162 assertTrue(mirror.property('a').value() instanceof debug.AccessorMirror); 166 assertTrue(mirror.property('a').hasGetter());
167 assertFalse(mirror.property('a').hasSetter());
163 assertEquals(debug.PropertyType.Callbacks, mirror.property('a').propertyType()); 168 assertEquals(debug.PropertyType.Callbacks, mirror.property('a').propertyType());
169 assertEquals('function', mirror.property('a').getter().type());
170 assertEquals('undefined', mirror.property('a').setter().type());
171 assertEquals('function (){return \'a\';}', mirror.property('a').getter().source( ));
172 assertEquals('a', mirror.property('a').value().value());
173 assertFalse(mirror.property('a').isException());
164 // b has setter but no getter. 174 // b has setter but no getter.
165 assertTrue(mirror.property('b').value() instanceof debug.AccessorMirror); 175 assertFalse(mirror.property('b').hasGetter());
176 assertTrue(mirror.property('b').hasSetter());
166 assertEquals(debug.PropertyType.Callbacks, mirror.property('b').propertyType()); 177 assertEquals(debug.PropertyType.Callbacks, mirror.property('b').propertyType());
167 // c has both getter and setter. 178 assertEquals('undefined', mirror.property('b').getter().type());
168 assertTrue(mirror.property('c').value() instanceof debug.AccessorMirror); 179 assertEquals('function', mirror.property('b').setter().type());
180 assertEquals('function (){}', mirror.property('b').setter().source());
181 assertFalse(mirror.property('b').isException());
182 // c has both getter and setter. The getter throws an exception.
183 assertTrue(mirror.property('c').hasGetter());
184 assertTrue(mirror.property('c').hasSetter());
169 assertEquals(debug.PropertyType.Callbacks, mirror.property('c').propertyType()); 185 assertEquals(debug.PropertyType.Callbacks, mirror.property('c').propertyType());
186 assertEquals('function', mirror.property('c').getter().type());
187 assertEquals('function', mirror.property('c').setter().type());
188 assertEquals('function (){throw \'c\';}', mirror.property('c').getter().source() );
189 assertEquals('function (){throw \'c\';}', mirror.property('c').setter().source() );
190 assertEquals('c', mirror.property('c').value().value());
191 assertTrue(mirror.property('c').isException());
170 192
171 // Test objects with native accessors. 193 // Test objects with native accessors.
172 mirror = debug.MakeMirror(new String('abc')); 194 mirror = debug.MakeMirror(new String('abc'));
173 assertTrue(mirror instanceof debug.ObjectMirror); 195 assertTrue(mirror instanceof debug.ObjectMirror);
174 assertTrue(mirror.property('length').value() instanceof debug.AccessorMirror); 196 assertFalse(mirror.property('length').hasGetter());
175 assertTrue(mirror.property('length').value().isNative()); 197 assertFalse(mirror.property('length').hasSetter());
198 assertTrue(mirror.property('length').isNative());
176 assertEquals('a', mirror.property(0).value().value()); 199 assertEquals('a', mirror.property(0).value().value());
177 assertEquals('b', mirror.property(1).value().value()); 200 assertEquals('b', mirror.property(1).value().value());
178 assertEquals('c', mirror.property(2).value().value()); 201 assertEquals('c', mirror.property(2).value().value());
OLDNEW
« no previous file with comments | « test/mjsunit/mirror-function.js ('k') | test/mjsunit/mirror-string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698