| 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 "use strict"; | 28 "use strict"; |
| 29 | 29 |
| 30 var observationState = %GetObservationState(); | 30 var observationState = %GetObservationState(); |
| 31 if (IS_UNDEFINED(observationState.observerInfoMap)) { | 31 if (IS_UNDEFINED(observationState.observerInfoMap)) { |
| 32 observationState.observerInfoMap = %CreateObjectHashTable(); | 32 observationState.observerInfoMap = %ObservationWeakMapCreate(); |
| 33 observationState.objectInfoMap = %CreateObjectHashTable(); | 33 observationState.objectInfoMap = %ObservationWeakMapCreate(); |
| 34 observationState.notifierTargetMap = %CreateObjectHashTable(); | 34 observationState.notifierTargetMap = %ObservationWeakMapCreate(); |
| 35 observationState.pendingObservers = new InternalArray; | 35 observationState.pendingObservers = new InternalArray; |
| 36 observationState.observerPriority = 0; | 36 observationState.observerPriority = 0; |
| 37 } | 37 } |
| 38 | 38 |
| 39 function InternalObjectHashTable(tableName) { | 39 function ObservationWeakMap(map) { |
| 40 this.tableName = tableName; | 40 this.map_ = map; |
| 41 } | 41 } |
| 42 | 42 |
| 43 InternalObjectHashTable.prototype = { | 43 ObservationWeakMap.prototype = { |
| 44 get: function(key) { | 44 get: function(key) { |
| 45 return %ObjectHashTableGet(observationState[this.tableName], key); | 45 key = %UnwrapGlobalProxy(key); |
| 46 if (!IS_SPEC_OBJECT(key)) return void 0; |
| 47 return %WeakMapGet(this.map_, key); |
| 46 }, | 48 }, |
| 47 set: function(key, value) { | 49 set: function(key, value) { |
| 48 observationState[this.tableName] = | 50 key = %UnwrapGlobalProxy(key); |
| 49 %ObjectHashTableSet(observationState[this.tableName], key, value); | 51 if (!IS_SPEC_OBJECT(key)) return void 0; |
| 52 %WeakMapSet(this.map_, key, value); |
| 50 }, | 53 }, |
| 51 has: function(key) { | 54 has: function(key) { |
| 52 return !IS_UNDEFINED(this.get(key)); | 55 return !IS_UNDEFINED(this.get(key)); |
| 53 } | 56 } |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 var observerInfoMap = new InternalObjectHashTable('observerInfoMap'); | 59 var observerInfoMap = |
| 57 var objectInfoMap = new InternalObjectHashTable('objectInfoMap'); | 60 new ObservationWeakMap(observationState.observerInfoMap); |
| 58 var notifierTargetMap = new InternalObjectHashTable('notifierTargetMap'); | 61 var objectInfoMap = new ObservationWeakMap(observationState.objectInfoMap); |
| 62 var notifierTargetMap = |
| 63 new ObservationWeakMap(observationState.notifierTargetMap); |
| 59 | 64 |
| 60 function CreateObjectInfo(object) { | 65 function CreateObjectInfo(object) { |
| 61 var info = { | 66 var info = { |
| 62 changeObservers: new InternalArray, | 67 changeObservers: new InternalArray, |
| 63 notifier: null, | 68 notifier: null, |
| 64 }; | 69 }; |
| 65 objectInfoMap.set(object, info); | 70 objectInfoMap.set(object, info); |
| 66 return info; | 71 return info; |
| 67 } | 72 } |
| 68 | 73 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 "getNotifier", ObjectGetNotifier, | 226 "getNotifier", ObjectGetNotifier, |
| 222 "observe", ObjectObserve, | 227 "observe", ObjectObserve, |
| 223 "unobserve", ObjectUnobserve | 228 "unobserve", ObjectUnobserve |
| 224 )); | 229 )); |
| 225 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 230 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 226 "notify", ObjectNotifierNotify | 231 "notify", ObjectNotifierNotify |
| 227 )); | 232 )); |
| 228 } | 233 } |
| 229 | 234 |
| 230 SetupObjectObserve(); | 235 SetupObjectObserve(); |
| OLD | NEW |