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 $observeNotifyChange; | 5 var $observeNotifyChange; |
6 var $observeEnqueueSpliceRecord; | 6 var $observeEnqueueSpliceRecord; |
7 var $observeBeginPerformSplice; | 7 var $observeBeginPerformSplice; |
8 var $observeEndPerformSplice; | 8 var $observeEndPerformSplice; |
9 var $observeNativeObjectObserve; | 9 var $observeNativeObjectObserve; |
10 var $observeNativeObjectGetNotifier; | 10 var $observeNativeObjectGetNotifier; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 369 } |
370 | 370 |
371 | 371 |
372 function ObjectObserve(object, callback, acceptList) { | 372 function ObjectObserve(object, callback, acceptList) { |
373 if (!IS_SPEC_OBJECT(object)) | 373 if (!IS_SPEC_OBJECT(object)) |
374 throw MakeTypeError(kObserveNonObject, "observe", "observe"); | 374 throw MakeTypeError(kObserveNonObject, "observe", "observe"); |
375 if (%IsJSGlobalProxy(object)) | 375 if (%IsJSGlobalProxy(object)) |
376 throw MakeTypeError(kObserveGlobalProxy, "observe"); | 376 throw MakeTypeError(kObserveGlobalProxy, "observe"); |
377 if (!IS_SPEC_FUNCTION(callback)) | 377 if (!IS_SPEC_FUNCTION(callback)) |
378 throw MakeTypeError(kObserveNonFunction, "observe"); | 378 throw MakeTypeError(kObserveNonFunction, "observe"); |
379 if (ObjectIsFrozen(callback)) | 379 if ($objectIsFrozen(callback)) |
380 throw MakeTypeError(kObserveCallbackFrozen); | 380 throw MakeTypeError(kObserveCallbackFrozen); |
381 | 381 |
382 var objectObserveFn = %GetObjectContextObjectObserve(object); | 382 var objectObserveFn = %GetObjectContextObjectObserve(object); |
383 return objectObserveFn(object, callback, acceptList); | 383 return objectObserveFn(object, callback, acceptList); |
384 } | 384 } |
385 | 385 |
386 | 386 |
387 function NativeObjectObserve(object, callback, acceptList) { | 387 function NativeObjectObserve(object, callback, acceptList) { |
388 var objectInfo = ObjectInfoGetOrCreate(object); | 388 var objectInfo = ObjectInfoGetOrCreate(object); |
389 var typeList = ConvertAcceptListToTypeMap(acceptList); | 389 var typeList = ConvertAcceptListToTypeMap(acceptList); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 var hasType = !IS_UNDEFINED(type); | 462 var hasType = !IS_UNDEFINED(type); |
463 var newRecord = hasType ? | 463 var newRecord = hasType ? |
464 { object: objectInfo.object, type: type } : | 464 { object: objectInfo.object, type: type } : |
465 { object: objectInfo.object }; | 465 { object: objectInfo.object }; |
466 | 466 |
467 for (var prop in changeRecord) { | 467 for (var prop in changeRecord) { |
468 if (prop === 'object' || (hasType && prop === 'type')) continue; | 468 if (prop === 'object' || (hasType && prop === 'type')) continue; |
469 %DefineDataPropertyUnchecked( | 469 %DefineDataPropertyUnchecked( |
470 newRecord, prop, changeRecord[prop], READ_ONLY + DONT_DELETE); | 470 newRecord, prop, changeRecord[prop], READ_ONLY + DONT_DELETE); |
471 } | 471 } |
472 ObjectFreezeJS(newRecord); | 472 $objectFreeze(newRecord); |
473 | 473 |
474 ObjectInfoEnqueueInternalChangeRecord(objectInfo, newRecord); | 474 ObjectInfoEnqueueInternalChangeRecord(objectInfo, newRecord); |
475 } | 475 } |
476 | 476 |
477 | 477 |
478 function ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord) { | 478 function ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord) { |
479 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 479 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
480 if (IS_SYMBOL(changeRecord.name)) return; | 480 if (IS_SYMBOL(changeRecord.name)) return; |
481 | 481 |
482 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { | 482 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return; | 514 return; |
515 | 515 |
516 var changeRecord = { | 516 var changeRecord = { |
517 type: 'splice', | 517 type: 'splice', |
518 object: array, | 518 object: array, |
519 index: index, | 519 index: index, |
520 removed: removed, | 520 removed: removed, |
521 addedCount: addedCount | 521 addedCount: addedCount |
522 }; | 522 }; |
523 | 523 |
524 ObjectFreezeJS(changeRecord); | 524 $objectFreeze(changeRecord); |
525 ObjectFreezeJS(changeRecord.removed); | 525 $objectFreeze(changeRecord.removed); |
526 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); | 526 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); |
527 } | 527 } |
528 | 528 |
529 | 529 |
530 function NotifyChange(type, object, name, oldValue) { | 530 function NotifyChange(type, object, name, oldValue) { |
531 var objectInfo = ObjectInfoGet(object); | 531 var objectInfo = ObjectInfoGet(object); |
532 if (!ObjectInfoHasActiveObservers(objectInfo)) | 532 if (!ObjectInfoHasActiveObservers(objectInfo)) |
533 return; | 533 return; |
534 | 534 |
535 var changeRecord; | 535 var changeRecord; |
536 if (arguments.length == 2) { | 536 if (arguments.length == 2) { |
537 changeRecord = { type: type, object: object }; | 537 changeRecord = { type: type, object: object }; |
538 } else if (arguments.length == 3) { | 538 } else if (arguments.length == 3) { |
539 changeRecord = { type: type, object: object, name: name }; | 539 changeRecord = { type: type, object: object, name: name }; |
540 } else { | 540 } else { |
541 changeRecord = { | 541 changeRecord = { |
542 type: type, | 542 type: type, |
543 object: object, | 543 object: object, |
544 name: name, | 544 name: name, |
545 oldValue: oldValue | 545 oldValue: oldValue |
546 }; | 546 }; |
547 } | 547 } |
548 | 548 |
549 ObjectFreezeJS(changeRecord); | 549 $objectFreeze(changeRecord); |
550 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); | 550 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); |
551 } | 551 } |
552 | 552 |
553 | 553 |
554 function ObjectNotifierNotify(changeRecord) { | 554 function ObjectNotifierNotify(changeRecord) { |
555 if (!IS_SPEC_OBJECT(this)) | 555 if (!IS_SPEC_OBJECT(this)) |
556 throw MakeTypeError(kCalledOnNonObject, "notify"); | 556 throw MakeTypeError(kCalledOnNonObject, "notify"); |
557 | 557 |
558 var objectInfo = ObjectInfoGetFromNotifier(this); | 558 var objectInfo = ObjectInfoGetFromNotifier(this); |
559 if (IS_UNDEFINED(objectInfo)) | 559 if (IS_UNDEFINED(objectInfo)) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); | 596 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); |
597 } | 597 } |
598 | 598 |
599 | 599 |
600 function ObjectGetNotifier(object) { | 600 function ObjectGetNotifier(object) { |
601 if (!IS_SPEC_OBJECT(object)) | 601 if (!IS_SPEC_OBJECT(object)) |
602 throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier"); | 602 throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier"); |
603 if (%IsJSGlobalProxy(object)) | 603 if (%IsJSGlobalProxy(object)) |
604 throw MakeTypeError(kObserveGlobalProxy, "getNotifier"); | 604 throw MakeTypeError(kObserveGlobalProxy, "getNotifier"); |
605 | 605 |
606 if (ObjectIsFrozen(object)) return null; | 606 if ($objectIsFrozen(object)) return null; |
607 | 607 |
608 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; | 608 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; |
609 | 609 |
610 var getNotifierFn = %GetObjectContextObjectGetNotifier(object); | 610 var getNotifierFn = %GetObjectContextObjectGetNotifier(object); |
611 return getNotifierFn(object); | 611 return getNotifierFn(object); |
612 } | 612 } |
613 | 613 |
614 | 614 |
615 function NativeObjectGetNotifier(object) { | 615 function NativeObjectGetNotifier(object) { |
616 var objectInfo = ObjectInfoGetOrCreate(object); | 616 var objectInfo = ObjectInfoGetOrCreate(object); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 if (!IS_NULL(pendingObservers)) { | 654 if (!IS_NULL(pendingObservers)) { |
655 SetPendingObservers(null); | 655 SetPendingObservers(null); |
656 for (var i in pendingObservers) { | 656 for (var i in pendingObservers) { |
657 CallbackDeliverPending(pendingObservers[i]); | 657 CallbackDeliverPending(pendingObservers[i]); |
658 } | 658 } |
659 } | 659 } |
660 } | 660 } |
661 | 661 |
662 // ------------------------------------------------------------------- | 662 // ------------------------------------------------------------------- |
663 | 663 |
664 InstallFunctions(GlobalObject, DONT_ENUM, [ | 664 $installFunctions(GlobalObject, DONT_ENUM, [ |
665 "deliverChangeRecords", ObjectDeliverChangeRecords, | 665 "deliverChangeRecords", ObjectDeliverChangeRecords, |
666 "getNotifier", ObjectGetNotifier, | 666 "getNotifier", ObjectGetNotifier, |
667 "observe", ObjectObserve, | 667 "observe", ObjectObserve, |
668 "unobserve", ObjectUnobserve | 668 "unobserve", ObjectUnobserve |
669 ]); | 669 ]); |
670 InstallFunctions(GlobalArray, DONT_ENUM, [ | 670 $installFunctions(GlobalArray, DONT_ENUM, [ |
671 "observe", ArrayObserve, | 671 "observe", ArrayObserve, |
672 "unobserve", ArrayUnobserve | 672 "unobserve", ArrayUnobserve |
673 ]); | 673 ]); |
674 InstallFunctions(notifierPrototype, DONT_ENUM, [ | 674 $installFunctions(notifierPrototype, DONT_ENUM, [ |
675 "notify", ObjectNotifierNotify, | 675 "notify", ObjectNotifierNotify, |
676 "performChange", ObjectNotifierPerformChange | 676 "performChange", ObjectNotifierPerformChange |
677 ]); | 677 ]); |
678 | 678 |
679 $observeNotifyChange = NotifyChange; | 679 $observeNotifyChange = NotifyChange; |
680 $observeEnqueueSpliceRecord = EnqueueSpliceRecord; | 680 $observeEnqueueSpliceRecord = EnqueueSpliceRecord; |
681 $observeBeginPerformSplice = BeginPerformSplice; | 681 $observeBeginPerformSplice = BeginPerformSplice; |
682 $observeEndPerformSplice = EndPerformSplice; | 682 $observeEndPerformSplice = EndPerformSplice; |
683 $observeNativeObjectObserve = NativeObjectObserve; | 683 $observeNativeObjectObserve = NativeObjectObserve; |
684 $observeNativeObjectGetNotifier = NativeObjectGetNotifier; | 684 $observeNativeObjectGetNotifier = NativeObjectGetNotifier; |
685 $observeNativeObjectNotifierPerformChange = NativeObjectNotifierPerformChange; | 685 $observeNativeObjectNotifierPerformChange = NativeObjectNotifierPerformChange; |
686 | 686 |
687 })(); | 687 })(); |
OLD | NEW |