OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
| 14 var GetHash; |
14 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
15 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
16 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; |
17 | |
18 var ObjectFreeze; | 18 var ObjectFreeze; |
19 var ObjectIsFrozen; | 19 var ObjectIsFrozen; |
20 | 20 |
21 utils.Import(function(from) { | 21 utils.Import(function(from) { |
| 22 GetHash = from.GetHash; |
22 ObjectFreeze = from.ObjectFreeze; | 23 ObjectFreeze = from.ObjectFreeze; |
23 ObjectIsFrozen = from.ObjectIsFrozen; | 24 ObjectIsFrozen = from.ObjectIsFrozen; |
24 }); | 25 }); |
25 | 26 |
26 // ------------------------------------------------------------------- | 27 // ------------------------------------------------------------------- |
27 | 28 |
28 // Overview: | 29 // Overview: |
29 // | 30 // |
30 // This file contains all of the routing and accounting for Object.observe. | 31 // This file contains all of the routing and accounting for Object.observe. |
31 // User code will interact with these mechanisms via the Object.observe APIs | 32 // User code will interact with these mechanisms via the Object.observe APIs |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 %SetIsObserved(object); | 194 %SetIsObserved(object); |
194 } | 195 } |
195 objectInfo = { | 196 objectInfo = { |
196 object: object, | 197 object: object, |
197 changeObservers: null, | 198 changeObservers: null, |
198 notifier: null, | 199 notifier: null, |
199 performing: null, | 200 performing: null, |
200 performingCount: 0, | 201 performingCount: 0, |
201 }; | 202 }; |
202 %WeakCollectionSet(GetObservationStateJS().objectInfoMap, | 203 %WeakCollectionSet(GetObservationStateJS().objectInfoMap, |
203 object, objectInfo, $getHash(object)); | 204 object, objectInfo, GetHash(object)); |
204 } | 205 } |
205 return objectInfo; | 206 return objectInfo; |
206 } | 207 } |
207 | 208 |
208 | 209 |
209 function ObjectInfoGet(object) { | 210 function ObjectInfoGet(object) { |
210 return %WeakCollectionGet(GetObservationStateJS().objectInfoMap, object, | 211 return %WeakCollectionGet(GetObservationStateJS().objectInfoMap, object, |
211 $getHash(object)); | 212 GetHash(object)); |
212 } | 213 } |
213 | 214 |
214 | 215 |
215 function ObjectInfoGetFromNotifier(notifier) { | 216 function ObjectInfoGetFromNotifier(notifier) { |
216 return %WeakCollectionGet(GetObservationStateJS().notifierObjectInfoMap, | 217 return %WeakCollectionGet(GetObservationStateJS().notifierObjectInfoMap, |
217 notifier, $getHash(notifier)); | 218 notifier, GetHash(notifier)); |
218 } | 219 } |
219 | 220 |
220 | 221 |
221 function ObjectInfoGetNotifier(objectInfo) { | 222 function ObjectInfoGetNotifier(objectInfo) { |
222 if (IS_NULL(objectInfo.notifier)) { | 223 if (IS_NULL(objectInfo.notifier)) { |
223 var notifier = { __proto__: notifierPrototype }; | 224 var notifier = { __proto__: notifierPrototype }; |
224 objectInfo.notifier = notifier; | 225 objectInfo.notifier = notifier; |
225 %WeakCollectionSet(GetObservationStateJS().notifierObjectInfoMap, | 226 %WeakCollectionSet(GetObservationStateJS().notifierObjectInfoMap, |
226 notifier, objectInfo, $getHash(notifier)); | 227 notifier, objectInfo, GetHash(notifier)); |
227 } | 228 } |
228 | 229 |
229 return objectInfo.notifier; | 230 return objectInfo.notifier; |
230 } | 231 } |
231 | 232 |
232 | 233 |
233 function ChangeObserversIsOptimized(changeObservers) { | 234 function ChangeObserversIsOptimized(changeObservers) { |
234 return IS_CALLABLE(changeObservers) || | 235 return IS_CALLABLE(changeObservers) || |
235 IS_CALLABLE(changeObservers.callback); | 236 IS_CALLABLE(changeObservers.callback); |
236 } | 237 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 329 |
329 return TypeMapCreateFromList(arg, len); | 330 return TypeMapCreateFromList(arg, len); |
330 } | 331 } |
331 | 332 |
332 | 333 |
333 // CallbackInfo's optimized state is just a number which represents its global | 334 // CallbackInfo's optimized state is just a number which represents its global |
334 // priority. When a change record must be enqueued for the callback, it | 335 // priority. When a change record must be enqueued for the callback, it |
335 // normalizes. When delivery clears any pending change records, it re-optimizes. | 336 // normalizes. When delivery clears any pending change records, it re-optimizes. |
336 function CallbackInfoGet(callback) { | 337 function CallbackInfoGet(callback) { |
337 return %WeakCollectionGet(GetObservationStateJS().callbackInfoMap, callback, | 338 return %WeakCollectionGet(GetObservationStateJS().callbackInfoMap, callback, |
338 $getHash(callback)); | 339 GetHash(callback)); |
339 } | 340 } |
340 | 341 |
341 | 342 |
342 function CallbackInfoSet(callback, callbackInfo) { | 343 function CallbackInfoSet(callback, callbackInfo) { |
343 %WeakCollectionSet(GetObservationStateJS().callbackInfoMap, | 344 %WeakCollectionSet(GetObservationStateJS().callbackInfoMap, |
344 callback, callbackInfo, $getHash(callback)); | 345 callback, callbackInfo, GetHash(callback)); |
345 } | 346 } |
346 | 347 |
347 | 348 |
348 function CallbackInfoGetOrCreate(callback) { | 349 function CallbackInfoGetOrCreate(callback) { |
349 var callbackInfo = CallbackInfoGet(callback); | 350 var callbackInfo = CallbackInfoGet(callback); |
350 if (!IS_UNDEFINED(callbackInfo)) | 351 if (!IS_UNDEFINED(callbackInfo)) |
351 return callbackInfo; | 352 return callbackInfo; |
352 | 353 |
353 var priority = GetNextCallbackPriority(); | 354 var priority = GetNextCallbackPriority(); |
354 CallbackInfoSet(callback, priority); | 355 CallbackInfoSet(callback, priority); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 710 |
710 utils.Export(function(to) { | 711 utils.Export(function(to) { |
711 to.ObserveArrayMethods = ObserveArrayMethods; | 712 to.ObserveArrayMethods = ObserveArrayMethods; |
712 to.ObserveBeginPerformSplice = BeginPerformSplice; | 713 to.ObserveBeginPerformSplice = BeginPerformSplice; |
713 to.ObserveEndPerformSplice = EndPerformSplice; | 714 to.ObserveEndPerformSplice = EndPerformSplice; |
714 to.ObserveEnqueueSpliceRecord = EnqueueSpliceRecord; | 715 to.ObserveEnqueueSpliceRecord = EnqueueSpliceRecord; |
715 to.ObserveObjectMethods = ObserveObjectMethods; | 716 to.ObserveObjectMethods = ObserveObjectMethods; |
716 }); | 717 }); |
717 | 718 |
718 }) | 719 }) |
OLD | NEW |