Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
|
Toon Verwaest
2013/06/12 17:26:01
2013
mvstanton
2013/06/12 17:58:12
Done.
| |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 27 | |
| 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc | |
| 29 // Flags: --track-allocation-sites --noalways-opt | |
| 30 | |
| 31 // Test element kind of objects. | |
| 32 // Since --smi-only-arrays affects builtins, its default setting at compile | |
| 33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | |
| 34 // by default, only a no-snapshot build actually has smi-only arrays enabled | |
| 35 // in this test case. Depending on whether smi-only arrays are actually | |
| 36 // enabled, this test takes the appropriate code path to check smi-only arrays. | |
| 37 | |
| 38 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | |
| 39 support_smi_only_arrays = true; | |
| 40 optimize_constructed_arrays = true; | |
| 41 | |
| 42 if (support_smi_only_arrays) { | |
| 43 print("Tests include smi-only arrays."); | |
| 44 } else { | |
| 45 print("Tests do NOT include smi-only arrays."); | |
| 46 } | |
| 47 | |
| 48 var elements_kind = { | |
| 49 fast_smi_only : 'fast smi only elements', | |
| 50 fast : 'fast elements', | |
| 51 fast_double : 'fast double elements', | |
| 52 dictionary : 'dictionary elements', | |
| 53 external_byte : 'external byte elements', | |
| 54 external_unsigned_byte : 'external unsigned byte elements', | |
| 55 external_short : 'external short elements', | |
| 56 external_unsigned_short : 'external unsigned short elements', | |
| 57 external_int : 'external int elements', | |
| 58 external_unsigned_int : 'external unsigned int elements', | |
| 59 external_float : 'external float elements', | |
| 60 external_double : 'external double elements', | |
| 61 external_pixel : 'external pixel elements' | |
| 62 } | |
| 63 | |
| 64 function getKind(obj) { | |
| 65 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; | |
| 66 if (%HasFastObjectElements(obj)) return elements_kind.fast; | |
| 67 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; | |
| 68 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; | |
| 69 } | |
| 70 | |
| 71 function isHoley(obj) { | |
| 72 if (%HasFastHoleyElements(obj)) return true; | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 function assertKind(expected, obj, name_opt) { | |
| 77 if (!support_smi_only_arrays && | |
| 78 expected == elements_kind.fast_smi_only) { | |
| 79 expected = elements_kind.fast; | |
| 80 } | |
| 81 assertEquals(expected, getKind(obj), name_opt); | |
| 82 } | |
| 83 | |
| 84 function assertHoley(obj, name_opt) { | |
| 85 assertEquals(true, isHoley(obj), name_opt); | |
| 86 } | |
| 87 | |
| 88 function assertNotHoley(obj, name_opt) { | |
| 89 assertEquals(false, isHoley(obj), name_opt); | |
| 90 } | |
| 91 | |
| 92 if (support_smi_only_arrays) { | |
| 93 function create_array(arg) { | |
| 94 var a = new Array(arg); | |
| 95 return a; | |
| 96 } | |
| 97 | |
| 98 obj = create_array(0); | |
| 99 assertNotHoley(obj); | |
| 100 create_array(0); | |
| 101 %OptimizeFunctionOnNextCall(create_array); | |
| 102 obj = create_array(10); | |
| 103 assertHoley(obj); | |
| 104 } | |
| 105 | |
| 106 // The code below would assert in debug or crash in release | |
| 107 function f(length) { | |
| 108 return new Array(length) | |
| 109 } | |
| 110 | |
| 111 f(0); | |
| 112 f(0); | |
| 113 %OptimizeFunctionOnNextCall(f); | |
| 114 var a = f(10); | |
| 115 | |
| 116 function g(a) { | |
| 117 return a[0]; | |
| 118 } | |
| 119 | |
| 120 var b = [0]; | |
| 121 g(b); | |
| 122 g(b); | |
| 123 %OptimizeFunctionOnNextCall(f); | |
|
Toon Verwaest
2013/06/12 17:26:01
You can remove this line I presume, since you are
mvstanton
2013/06/12 17:58:12
Done.
| |
| 124 assertEquals(undefined, g(a)); | |
| OLD | NEW |