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 var $observeEnqueueSpliceRecord; | 5 var $observeEnqueueSpliceRecord; |
6 var $observeBeginPerformSplice; | 6 var $observeBeginPerformSplice; |
7 var $observeEndPerformSplice; | 7 var $observeEndPerformSplice; |
8 | 8 |
9 var $observeObjectMethods; | 9 var $observeObjectMethods; |
10 var $observeArrayMethods; | 10 var $observeArrayMethods; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (IS_UNDEFINED(acceptList)) | 171 if (IS_UNDEFINED(acceptList)) |
172 return callback; | 172 return callback; |
173 var observer = nullProtoObject(); | 173 var observer = nullProtoObject(); |
174 observer.callback = callback; | 174 observer.callback = callback; |
175 observer.accept = acceptList; | 175 observer.accept = acceptList; |
176 return observer; | 176 return observer; |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 function ObserverGetCallback(observer) { | 180 function ObserverGetCallback(observer) { |
181 return IS_SPEC_FUNCTION(observer) ? observer : observer.callback; | 181 return IS_CALLABLE(observer) ? observer : observer.callback; |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 function ObserverGetAcceptTypes(observer) { | 185 function ObserverGetAcceptTypes(observer) { |
186 return IS_SPEC_FUNCTION(observer) ? defaultAcceptTypes : observer.accept; | 186 return IS_CALLABLE(observer) ? defaultAcceptTypes : observer.accept; |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 function ObserverIsActive(observer, objectInfo) { | 190 function ObserverIsActive(observer, objectInfo) { |
191 return TypeMapIsDisjointFrom(ObjectInfoGetPerformingTypes(objectInfo), | 191 return TypeMapIsDisjointFrom(ObjectInfoGetPerformingTypes(objectInfo), |
192 ObserverGetAcceptTypes(observer)); | 192 ObserverGetAcceptTypes(observer)); |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 function ObjectInfoGetOrCreate(object) { | 196 function ObjectInfoGetOrCreate(object) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 objectInfo.notifier = notifier; | 231 objectInfo.notifier = notifier; |
232 %WeakCollectionSet(GetObservationStateJS().notifierObjectInfoMap, | 232 %WeakCollectionSet(GetObservationStateJS().notifierObjectInfoMap, |
233 notifier, objectInfo, $getHash(notifier)); | 233 notifier, objectInfo, $getHash(notifier)); |
234 } | 234 } |
235 | 235 |
236 return objectInfo.notifier; | 236 return objectInfo.notifier; |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 function ChangeObserversIsOptimized(changeObservers) { | 240 function ChangeObserversIsOptimized(changeObservers) { |
241 return IS_SPEC_FUNCTION(changeObservers) || | 241 return IS_CALLABLE(changeObservers) || |
242 IS_SPEC_FUNCTION(changeObservers.callback); | 242 IS_CALLABLE(changeObservers.callback); |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 // The set of observers on an object is called 'changeObservers'. The first | 246 // The set of observers on an object is called 'changeObservers'. The first |
247 // observer is referenced directly via objectInfo.changeObservers. When a second | 247 // observer is referenced directly via objectInfo.changeObservers. When a second |
248 // is added, changeObservers "normalizes" to become a mapping of callback | 248 // is added, changeObservers "normalizes" to become a mapping of callback |
249 // priority -> observer and is then stored on objectInfo.changeObservers. | 249 // priority -> observer and is then stored on objectInfo.changeObservers. |
250 function ObjectInfoNormalizeChangeObservers(objectInfo) { | 250 function ObjectInfoNormalizeChangeObservers(objectInfo) { |
251 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { | 251 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { |
252 var observer = objectInfo.changeObservers; | 252 var observer = objectInfo.changeObservers; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 381 } |
382 return callbackInfo; | 382 return callbackInfo; |
383 } | 383 } |
384 | 384 |
385 | 385 |
386 function ObjectObserve(object, callback, acceptList) { | 386 function ObjectObserve(object, callback, acceptList) { |
387 if (!IS_SPEC_OBJECT(object)) | 387 if (!IS_SPEC_OBJECT(object)) |
388 throw MakeTypeError(kObserveNonObject, "observe", "observe"); | 388 throw MakeTypeError(kObserveNonObject, "observe", "observe"); |
389 if (%IsJSGlobalProxy(object)) | 389 if (%IsJSGlobalProxy(object)) |
390 throw MakeTypeError(kObserveGlobalProxy, "observe"); | 390 throw MakeTypeError(kObserveGlobalProxy, "observe"); |
391 if (!IS_SPEC_FUNCTION(callback)) | 391 if (!IS_CALLABLE(callback)) |
392 throw MakeTypeError(kObserveNonFunction, "observe"); | 392 throw MakeTypeError(kObserveNonFunction, "observe"); |
393 if (ObjectIsFrozen(callback)) | 393 if (ObjectIsFrozen(callback)) |
394 throw MakeTypeError(kObserveCallbackFrozen); | 394 throw MakeTypeError(kObserveCallbackFrozen); |
395 | 395 |
396 var objectObserveFn = %GetObjectContextObjectObserve(object); | 396 var objectObserveFn = %GetObjectContextObjectObserve(object); |
397 return objectObserveFn(object, callback, acceptList); | 397 return objectObserveFn(object, callback, acceptList); |
398 } | 398 } |
399 | 399 |
400 | 400 |
401 function NativeObjectObserve(object, callback, acceptList) { | 401 function NativeObjectObserve(object, callback, acceptList) { |
402 var objectInfo = ObjectInfoGetOrCreate(object); | 402 var objectInfo = ObjectInfoGetOrCreate(object); |
403 var typeList = ConvertAcceptListToTypeMap(acceptList); | 403 var typeList = ConvertAcceptListToTypeMap(acceptList); |
404 ObjectInfoAddObserver(objectInfo, callback, typeList); | 404 ObjectInfoAddObserver(objectInfo, callback, typeList); |
405 return object; | 405 return object; |
406 } | 406 } |
407 | 407 |
408 | 408 |
409 function ObjectUnobserve(object, callback) { | 409 function ObjectUnobserve(object, callback) { |
410 if (!IS_SPEC_OBJECT(object)) | 410 if (!IS_SPEC_OBJECT(object)) |
411 throw MakeTypeError(kObserveNonObject, "unobserve", "unobserve"); | 411 throw MakeTypeError(kObserveNonObject, "unobserve", "unobserve"); |
412 if (%IsJSGlobalProxy(object)) | 412 if (%IsJSGlobalProxy(object)) |
413 throw MakeTypeError(kObserveGlobalProxy, "unobserve"); | 413 throw MakeTypeError(kObserveGlobalProxy, "unobserve"); |
414 if (!IS_SPEC_FUNCTION(callback)) | 414 if (!IS_CALLABLE(callback)) |
415 throw MakeTypeError(kObserveNonFunction, "unobserve"); | 415 throw MakeTypeError(kObserveNonFunction, "unobserve"); |
416 | 416 |
417 var objectInfo = ObjectInfoGet(object); | 417 var objectInfo = ObjectInfoGet(object); |
418 if (IS_UNDEFINED(objectInfo)) | 418 if (IS_UNDEFINED(objectInfo)) |
419 return object; | 419 return object; |
420 | 420 |
421 ObjectInfoRemoveObserver(objectInfo, callback); | 421 ObjectInfoRemoveObserver(objectInfo, callback); |
422 return object; | 422 return object; |
423 } | 423 } |
424 | 424 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 581 |
582 function ObjectNotifierPerformChange(changeType, changeFn) { | 582 function ObjectNotifierPerformChange(changeType, changeFn) { |
583 if (!IS_SPEC_OBJECT(this)) | 583 if (!IS_SPEC_OBJECT(this)) |
584 throw MakeTypeError(kCalledOnNonObject, "performChange"); | 584 throw MakeTypeError(kCalledOnNonObject, "performChange"); |
585 | 585 |
586 var objectInfo = ObjectInfoGetFromNotifier(this); | 586 var objectInfo = ObjectInfoGetFromNotifier(this); |
587 if (IS_UNDEFINED(objectInfo)) | 587 if (IS_UNDEFINED(objectInfo)) |
588 throw MakeTypeError(kObserveNotifyNonNotifier); | 588 throw MakeTypeError(kObserveNotifyNonNotifier); |
589 if (!IS_STRING(changeType)) | 589 if (!IS_STRING(changeType)) |
590 throw MakeTypeError(kObservePerformNonString); | 590 throw MakeTypeError(kObservePerformNonString); |
591 if (!IS_SPEC_FUNCTION(changeFn)) | 591 if (!IS_CALLABLE(changeFn)) |
592 throw MakeTypeError(kObservePerformNonFunction); | 592 throw MakeTypeError(kObservePerformNonFunction); |
593 | 593 |
594 var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo); | 594 var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo); |
595 performChangeFn(objectInfo, changeType, changeFn); | 595 performChangeFn(objectInfo, changeType, changeFn); |
596 } | 596 } |
597 | 597 |
598 | 598 |
599 function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { | 599 function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { |
600 ObjectInfoAddPerformingType(objectInfo, changeType); | 600 ObjectInfoAddPerformingType(objectInfo, changeType); |
601 | 601 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // TODO: combine the following runtime calls for perf optimization. | 649 // TODO: combine the following runtime calls for perf optimization. |
650 var delivered = []; | 650 var delivered = []; |
651 %MoveArrayContents(callbackInfo, delivered); | 651 %MoveArrayContents(callbackInfo, delivered); |
652 %DeliverObservationChangeRecords(callback, delivered); | 652 %DeliverObservationChangeRecords(callback, delivered); |
653 | 653 |
654 return true; | 654 return true; |
655 } | 655 } |
656 | 656 |
657 | 657 |
658 function ObjectDeliverChangeRecords(callback) { | 658 function ObjectDeliverChangeRecords(callback) { |
659 if (!IS_SPEC_FUNCTION(callback)) | 659 if (!IS_CALLABLE(callback)) |
660 throw MakeTypeError(kObserveNonFunction, "deliverChangeRecords"); | 660 throw MakeTypeError(kObserveNonFunction, "deliverChangeRecords"); |
661 | 661 |
662 while (CallbackDeliverPending(callback)) {} | 662 while (CallbackDeliverPending(callback)) {} |
663 } | 663 } |
664 | 664 |
665 | 665 |
666 function ObserveMicrotaskRunner() { | 666 function ObserveMicrotaskRunner() { |
667 var pendingObservers = GetPendingObservers(); | 667 var pendingObservers = GetPendingObservers(); |
668 if (!IS_NULL(pendingObservers)) { | 668 if (!IS_NULL(pendingObservers)) { |
669 SetPendingObservers(null); | 669 SetPendingObservers(null); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 "native_object_get_notifier", NativeObjectGetNotifier, | 707 "native_object_get_notifier", NativeObjectGetNotifier, |
708 "native_object_notifier_perform_change", NativeObjectNotifierPerformChange, | 708 "native_object_notifier_perform_change", NativeObjectNotifierPerformChange, |
709 "native_object_observe", NativeObjectObserve, | 709 "native_object_observe", NativeObjectObserve, |
710 "observers_begin_perform_splice", BeginPerformSplice, | 710 "observers_begin_perform_splice", BeginPerformSplice, |
711 "observers_end_perform_splice", EndPerformSplice, | 711 "observers_end_perform_splice", EndPerformSplice, |
712 "observers_enqueue_splice", EnqueueSpliceRecord, | 712 "observers_enqueue_splice", EnqueueSpliceRecord, |
713 "observers_notify_change", NotifyChange, | 713 "observers_notify_change", NotifyChange, |
714 ]); | 714 ]); |
715 | 715 |
716 }) | 716 }) |
OLD | NEW |