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

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

Issue 18221006: Add map transition for observed objects (Closed) Base URL: https://github.com/v8/v8.git@bleeding_edge
Patch Set: better check Created 7 years, 5 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
« no previous file with comments | « src/heap.cc ('k') | src/objects.h » ('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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 throw MakeTypeError("observe_accept_invalid"); 209 throw MakeTypeError("observe_accept_invalid");
210 210
211 if (!observerInfoMap.has(callback)) { 211 if (!observerInfoMap.has(callback)) {
212 observerInfoMap.set(callback, { 212 observerInfoMap.set(callback, {
213 pendingChangeRecords: null, 213 pendingChangeRecords: null,
214 priority: observationState.observerPriority++, 214 priority: observationState.observerPriority++,
215 }); 215 });
216 } 216 }
217 217
218 var objectInfo = objectInfoMap.get(object); 218 var objectInfo = objectInfoMap.get(object);
219 if (IS_UNDEFINED(objectInfo)) objectInfo = CreateObjectInfo(object); 219 if (IS_UNDEFINED(objectInfo)) {
220 %SetIsObserved(object, true); 220 objectInfo = CreateObjectInfo(object);
221 %SetIsObserved(object);
222 }
221 223
222 EnsureObserverRemoved(objectInfo, callback); 224 EnsureObserverRemoved(objectInfo, callback);
223 225
224 var observer = CreateObserver(callback, accept); 226 var observer = CreateObserver(callback, accept);
225 if (ObserverIsActive(observer, objectInfo)) 227 if (ObserverIsActive(observer, objectInfo))
226 objectInfo.changeObservers.push(observer); 228 objectInfo.changeObservers.push(observer);
227 else 229 else
228 objectInfo.inactiveObservers.push(observer); 230 objectInfo.inactiveObservers.push(observer);
229 231
230 return object; 232 return object;
231 } 233 }
232 234
233 function ObjectUnobserve(object, callback) { 235 function ObjectUnobserve(object, callback) {
234 if (!IS_SPEC_OBJECT(object)) 236 if (!IS_SPEC_OBJECT(object))
235 throw MakeTypeError("observe_non_object", ["unobserve"]); 237 throw MakeTypeError("observe_non_object", ["unobserve"]);
236 if (!IS_SPEC_FUNCTION(callback)) 238 if (!IS_SPEC_FUNCTION(callback))
237 throw MakeTypeError("observe_non_function", ["unobserve"]); 239 throw MakeTypeError("observe_non_function", ["unobserve"]);
238 240
239 var objectInfo = objectInfoMap.get(object); 241 var objectInfo = objectInfoMap.get(object);
240 if (IS_UNDEFINED(objectInfo)) 242 if (IS_UNDEFINED(objectInfo))
241 return object; 243 return object;
242 244
243 EnsureObserverRemoved(objectInfo, callback); 245 EnsureObserverRemoved(objectInfo, callback);
244
245 if (objectInfo.changeObservers.length === 0 &&
246 objectInfo.inactiveObservers.length === 0) {
247 %SetIsObserved(object, false);
248 }
249
250 return object; 246 return object;
251 } 247 }
252 248
253 function ArrayObserve(object, callback) { 249 function ArrayObserve(object, callback) {
254 return ObjectObserve(object, callback, ['new', 250 return ObjectObserve(object, callback, ['new',
255 'updated', 251 'updated',
256 'deleted', 252 'deleted',
257 'splice']); 253 'splice']);
258 } 254 }
259 255
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 "observe", ArrayObserve, 442 "observe", ArrayObserve,
447 "unobserve", ArrayUnobserve 443 "unobserve", ArrayUnobserve
448 )); 444 ));
449 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 445 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
450 "notify", ObjectNotifierNotify, 446 "notify", ObjectNotifierNotify,
451 "performChange", ObjectNotifierPerformChange 447 "performChange", ObjectNotifierPerformChange
452 )); 448 ));
453 } 449 }
454 450
455 SetupObjectObserve(); 451 SetupObjectObserve();
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698