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

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

Issue 11419078: Object.observe/unobserve now return object (Closed) Base URL: git://github.com/v8/v8.git@master
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
« 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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); 87 %SetIsObserved(object, true);
88 } 88 }
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 return; 92 changeObservers.push(callback);
93 93
94 changeObservers.push(callback); 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; 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 return; 110 changeObservers.splice(index, 1);
111 111
112 changeObservers.splice(index, 1); 112 return object;
113 } 113 }
114 114
115 function EnqueueChangeRecord(changeRecord, observers) { 115 function EnqueueChangeRecord(changeRecord, observers) {
116 for (var i = 0; i < observers.length; i++) { 116 for (var i = 0; i < observers.length; i++) {
117 var observer = observers[i]; 117 var observer = observers[i];
118 var observerInfo = observerInfoMap.get(observer); 118 var observerInfo = observerInfoMap.get(observer);
119 observationState.pendingObservers[observerInfo.priority] = observer; 119 observationState.pendingObservers[observerInfo.priority] = observer;
120 %SetObserverDeliveryPending(); 120 %SetObserverDeliveryPending();
121 if (IS_NULL(observerInfo.pendingChangeRecords)) { 121 if (IS_NULL(observerInfo.pendingChangeRecords)) {
122 observerInfo.pendingChangeRecords = new InternalArray(changeRecord); 122 observerInfo.pendingChangeRecords = new InternalArray(changeRecord);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 "getNotifier", ObjectGetNotifier, 233 "getNotifier", ObjectGetNotifier,
234 "observe", ObjectObserve, 234 "observe", ObjectObserve,
235 "unobserve", ObjectUnobserve 235 "unobserve", ObjectUnobserve
236 )); 236 ));
237 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 237 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
238 "notify", ObjectNotifierNotify 238 "notify", ObjectNotifierNotify
239 )); 239 ));
240 } 240 }
241 241
242 SetupObjectObserve(); 242 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
This is Rietveld 408576698