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 12 matching lines...) Expand all Loading... |
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 InternalObjectIsFrozen = $Object.isFrozen; | 30 var InternalObjectIsFrozen = $Object.isFrozen; |
31 var InternalObjectFreeze = $Object.freeze; | 31 var InternalObjectFreeze = $Object.freeze; |
32 | 32 |
33 var InternalWeakMapProto = { | 33 var objectObservationState = %GetObjectObservationState(); |
34 __proto__: null, | 34 if (IS_UNDEFINED(objectObservationState.observerInfoMap)) { |
35 set: $WeakMap.prototype.set, | 35 objectObservationState.observerInfoMap = %CreateObjectHashTable(); |
36 get: $WeakMap.prototype.get, | 36 objectObservationState.objectInfoMap = %CreateObjectHashTable(); |
37 has: $WeakMap.prototype.has | |
38 } | 37 } |
39 | 38 |
40 function createInternalWeakMap() { | 39 function InternalObjectHashTable(table) { |
41 var map = new $WeakMap; | 40 this.table = table; |
42 map.__proto__ = InternalWeakMapProto; | |
43 return map; | |
44 } | 41 } |
45 | 42 |
46 var observerInfoMap = createInternalWeakMap(); | 43 InternalObjectHashTable.prototype = { |
47 var objectInfoMap = createInternalWeakMap(); | 44 get: function(key) { |
| 45 return %ObjectHashTableGet(this.table, key); |
| 46 }, |
| 47 set: function(key, value) { |
| 48 return %ObjectHashTableSet(this.table, key, value); |
| 49 }, |
| 50 has: function(key) { |
| 51 return %ObjectHashTableHas(this.table, key); |
| 52 } |
| 53 }; |
| 54 |
| 55 var observerInfoMap = new InternalObjectHashTable( |
| 56 objectObservationState.observerInfoMap); |
| 57 var objectInfoMap = new InternalObjectHashTable( |
| 58 objectObservationState.observerInfoMap); |
48 | 59 |
49 function ObjectObserve(object, callback) { | 60 function ObjectObserve(object, callback) { |
50 if (!IS_SPEC_OBJECT(object)) | 61 if (!IS_SPEC_OBJECT(object)) |
51 throw MakeTypeError("observe_non_object", ["observe"]); | 62 throw MakeTypeError("observe_non_object", ["observe"]); |
52 if (!IS_SPEC_FUNCTION(callback)) | 63 if (!IS_SPEC_FUNCTION(callback)) |
53 throw MakeTypeError("observe_non_function", ["observe"]); | 64 throw MakeTypeError("observe_non_function", ["observe"]); |
54 if (InternalObjectIsFrozen(callback)) | 65 if (InternalObjectIsFrozen(callback)) |
55 throw MakeTypeError("observe_callback_frozen"); | 66 throw MakeTypeError("observe_callback_frozen"); |
56 | 67 |
57 if (!observerInfoMap.has(callback)) { | 68 if (!observerInfoMap.has(callback)) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 function SetupObjectObserve() { | 165 function SetupObjectObserve() { |
155 %CheckIsBootstrapping(); | 166 %CheckIsBootstrapping(); |
156 InstallFunctions($Object, DONT_ENUM, $Array( | 167 InstallFunctions($Object, DONT_ENUM, $Array( |
157 "deliverChangeRecords", ObjectDeliverChangeRecords, | 168 "deliverChangeRecords", ObjectDeliverChangeRecords, |
158 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. | 169 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. |
159 "observe", ObjectObserve, | 170 "observe", ObjectObserve, |
160 "unobserve", ObjectUnobserve | 171 "unobserve", ObjectUnobserve |
161 )); | 172 )); |
162 } | 173 } |
163 | 174 |
164 SetupObjectObserve(); | 175 SetupObjectObserve(); |
OLD | NEW |