| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(); |
| OLD | NEW |