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

Side by Side Diff: test/mjsunit/harmony/object-observe.js

Issue 11369154: Implement Object.getNotifier() and remove Object.notify() (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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
« src/object-observe.js ('K') | « test/cctest/test-object-observe.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 }) 94 })
95 95
96 // Object.observe 96 // Object.observe
97 assertThrows(function() { Object.observe("non-object", observer.callback); }, Ty peError); 97 assertThrows(function() { Object.observe("non-object", observer.callback); }, Ty peError);
98 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); 98 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError);
99 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); 99 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError);
100 100
101 // Object.unobserve 101 // Object.unobserve
102 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError); 102 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError);
103 103
104 // Object.notify 104 // Object.getNotifier
105 assertThrows(function() { Object.notify(obj, {}); }, TypeError); 105 var notifier = Object.getNotifier(obj);
106 assertThrows(function() { Object.notify(obj, { type: 4 }); }, TypeError); 106 assertSame(notifier, Object.getNotifier(obj));
107 assertEquals(null, Object.getNotifier(Object.freeze({})));
108 assertFalse(notifier.hasOwnProperty('notify'));
109 assertEquals([], Object.keys(notifier));
110 var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify');
111 assertTrue(notifyDesc.configurable);
112 assertTrue(notifyDesc.writable);
113 assertFalse(notifyDesc.enumerable);
114 assertThrows(function() { notifier.notify({}); }, TypeError);
115 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError);
116 assertThrows(function() {
117 notifier.notify.call(undefined, { type: 'a' });
118 }, TypeError);
119 assertThrows(function() {
120 notifier.notify.call(null, { type: 'a' });
121 }, TypeError);
rossberg 2012/11/09 14:41:25 Also: notifier.notify.call({}, { type: 'a' }) Doe
adamk 2012/11/09 14:48:41 Added a test for this below
107 assertFalse(recordCreated); 122 assertFalse(recordCreated);
108 Object.notify(obj, changeRecordWithAccessor); 123 notifier.notify(changeRecordWithAccessor);
109 assertFalse(recordCreated); 124 assertFalse(recordCreated); // not observed yet
rossberg 2012/11/09 14:41:25 Nit: 2 spaces before //
adamk 2012/11/09 14:48:41 Damn, WebKit vs google3 style getting me in troubl
110 125
111 // Object.deliverChangeRecords 126 // Object.deliverChangeRecords
112 assertThrows(function() { Object.deliverChangeRecords(nonFunction); }, TypeError ); 127 assertThrows(function() { Object.deliverChangeRecords(nonFunction); }, TypeError );
113 128
114 // Multiple records are delivered. 129 // Multiple records are delivered.
115 Object.observe(obj, observer.callback); 130 Object.observe(obj, observer.callback);
116 Object.notify(obj, { 131 notifier.notify({
117 object: obj,
118 type: 'updated', 132 type: 'updated',
119 name: 'foo', 133 name: 'foo',
120 expando: 1 134 expando: 1
121 }); 135 });
122 136
123 Object.notify(obj, { 137 notifier.notify({
124 object: obj, 138 object: notifier, // object property is ignored
rossberg 2012/11/09 14:41:25 dito
adamk 2012/11/09 14:48:41 Done.
125 type: 'deleted', 139 type: 'deleted',
126 name: 'bar', 140 name: 'bar',
127 expando2: 'str' 141 expando2: 'str'
128 }); 142 });
129 Object.deliverChangeRecords(observer.callback); 143 Object.deliverChangeRecords(observer.callback);
130 observer.assertCallbackRecords([ 144 observer.assertCallbackRecords([
131 { object: obj, name: 'foo', type: 'updated', expando: 1 }, 145 { object: obj, name: 'foo', type: 'updated', expando: 1 },
132 { object: obj, name: 'bar', type: 'deleted', expando2: 'str' } 146 { object: obj, name: 'bar', type: 'deleted', expando2: 'str' }
133 ]); 147 ]);
134 148
135 // No delivery takes place if no records are pending 149 // No delivery takes place if no records are pending
136 reset(); 150 reset();
137 Object.deliverChangeRecords(observer.callback); 151 Object.deliverChangeRecords(observer.callback);
138 observer.assertNotCalled(); 152 observer.assertNotCalled();
139 153
140 // Multiple observation has no effect. 154 // Multiple observation has no effect.
141 reset(); 155 reset();
142 Object.observe(obj, observer.callback); 156 Object.observe(obj, observer.callback);
143 Object.observe(obj, observer.callback); 157 Object.observe(obj, observer.callback);
144 Object.notify(obj, { 158 Object.getNotifier(obj).notify({
145 type: 'foo', 159 type: 'foo',
146 }); 160 });
147 Object.deliverChangeRecords(observer.callback); 161 Object.deliverChangeRecords(observer.callback);
148 observer.assertCalled(); 162 observer.assertCalled();
149 163
150 // Observation can be stopped. 164 // Observation can be stopped.
151 reset(); 165 reset();
152 Object.unobserve(obj, observer.callback); 166 Object.unobserve(obj, observer.callback);
153 Object.notify(obj, { 167 Object.getNotifier(obj).notify({
154 type: 'foo', 168 type: 'foo',
155 }); 169 });
156 Object.deliverChangeRecords(observer.callback); 170 Object.deliverChangeRecords(observer.callback);
157 observer.assertNotCalled(); 171 observer.assertNotCalled();
158 172
159 // Multiple unobservation has no effect 173 // Multiple unobservation has no effect
160 reset(); 174 reset();
161 Object.unobserve(obj, observer.callback); 175 Object.unobserve(obj, observer.callback);
162 Object.unobserve(obj, observer.callback); 176 Object.unobserve(obj, observer.callback);
163 Object.notify(obj, { 177 Object.getNotifier(obj).notify({
164 type: 'foo', 178 type: 'foo',
165 }); 179 });
166 Object.deliverChangeRecords(observer.callback); 180 Object.deliverChangeRecords(observer.callback);
167 observer.assertNotCalled(); 181 observer.assertNotCalled();
168 182
169 // Re-observation works and only includes changeRecords after of call. 183 // Re-observation works and only includes changeRecords after of call.
170 reset(); 184 reset();
171 Object.notify(obj, { 185 Object.getNotifier(obj).notify({
172 type: 'foo', 186 type: 'foo',
173 }); 187 });
174 Object.observe(obj, observer.callback); 188 Object.observe(obj, observer.callback);
175 Object.notify(obj, { 189 Object.getNotifier(obj).notify({
176 type: 'foo', 190 type: 'foo',
177 }); 191 });
178 records = undefined; 192 records = undefined;
179 Object.deliverChangeRecords(observer.callback); 193 Object.deliverChangeRecords(observer.callback);
180 observer.assertRecordCount(1); 194 observer.assertRecordCount(1);
181 195
182 // Observing a continuous stream of changes, while itermittantly unobserving. 196 // Observing a continuous stream of changes, while itermittantly unobserving.
183 reset(); 197 reset();
184 Object.observe(obj, observer.callback); 198 Object.observe(obj, observer.callback);
185 Object.notify(obj, { 199 Object.getNotifier(obj).notify({
186 type: 'foo', 200 type: 'foo',
187 val: 1 201 val: 1
188 }); 202 });
189 203
190 Object.unobserve(obj, observer.callback); 204 Object.unobserve(obj, observer.callback);
191 Object.notify(obj, { 205 Object.getNotifier(obj).notify({
192 type: 'foo', 206 type: 'foo',
193 val: 2 207 val: 2
194 }); 208 });
195 209
196 Object.observe(obj, observer.callback); 210 Object.observe(obj, observer.callback);
197 Object.notify(obj, { 211 Object.getNotifier(obj).notify({
198 type: 'foo', 212 type: 'foo',
199 val: 3 213 val: 3
200 }); 214 });
201 215
202 Object.unobserve(obj, observer.callback); 216 Object.unobserve(obj, observer.callback);
203 Object.notify(obj, { 217 Object.getNotifier(obj).notify({
204 type: 'foo', 218 type: 'foo',
205 val: 4 219 val: 4
206 }); 220 });
207 221
208 Object.observe(obj, observer.callback); 222 Object.observe(obj, observer.callback);
209 Object.notify(obj, { 223 Object.getNotifier(obj).notify({
210 type: 'foo', 224 type: 'foo',
211 val: 5 225 val: 5
212 }); 226 });
213 227
214 Object.unobserve(obj, observer.callback); 228 Object.unobserve(obj, observer.callback);
215 Object.deliverChangeRecords(observer.callback); 229 Object.deliverChangeRecords(observer.callback);
216 observer.assertCallbackRecords([ 230 observer.assertCallbackRecords([
217 { object: obj, type: 'foo', val: 1 }, 231 { object: obj, type: 'foo', val: 1 },
218 { object: obj, type: 'foo', val: 3 }, 232 { object: obj, type: 'foo', val: 3 },
219 { object: obj, type: 'foo', val: 5 } 233 { object: obj, type: 'foo', val: 5 }
220 ]); 234 ]);
221 235
222 // Observing multiple objects; records appear in order. 236 // Observing multiple objects; records appear in order.
223 reset(); 237 reset();
224 var obj2 = {}; 238 var obj2 = {};
225 var obj3 = {} 239 var obj3 = {}
226 Object.observe(obj, observer.callback); 240 Object.observe(obj, observer.callback);
227 Object.observe(obj3, observer.callback); 241 Object.observe(obj3, observer.callback);
228 Object.observe(obj2, observer.callback); 242 Object.observe(obj2, observer.callback);
229 Object.notify(obj, { 243 Object.getNotifier(obj).notify({
230 type: 'foo1', 244 type: 'foo1',
231 }); 245 });
232 Object.notify(obj2, { 246 Object.getNotifier(obj2).notify({
233 type: 'foo2', 247 type: 'foo2',
234 }); 248 });
235 Object.notify(obj3, { 249 Object.getNotifier(obj3).notify({
236 type: 'foo3', 250 type: 'foo3',
237 }); 251 });
238 Object.observe(obj3, observer.callback); 252 Object.observe(obj3, observer.callback);
239 Object.deliverChangeRecords(observer.callback); 253 Object.deliverChangeRecords(observer.callback);
240 observer.assertCallbackRecords([ 254 observer.assertCallbackRecords([
241 { object: obj, type: 'foo1' }, 255 { object: obj, type: 'foo1' },
242 { object: obj2, type: 'foo2' }, 256 { object: obj2, type: 'foo2' },
243 { object: obj3, type: 'foo3' } 257 { object: obj3, type: 'foo3' }
244 ]); 258 ]);
245 259
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 { object: arr, name: '3', type: 'new' }, 438 { object: arr, name: '3', type: 'new' },
425 { object: arr, name: 'length', type: 'updated', oldValue: 3 }, 439 { object: arr, name: 'length', type: 'updated', oldValue: 3 },
426 { object: arr, name: '100', type: 'new' }, 440 { object: arr, name: '100', type: 'new' },
427 { object: arr, name: 'length', type: 'updated', oldValue: 4 }, 441 { object: arr, name: 'length', type: 'updated', oldValue: 4 },
428 { object: arr, name: '200', type: 'new' }, 442 { object: arr, name: '200', type: 'new' },
429 { object: arr, name: 'length', type: 'updated', oldValue: 101 }, 443 { object: arr, name: 'length', type: 'updated', oldValue: 101 },
430 { object: arr, name: '400', type: 'new' }, 444 { object: arr, name: '400', type: 'new' },
431 { object: arr, name: 'length', type: 'updated', oldValue: 201 }, 445 { object: arr, name: 'length', type: 'updated', oldValue: 201 },
432 { object: arr, name: '50', type: 'new' }, 446 { object: arr, name: '50', type: 'new' },
433 ]); 447 ]);
OLDNEW
« src/object-observe.js ('K') | « test/cctest/test-object-observe.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698