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

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

Issue 11554019: Object.observe: Make array length and other magic data properties work correctly. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Michael's comments Created 8 years 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 | « no previous file | src/objects.cc » ('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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (!observerInfoMap.has(callback)) { 77 if (!observerInfoMap.has(callback)) {
78 observerInfoMap.set(callback, { 78 observerInfoMap.set(callback, {
79 pendingChangeRecords: null, 79 pendingChangeRecords: null,
80 priority: observationState.observerPriority++, 80 priority: observationState.observerPriority++,
81 }); 81 });
82 } 82 }
83 83
84 var objectInfo = objectInfoMap.get(object); 84 var objectInfo = objectInfoMap.get(object);
85 if (IS_UNDEFINED(objectInfo)) { 85 if (IS_UNDEFINED(objectInfo)) {
86 objectInfo = CreateObjectInfo(object); 86 objectInfo = CreateObjectInfo(object);
87 %SetIsObserved(object, true);
88 } 87 }
88 %SetIsObserved(object, true);
89 89
90 var changeObservers = objectInfo.changeObservers; 90 var changeObservers = objectInfo.changeObservers;
91 if (changeObservers.indexOf(callback) < 0) 91 if (changeObservers.indexOf(callback) < 0)
92 changeObservers.push(callback); 92 changeObservers.push(callback);
93 93
94 return object; 94 return object;
95 } 95 }
96 96
97 function ObjectUnobserve(object, callback) { 97 function ObjectUnobserve(object, callback) {
98 if (!IS_SPEC_OBJECT(object)) 98 if (!IS_SPEC_OBJECT(object))
99 throw MakeTypeError("observe_non_object", ["unobserve"]); 99 throw MakeTypeError("observe_non_object", ["unobserve"]);
100 if (!IS_SPEC_FUNCTION(callback)) 100 if (!IS_SPEC_FUNCTION(callback))
101 throw MakeTypeError("observe_non_function", ["unobserve"]); 101 throw MakeTypeError("observe_non_function", ["unobserve"]);
102 102
103 var objectInfo = objectInfoMap.get(object); 103 var objectInfo = objectInfoMap.get(object);
104 if (IS_UNDEFINED(objectInfo)) 104 if (IS_UNDEFINED(objectInfo))
105 return object; 105 return object;
106 106
107 var changeObservers = objectInfo.changeObservers; 107 var changeObservers = objectInfo.changeObservers;
108 var index = changeObservers.indexOf(callback); 108 var index = changeObservers.indexOf(callback);
109 if (index >= 0) 109 if (index >= 0) {
110 changeObservers.splice(index, 1); 110 changeObservers.splice(index, 1);
111 if (changeObservers.length === 0)
112 %SetIsObserved(object, false);
113 }
111 114
112 return object; 115 return object;
113 } 116 }
114 117
115 function EnqueueChangeRecord(changeRecord, observers) { 118 function EnqueueChangeRecord(changeRecord, observers) {
116 for (var i = 0; i < observers.length; i++) { 119 for (var i = 0; i < observers.length; i++) {
117 var observer = observers[i]; 120 var observer = observers[i];
118 var observerInfo = observerInfoMap.get(observer); 121 var observerInfo = observerInfoMap.get(observer);
119 observationState.pendingObservers[observerInfo.priority] = observer; 122 observationState.pendingObservers[observerInfo.priority] = observer;
120 %SetObserverDeliveryPending(); 123 %SetObserverDeliveryPending();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 "getNotifier", ObjectGetNotifier, 236 "getNotifier", ObjectGetNotifier,
234 "observe", ObjectObserve, 237 "observe", ObjectObserve,
235 "unobserve", ObjectUnobserve 238 "unobserve", ObjectUnobserve
236 )); 239 ));
237 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 240 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
238 "notify", ObjectNotifierNotify 241 "notify", ObjectNotifierNotify
239 )); 242 ));
240 } 243 }
241 244
242 SetupObjectObserve(); 245 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698