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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --harmony-observation --harmony-proxies --harmony-collections | 28 // Flags: --harmony-observation --harmony-proxies --harmony-collections --allow- natives-syntax |
Michael Starzinger
2012/12/11 15:20:19
You can have multiple "// Flags:" lines and thereb
rossberg
2012/12/11 15:29:35
Done.
| |
29 | 29 |
30 var allObservers = []; | 30 var allObservers = []; |
31 function reset() { | 31 function reset() { |
32 allObservers.forEach(function(observer) { observer.reset(); }); | 32 allObservers.forEach(function(observer) { observer.reset(); }); |
33 } | 33 } |
34 | 34 |
35 function stringifyNoThrow(arg) { | 35 function stringifyNoThrow(arg) { |
36 try { | 36 try { |
37 return JSON.stringify(arg); | 37 return JSON.stringify(arg); |
38 } catch (e) { | 38 } catch (e) { |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 ]); | 864 ]); |
865 | 865 |
866 // Function.prototype should not be observable except on the object itself | 866 // Function.prototype should not be observable except on the object itself |
867 reset(); | 867 reset(); |
868 var fun = function(){}; | 868 var fun = function(){}; |
869 var obj = { __proto__: fun }; | 869 var obj = { __proto__: fun }; |
870 Object.observe(obj, observer.callback); | 870 Object.observe(obj, observer.callback); |
871 obj.prototype = 7; | 871 obj.prototype = 7; |
872 Object.deliverChangeRecords(observer.callback); | 872 Object.deliverChangeRecords(observer.callback); |
873 observer.assertNotCalled(); | 873 observer.assertNotCalled(); |
874 | |
875 | |
876 // Check that changes in observation status are detected in all IC states and | |
877 // in optimized code, especially in cases usually using fast elements. | |
878 function TestFastElements(prepopulate, polymorphic, optimize) { | |
879 var setElement = eval( | |
880 "(function setElement(a, i, v) { a[i] = v " + | |
881 "/* " + prepopulate + " " + polymorphic + " " + optimize + " */" + | |
882 "})" | |
883 ); | |
884 print("TestFastElements:", setElement); | |
885 | |
886 var arr = prepopulate ? [1, 2, 3, 4, 5] : [0]; | |
887 setElement(arr, 1, 210); | |
888 setElement(arr, 1, 211); | |
889 if (polymorphic) setElement(["M", "i", "l", "n", "e", "r"], 0, "m"); | |
890 if (optimize) %OptimizeFunctionOnNextCall(setElement); | |
891 setElement(arr, 1, 212); | |
892 | |
893 reset(); | |
894 Object.observe(arr, observer.callback); | |
895 setElement(arr, 1, 989898); | |
896 Object.deliverChangeRecords(observer.callback); | |
897 observer.assertCallbackRecords([ | |
898 { object: arr, name: '1', type: 'updated', oldValue: 212 } | |
899 ]); | |
900 } | |
901 | |
902 for (var b1 = 0; b1 < 2; ++b1) | |
903 for (var b2 = 0; b2 < 2; ++b2) | |
904 for (var b3 = 0; b3 < 2; ++b3) | |
905 TestFastElements(b1 != 0, b2 != 0, b3 != 0); | |
906 | |
907 | |
908 function TestFastElementsLength(polymorphic, optimize, oldSize, newSize) { | |
909 var setLength = eval( | |
910 "(function setLength(a, n) { a.length = n " + | |
911 "/* " + polymorphic + " " + optimize + " " + oldSize + " " + newSize + " */" | |
912 + "})" | |
913 ); | |
914 print("TestFastElementsLength:", setLength); | |
915 | |
916 function array(n) { | |
917 var arr = new Array(n); | |
918 for (var i = 0; i < n; ++i) arr[i] = i; | |
919 return arr; | |
920 } | |
921 | |
922 setLength(array(oldSize), newSize); | |
923 setLength(array(oldSize), newSize); | |
924 if (polymorphic) setLength(array(oldSize).map(isNaN), newSize); | |
925 if (optimize) %OptimizeFunctionOnNextCall(setLength); | |
926 setLength(array(oldSize), newSize); | |
927 | |
928 reset(); | |
929 var arr = array(oldSize); | |
930 Object.observe(arr, observer.callback); | |
931 setLength(arr, newSize); | |
932 Object.deliverChangeRecords(observer.callback); | |
933 if (oldSize === newSize) { | |
934 observer.assertNotCalled(); | |
935 } else { | |
936 var count = oldSize > newSize ? oldSize - newSize : 0; | |
937 observer.assertRecordCount(count + 1); | |
938 var lengthRecord = observer.records[count]; | |
939 assertSame(arr, lengthRecord.object); | |
940 assertEquals('length', lengthRecord.name); | |
941 assertEquals('updated', lengthRecord.type); | |
942 assertSame(oldSize, lengthRecord.oldValue); | |
943 } | |
944 } | |
945 | |
946 for (var b1 = 0; b1 < 2; ++b1) | |
947 for (var b2 = 0; b2 < 2; ++b2) | |
948 for (var n1 = 0; n1 < 3; ++n1) | |
949 for (var n2 = 0; n2 < 3; ++n2) | |
950 TestFastElementsLength(b1 != 0, b2 != 0, 20*n1, 20*n2); | |
OLD | NEW |