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