Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 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 --inline-accessors | |
| 29 | |
| 30 var accessorCallCount, setterArgument, setterValue, obj, forceDeopt; | |
| 31 | |
| 32 // ----------------------------------------------------------------------------- | |
| 33 // Helpers for testing inlining of getters. | |
| 34 | |
| 35 function TestInlinedGetter(context, expected) { | |
| 36 forceDeopt = 0; | |
| 37 accessorCallCount = 0; | |
| 38 | |
| 39 assertEquals(expected, context()); | |
| 40 assertEquals(1, accessorCallCount); | |
| 41 | |
| 42 assertEquals(expected, context()); | |
| 43 assertEquals(2, accessorCallCount); | |
| 44 | |
| 45 %OptimizeFunctionOnNextCall(context); | |
| 46 assertEquals(expected, context()); | |
| 47 assertEquals(3, accessorCallCount); | |
| 48 | |
| 49 %DeoptimizeFunction(context); | |
| 50 %ClearFunctionTypeFeedback(context); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 function TestGetterInAllContexts(obj, expected) { | |
| 55 function value_context() { | |
| 56 return obj.getterProperty; | |
| 57 } | |
| 58 TestInlinedGetter(value_context, expected); | |
| 59 | |
| 60 function test_context() { | |
| 61 if (obj.getterProperty) { | |
| 62 return 111; | |
| 63 } else { | |
| 64 return 222; | |
| 65 } | |
| 66 } | |
| 67 TestInlinedGetter(test_context, expected ? 111 : 222); | |
| 68 | |
| 69 function effect_context() { | |
| 70 obj.getterProperty; | |
| 71 return 5678; | |
| 72 } | |
| 73 TestInlinedGetter(effect_context, 5678); | |
| 74 } | |
| 75 | |
| 76 // ----------------------------------------------------------------------------- | |
| 77 // Test getter returning something 'true'ish in all contexts. | |
| 78 | |
| 79 function getter1() { | |
| 80 assertEquals(obj, this); | |
|
Michael Starzinger
2012/08/09 12:20:55
I would really use assertSame() here instead, beca
Sven Panne
2012/08/09 14:06:37
Done.
| |
| 81 accessorCallCount++; | |
| 82 forceDeopt + 1; | |
| 83 return 1234; | |
| 84 } | |
| 85 | |
| 86 function ConstrG1() { } | |
| 87 obj = Object.defineProperty(new ConstrG1(), "getterProperty", { get: getter1 }); | |
| 88 TestGetterInAllContexts(obj, 1234); | |
| 89 TestGetterInAllContexts(Object.create(obj), 1234); | |
| 90 | |
| 91 // ----------------------------------------------------------------------------- | |
| 92 // Test getter returning false in all contexts. | |
| 93 | |
| 94 function getter2() { | |
| 95 assertEquals(obj, this); | |
| 96 accessorCallCount++; | |
| 97 forceDeopt + 1; | |
| 98 return false; | |
| 99 } | |
| 100 | |
| 101 function ConstrG2() { } | |
| 102 obj = Object.defineProperty(new ConstrG2(), "getterProperty", { get: getter2 }); | |
| 103 TestGetterInAllContexts(obj, false); | |
| 104 TestGetterInAllContexts(Object.create(obj), false); | |
| 105 | |
| 106 // ----------------------------------------------------------------------------- | |
| 107 // Test getter without a return in all contexts. | |
| 108 | |
| 109 function getter3() { | |
| 110 assertEquals(obj, this); | |
| 111 accessorCallCount++; | |
| 112 forceDeopt + 1; | |
| 113 } | |
| 114 | |
| 115 function ConstrG3() { } | |
| 116 obj = Object.defineProperty(new ConstrG3(), "getterProperty", { get: getter3 }); | |
| 117 TestGetterInAllContexts(obj, undefined); | |
| 118 TestGetterInAllContexts(Object.create(obj), undefined); | |
| 119 | |
| 120 // ----------------------------------------------------------------------------- | |
| 121 // Test getter with a mismatch in the number of arguments in all contexts. | |
| 122 | |
| 123 function getter4(a) { | |
| 124 assertEquals(obj, this); | |
| 125 assertEquals(undefined, a); | |
| 126 accessorCallCount++; | |
| 127 forceDeopt + 1; | |
| 128 return 9876; | |
| 129 } | |
| 130 | |
| 131 function ConstrG4() { } | |
| 132 obj = Object.defineProperty(new ConstrG4(), "getterProperty", { get: getter4 }); | |
| 133 TestGetterInAllContexts(obj, 9876); | |
| 134 TestGetterInAllContexts(Object.create(obj), 9876); | |
| 135 | |
| 136 // ----------------------------------------------------------------------------- | |
| 137 // Helpers for testing inlining of setters. | |
| 138 | |
| 139 function TestInlinedSetter(context, value, expected) { | |
| 140 forceDeopt = 0; | |
| 141 accessorCallCount = 0; | |
| 142 setterArgument = value; | |
| 143 | |
| 144 assertEquals(expected, context(value)); | |
| 145 assertEquals(value, setterValue); | |
| 146 assertEquals(1, accessorCallCount); | |
| 147 | |
| 148 assertEquals(expected, context(value)); | |
| 149 assertEquals(value, setterValue); | |
| 150 assertEquals(2, accessorCallCount); | |
| 151 | |
| 152 %OptimizeFunctionOnNextCall(context); | |
| 153 assertEquals(expected, context(value)); | |
| 154 assertEquals(value, setterValue); | |
| 155 assertEquals(3, accessorCallCount); | |
| 156 | |
| 157 %DeoptimizeFunction(context); | |
| 158 %ClearFunctionTypeFeedback(context); | |
| 159 } | |
| 160 | |
| 161 function TestSetterInAllContexts(obj) { | |
| 162 function value_context(value) { | |
| 163 return obj.setterProperty = value; | |
| 164 } | |
| 165 TestInlinedSetter(value_context, 111, 111); | |
| 166 | |
| 167 function test_context(value) { | |
| 168 if (obj.setterProperty = value) { | |
| 169 return 333; | |
| 170 } else { | |
| 171 return 444; | |
| 172 } | |
| 173 } | |
| 174 TestInlinedSetter(test_context, true, 333); | |
| 175 TestInlinedSetter(test_context, false, 444); | |
| 176 | |
| 177 function effect_context(value) { | |
| 178 obj.setterProperty = value; | |
| 179 return 666; | |
| 180 } | |
| 181 TestInlinedSetter(effect_context, 555, 666); | |
| 182 } | |
| 183 | |
| 184 // ----------------------------------------------------------------------------- | |
| 185 // Test setter returning nothing in all contexts. | |
| 186 | |
| 187 function setter1(value) { | |
| 188 assertEquals(obj, this); | |
| 189 accessorCallCount++; | |
| 190 forceDeopt + 1; | |
| 191 setterValue = value; | |
| 192 } | |
| 193 | |
| 194 function ConstrS1() { } | |
| 195 obj = Object.defineProperty(new ConstrS1(), "setterProperty", { set: setter1 }); | |
| 196 TestSetterInAllContexts(obj); | |
| 197 TestSetterInAllContexts(Object.create(obj)); | |
| 198 | |
| 199 // ----------------------------------------------------------------------------- | |
| 200 // Test setter returning something different than the RHS in all contexts. | |
| 201 | |
| 202 function setter2(value) { | |
| 203 assertEquals(obj, this); | |
| 204 accessorCallCount++; | |
| 205 forceDeopt + 1; | |
| 206 setterValue = value; | |
| 207 return 1000000; | |
| 208 } | |
| 209 | |
| 210 function ConstrS2() { } | |
| 211 obj = Object.defineProperty(new ConstrS2(), "setterProperty", { set: setter2 }); | |
| 212 TestSetterInAllContexts(obj); | |
| 213 TestSetterInAllContexts(Object.create(obj)); | |
| 214 | |
| 215 // ----------------------------------------------------------------------------- | |
| 216 // Test setter with too few arguments in all contexts. | |
| 217 | |
| 218 function setter3() { | |
| 219 assertEquals(obj, this); | |
| 220 accessorCallCount++; | |
| 221 forceDeopt + 1; | |
| 222 setterValue = setterArgument; | |
| 223 return 1000000; | |
| 224 } | |
| 225 | |
| 226 function ConstrS3() { } | |
| 227 obj = Object.defineProperty(new ConstrS3(), "setterProperty", { set: setter3 }); | |
| 228 TestSetterInAllContexts(obj); | |
| 229 TestSetterInAllContexts(Object.create(obj)); | |
| 230 | |
| 231 // ----------------------------------------------------------------------------- | |
| 232 // Test setter with too many arguments in all contexts. | |
| 233 | |
| 234 function setter4(value, foo) { | |
| 235 assertEquals(obj, this); | |
| 236 assertEquals(undefined, foo); | |
| 237 accessorCallCount++; | |
| 238 forceDeopt + 1; | |
| 239 setterValue = value; | |
| 240 return 1000000; | |
| 241 } | |
| 242 | |
| 243 function ConstrS4() { } | |
| 244 obj = Object.defineProperty(new ConstrS4(), "setterProperty", { set: setter4 }); | |
| 245 TestSetterInAllContexts(obj); | |
| 246 TestSetterInAllContexts(Object.create(obj)); | |
| OLD | NEW |