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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 type: 'updated', | 252 type: 'updated', |
253 }); | 253 }); |
254 Object.observe(obj, observer.callback); | 254 Object.observe(obj, observer.callback); |
255 Object.getNotifier(obj).notify({ | 255 Object.getNotifier(obj).notify({ |
256 type: 'updated', | 256 type: 'updated', |
257 }); | 257 }); |
258 records = undefined; | 258 records = undefined; |
259 Object.deliverChangeRecords(observer.callback); | 259 Object.deliverChangeRecords(observer.callback); |
260 observer.assertRecordCount(1); | 260 observer.assertRecordCount(1); |
261 | 261 |
262 // Get notifier prior to observing | |
263 reset(); | |
264 var obj = {}; | |
265 Object.getNotifier(obj); | |
266 Object.observe(obj, observer.callback); | |
267 obj.id = 1; | |
268 Object.deliverChangeRecords(observer.callback); | |
269 observer.assertCallbackRecords([ | |
270 { object: obj, type: 'new', name: 'id' }, | |
271 ]); | |
272 | 262 |
273 // Observing a continuous stream of changes, while itermittantly unobserving. | 263 // Observing a continuous stream of changes, while itermittantly unobserving. |
274 reset(); | 264 reset(); |
275 Object.observe(obj, observer.callback); | 265 Object.observe(obj, observer.callback); |
276 Object.getNotifier(obj).notify({ | 266 Object.getNotifier(obj).notify({ |
277 type: 'updated', | 267 type: 'updated', |
278 val: 1 | 268 val: 1 |
279 }); | 269 }); |
280 | 270 |
281 Object.unobserve(obj, observer.callback); | 271 Object.unobserve(obj, observer.callback); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 function recursiveObserver2(r) { | 629 function recursiveObserver2(r) { |
640 recordCount += r.length; | 630 recordCount += r.length; |
641 if (r[0].oldValue < 100) { | 631 if (r[0].oldValue < 100) { |
642 ++obj1.a; | 632 ++obj1.a; |
643 ++obj2.a; | 633 ++obj2.a; |
644 } | 634 } |
645 } | 635 } |
646 Object.observe(obj1, recursiveObserver2); | 636 Object.observe(obj1, recursiveObserver2); |
647 Object.observe(obj2, recursiveObserver2); | 637 Object.observe(obj2, recursiveObserver2); |
648 ++obj1.a; | 638 ++obj1.a; |
| 639 Object.deliverChangeRecords(recursiveObserver2); |
649 // TODO(verwaest): Disabled because of bug 2774. | 640 // TODO(verwaest): Disabled because of bug 2774. |
650 // Object.deliverChangeRecords(recursiveObserver2); | |
651 // assertEquals(199, recordCount); | 641 // assertEquals(199, recordCount); |
652 | 642 |
653 | 643 |
654 // Observing named properties. | 644 // Observing named properties. |
655 reset(); | 645 reset(); |
656 var obj = {a: 1} | 646 var obj = {a: 1} |
657 Object.observe(obj, observer.callback); | 647 Object.observe(obj, observer.callback); |
658 obj.a = 2; | 648 obj.a = 2; |
659 obj["a"] = 3; | 649 obj["a"] = 3; |
660 delete obj.a; | 650 delete obj.a; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 delete obj[symbol]; | 776 delete obj[symbol]; |
787 obj.__defineSetter__(symbol, function() {}); | 777 obj.__defineSetter__(symbol, function() {}); |
788 obj.__defineGetter__(symbol, function() {}); | 778 obj.__defineGetter__(symbol, function() {}); |
789 Object.deliverChangeRecords(observer.callback); | 779 Object.deliverChangeRecords(observer.callback); |
790 observer.assertNotCalled(); | 780 observer.assertNotCalled(); |
791 | 781 |
792 | 782 |
793 // Test all kinds of objects generically. | 783 // Test all kinds of objects generically. |
794 function TestObserveConfigurable(obj, prop) { | 784 function TestObserveConfigurable(obj, prop) { |
795 reset(); | 785 reset(); |
796 Object.observe(obj, observer.callback); | |
797 Object.unobserve(obj, observer.callback); | |
798 obj[prop] = 1; | 786 obj[prop] = 1; |
799 Object.observe(obj, observer.callback); | 787 Object.observe(obj, observer.callback); |
800 obj[prop] = 2; | 788 obj[prop] = 2; |
801 obj[prop] = 3; | 789 obj[prop] = 3; |
802 delete obj[prop]; | 790 delete obj[prop]; |
803 obj[prop] = 4; | 791 obj[prop] = 4; |
804 obj[prop] = 4; // ignored | 792 obj[prop] = 4; // ignored |
805 obj[prop] = 5; | 793 obj[prop] = 5; |
806 Object.defineProperty(obj, prop, {value: 6}); | 794 Object.defineProperty(obj, prop, {value: 6}); |
807 Object.defineProperty(obj, prop, {writable: false}); | 795 Object.defineProperty(obj, prop, {writable: false}); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 { object: obj, name: prop, type: "updated", oldValue: 12 }, | 845 { object: obj, name: prop, type: "updated", oldValue: 12 }, |
858 { object: obj, name: prop, type: "deleted", oldValue: 36 }, | 846 { object: obj, name: prop, type: "deleted", oldValue: 36 }, |
859 { object: obj, name: prop, type: "new" }, | 847 { object: obj, name: prop, type: "new" }, |
860 ]); | 848 ]); |
861 Object.unobserve(obj, observer.callback); | 849 Object.unobserve(obj, observer.callback); |
862 delete obj[prop]; | 850 delete obj[prop]; |
863 } | 851 } |
864 | 852 |
865 function TestObserveNonConfigurable(obj, prop, desc) { | 853 function TestObserveNonConfigurable(obj, prop, desc) { |
866 reset(); | 854 reset(); |
867 Object.observe(obj, observer.callback); | |
868 Object.unobserve(obj, observer.callback); | |
869 obj[prop] = 1; | 855 obj[prop] = 1; |
870 Object.observe(obj, observer.callback); | 856 Object.observe(obj, observer.callback); |
871 obj[prop] = 4; | 857 obj[prop] = 4; |
872 obj[prop] = 4; // ignored | 858 obj[prop] = 4; // ignored |
873 obj[prop] = 5; | 859 obj[prop] = 5; |
874 Object.defineProperty(obj, prop, {value: 6}); | 860 Object.defineProperty(obj, prop, {value: 6}); |
875 Object.defineProperty(obj, prop, {value: 6}); // ignored | 861 Object.defineProperty(obj, prop, {value: 6}); // ignored |
876 Object.defineProperty(obj, prop, {value: 7}); | 862 Object.defineProperty(obj, prop, {value: 7}); |
877 Object.defineProperty(obj, prop, {enumerable: desc.enumerable}); // ignored | 863 Object.defineProperty(obj, prop, {enumerable: desc.enumerable}); // ignored |
878 Object.defineProperty(obj, prop, {writable: false}); | 864 Object.defineProperty(obj, prop, {writable: false}); |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 for (var n1 = 0; n1 < 3; ++n1) | 1512 for (var n1 = 0; n1 < 3; ++n1) |
1527 for (var n2 = 0; n2 < 3; ++n2) | 1513 for (var n2 = 0; n2 < 3; ++n2) |
1528 for (var i in mutation) | 1514 for (var i in mutation) |
1529 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1515 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); |
1530 | 1516 |
1531 for (var b1 = 0; b1 < 2; ++b1) | 1517 for (var b1 = 0; b1 < 2; ++b1) |
1532 for (var b2 = 0; b2 < 2; ++b2) | 1518 for (var b2 = 0; b2 < 2; ++b2) |
1533 for (var n = 0; n < 3; ++n) | 1519 for (var n = 0; n < 3; ++n) |
1534 for (var i in mutationByIncr) | 1520 for (var i in mutationByIncr) |
1535 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1521 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); |
OLD | NEW |