Chromium Code Reviews

Side by Side Diff: src/object-observe.js

Issue 11593028: Object.observe: Change semantics of deliverChangeRecords to iterate. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.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 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 179 matching lines...)
190 }; 190 };
191 notifierTargetMap.set(objectInfo.notifier, object); 191 notifierTargetMap.set(objectInfo.notifier, object);
192 } 192 }
193 193
194 return objectInfo.notifier; 194 return objectInfo.notifier;
195 } 195 }
196 196
197 function DeliverChangeRecordsForObserver(observer) { 197 function DeliverChangeRecordsForObserver(observer) {
198 var observerInfo = observerInfoMap.get(observer); 198 var observerInfo = observerInfoMap.get(observer);
199 if (IS_UNDEFINED(observerInfo)) 199 if (IS_UNDEFINED(observerInfo))
200 return; 200 return false;
Yang 2012/12/19 09:37:06 This formatting looks very WebKit-ish. We usually
201 201
202 var pendingChangeRecords = observerInfo.pendingChangeRecords; 202 var pendingChangeRecords = observerInfo.pendingChangeRecords;
203 if (IS_NULL(pendingChangeRecords)) 203 if (IS_NULL(pendingChangeRecords))
204 return; 204 return false;
Yang 2012/12/19 09:37:06 Ditto.
205 205
206 observerInfo.pendingChangeRecords = null; 206 observerInfo.pendingChangeRecords = null;
207 delete observationState.pendingObservers[observerInfo.priority]; 207 delete observationState.pendingObservers[observerInfo.priority];
208 var delivered = []; 208 var delivered = [];
209 %MoveArrayContents(pendingChangeRecords, delivered); 209 %MoveArrayContents(pendingChangeRecords, delivered);
210 try { 210 try {
211 %Call(void 0, delivered, observer); 211 %Call(void 0, delivered, observer);
212 } catch (ex) {} 212 } catch (ex) {}
213 return true;
213 } 214 }
214 215
215 function ObjectDeliverChangeRecords(callback) { 216 function ObjectDeliverChangeRecords(callback) {
216 if (!IS_SPEC_FUNCTION(callback)) 217 if (!IS_SPEC_FUNCTION(callback))
217 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); 218 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]);
218 219
219 DeliverChangeRecordsForObserver(callback); 220 while (DeliverChangeRecordsForObserver(callback)) {}
220 } 221 }
221 222
222 function DeliverChangeRecords() { 223 function DeliverChangeRecords() {
223 while (observationState.pendingObservers.length) { 224 while (observationState.pendingObservers.length) {
224 var pendingObservers = observationState.pendingObservers; 225 var pendingObservers = observationState.pendingObservers;
225 observationState.pendingObservers = new InternalArray; 226 observationState.pendingObservers = new InternalArray;
226 for (var i in pendingObservers) { 227 for (var i in pendingObservers) {
227 DeliverChangeRecordsForObserver(pendingObservers[i]); 228 DeliverChangeRecordsForObserver(pendingObservers[i]);
228 } 229 }
229 } 230 }
230 } 231 }
231 232
232 function SetupObjectObserve() { 233 function SetupObjectObserve() {
233 %CheckIsBootstrapping(); 234 %CheckIsBootstrapping();
234 InstallFunctions($Object, DONT_ENUM, $Array( 235 InstallFunctions($Object, DONT_ENUM, $Array(
235 "deliverChangeRecords", ObjectDeliverChangeRecords, 236 "deliverChangeRecords", ObjectDeliverChangeRecords,
236 "getNotifier", ObjectGetNotifier, 237 "getNotifier", ObjectGetNotifier,
237 "observe", ObjectObserve, 238 "observe", ObjectObserve,
238 "unobserve", ObjectUnobserve 239 "unobserve", ObjectUnobserve
239 )); 240 ));
240 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 241 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
241 "notify", ObjectNotifierNotify 242 "notify", ObjectNotifierNotify
242 )); 243 ));
243 } 244 }
244 245
245 SetupObjectObserve(); 246 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine