| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 }); | 61 }); |
| 62 } | 62 } |
| 63 | 63 |
| 64 var objectInfo = objectInfoMap.get(object); | 64 var objectInfo = objectInfoMap.get(object); |
| 65 if (IS_UNDEFINED(objectInfo)) { | 65 if (IS_UNDEFINED(objectInfo)) { |
| 66 // TODO: setup objectInfo.notifier | 66 // TODO: setup objectInfo.notifier |
| 67 objectInfo = { | 67 objectInfo = { |
| 68 changeObservers: new InternalArray(callback) | 68 changeObservers: new InternalArray(callback) |
| 69 }; | 69 }; |
| 70 objectInfoMap.set(object, objectInfo); | 70 objectInfoMap.set(object, objectInfo); |
| 71 %SetIsObserved(object, true); |
| 71 return; | 72 return; |
| 72 } | 73 } |
| 73 | 74 |
| 74 var changeObservers = objectInfo.changeObservers; | 75 var changeObservers = objectInfo.changeObservers; |
| 75 if (changeObservers.indexOf(callback) >= 0) | 76 if (changeObservers.indexOf(callback) >= 0) |
| 76 return; | 77 return; |
| 77 | 78 |
| 78 changeObservers.push(callback); | 79 changeObservers.push(callback); |
| 79 } | 80 } |
| 80 | 81 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 102 // TODO: "activate" the observer | 103 // TODO: "activate" the observer |
| 103 | 104 |
| 104 if (IS_NULL(observerInfo.pendingChangeRecords)) { | 105 if (IS_NULL(observerInfo.pendingChangeRecords)) { |
| 105 observerInfo.pendingChangeRecords = new InternalArray(changeRecord); | 106 observerInfo.pendingChangeRecords = new InternalArray(changeRecord); |
| 106 } else { | 107 } else { |
| 107 observerInfo.pendingChangeRecords.push(changeRecord); | 108 observerInfo.pendingChangeRecords.push(changeRecord); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 113 function NotifyChange(type, object, name, oldValue) { |
| 114 var objectInfo = objectInfoMap.get(object); |
| 115 var changeRecord = (arguments.length < 4) ? |
| 116 { type: type, object: object, name: name } : |
| 117 { type: type, object: object, name: name, oldValue: oldValue }; |
| 118 InternalObjectFreeze(changeRecord); |
| 119 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers); |
| 120 } |
| 121 |
| 112 function ObjectNotify(object, changeRecord) { | 122 function ObjectNotify(object, changeRecord) { |
| 113 // TODO: notifier needs to be [[THIS]] | 123 // TODO: notifier needs to be [[THIS]] |
| 114 if (!IS_STRING(changeRecord.type)) | 124 if (!IS_STRING(changeRecord.type)) |
| 115 throw MakeTypeError("observe_type_non_string"); | 125 throw MakeTypeError("observe_type_non_string"); |
| 116 | 126 |
| 117 var objectInfo = objectInfoMap.get(object); | 127 var objectInfo = objectInfoMap.get(object); |
| 118 if (IS_UNDEFINED(objectInfo)) | 128 if (IS_UNDEFINED(objectInfo)) |
| 119 return; | 129 return; |
| 120 | 130 |
| 121 var newRecord = { | 131 var newRecord = { |
| 122 object: object // TODO: Needs to be 'object' retreived from notifier | 132 object: object // TODO: Needs to be 'object' retrieved from notifier |
| 123 }; | 133 }; |
| 124 for (var prop in changeRecord) { | 134 for (var prop in changeRecord) { |
| 125 if (prop === 'object') | 135 if (prop === 'object') |
| 126 continue; | 136 continue; |
| 127 newRecord[prop] = changeRecord[prop]; | 137 newRecord[prop] = changeRecord[prop]; |
| 128 } | 138 } |
| 129 InternalObjectFreeze(newRecord); | 139 InternalObjectFreeze(newRecord); |
| 130 | 140 |
| 131 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); | 141 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); |
| 132 } | 142 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 154 function SetupObjectObserve() { | 164 function SetupObjectObserve() { |
| 155 %CheckIsBootstrapping(); | 165 %CheckIsBootstrapping(); |
| 156 InstallFunctions($Object, DONT_ENUM, $Array( | 166 InstallFunctions($Object, DONT_ENUM, $Array( |
| 157 "deliverChangeRecords", ObjectDeliverChangeRecords, | 167 "deliverChangeRecords", ObjectDeliverChangeRecords, |
| 158 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. | 168 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. |
| 159 "observe", ObjectObserve, | 169 "observe", ObjectObserve, |
| 160 "unobserve", ObjectUnobserve | 170 "unobserve", ObjectUnobserve |
| 161 )); | 171 )); |
| 162 } | 172 } |
| 163 | 173 |
| 164 SetupObjectObserve(); | 174 SetupObjectObserve(); |
| OLD | NEW |