| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 // Flags: --strong-mode --allow-natives-syntax | 5 // Flags: --strong-mode --allow-natives-syntax |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 // TODO(conradw): Implement other strong operators | 9 // Boolean indicates whether an operator can be part of a compound assignment. |
| 10 let strongNumberBinops = [ | 10 let strongNumberBinops = [ |
| 11 "-", | 11 ["-", true], |
| 12 "*", | 12 ["*", true], |
| 13 "/", | 13 ["/", true], |
| 14 "%", | 14 ["%", true], |
| 15 "|", | 15 ["|", true], |
| 16 "&", | 16 ["&", true], |
| 17 "^", | 17 ["^", true], |
| 18 "<<", | 18 ["<<", true], |
| 19 ">>", | 19 [">>", true], |
| 20 ">>>", | 20 [">>>", true] |
| 21 ]; | 21 ]; |
| 22 | 22 |
| 23 let strongStringOrNumberBinops = [ | 23 let strongStringOrNumberBinops = [ |
| 24 "+" | 24 ["+", true], |
| 25 ["<", false], |
| 26 [">", false], |
| 27 ["<=", false], |
| 28 [">=", false] |
| 25 ]; | 29 ]; |
| 26 | 30 |
| 27 let strongBinops = strongNumberBinops.concat(strongStringOrNumberBinops); | 31 let strongBinops = strongNumberBinops.concat(strongStringOrNumberBinops); |
| 28 | 32 |
| 29 let strongUnops = [ | 33 let strongUnops = [ |
| 30 "~", | 34 "~", |
| 31 "+", | 35 "+", |
| 32 "-" | 36 "-" |
| 33 ]; | 37 ]; |
| 34 | 38 |
| 35 let nonStringOrNumberValues = [ | 39 let nonStringOrNumberValues = [ |
| 40 "null", |
| 41 "undefined", |
| 36 "{}", | 42 "{}", |
| 37 "false", | 43 "false", |
| 38 "(function(){})", | 44 "(function(){})", |
| 39 "[]", | 45 "[]", |
| 40 "(class Foo {})" | 46 "(class Foo {})" |
| 41 ]; | 47 ]; |
| 42 | 48 |
| 43 let stringValues = [ | 49 let stringValues = [ |
| 44 "''", | 50 "''", |
| 45 "' '", | 51 "' '", |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 function shr_strong(x, y) { | 131 function shr_strong(x, y) { |
| 126 "use strong"; | 132 "use strong"; |
| 127 return x >> y; | 133 return x >> y; |
| 128 } | 134 } |
| 129 | 135 |
| 130 function sar_strong(x, y) { | 136 function sar_strong(x, y) { |
| 131 "use strong"; | 137 "use strong"; |
| 132 return x >>> y; | 138 return x >>> y; |
| 133 } | 139 } |
| 134 | 140 |
| 141 function less_strong(x, y) { |
| 142 "use strong"; |
| 143 return x < y; |
| 144 } |
| 145 |
| 146 function less_num_strong(x, y) { |
| 147 "use strong"; |
| 148 return x < y; |
| 149 } |
| 150 |
| 151 function greater_strong(x, y) { |
| 152 "use strong"; |
| 153 return x > y; |
| 154 } |
| 155 |
| 156 function greater_num_strong(x, y) { |
| 157 "use strong"; |
| 158 return x > y; |
| 159 } |
| 160 |
| 161 function less_equal_strong(x, y) { |
| 162 "use strong"; |
| 163 return x <= y; |
| 164 } |
| 165 |
| 166 function less_equal_num_strong(x, y) { |
| 167 "use strong"; |
| 168 return x <= y; |
| 169 } |
| 170 |
| 171 function greater_equal_strong(x, y) { |
| 172 "use strong"; |
| 173 return x >= y; |
| 174 } |
| 175 |
| 176 function greater_equal_num_strong(x, y) { |
| 177 "use strong"; |
| 178 return x >= y; |
| 179 } |
| 180 |
| 135 function typed_add_strong(x, y) { | 181 function typed_add_strong(x, y) { |
| 136 "use strong"; | 182 "use strong"; |
| 137 return (+x) + (+y); | 183 return (+x) + (+y); |
| 138 } | 184 } |
| 139 | 185 |
| 140 function typed_sub_strong(x, y) { | 186 function typed_sub_strong(x, y) { |
| 141 "use strong"; | 187 "use strong"; |
| 142 return (+x) - (+y); | 188 return (+x) - (+y); |
| 143 } | 189 } |
| 144 | 190 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 function typed_shr_strong(x, y) { | 226 function typed_shr_strong(x, y) { |
| 181 "use strong"; | 227 "use strong"; |
| 182 return (+x) >> (+y); | 228 return (+x) >> (+y); |
| 183 } | 229 } |
| 184 | 230 |
| 185 function typed_sar_strong(x, y) { | 231 function typed_sar_strong(x, y) { |
| 186 "use strong"; | 232 "use strong"; |
| 187 return (+x) >>> (+y); | 233 return (+x) >>> (+y); |
| 188 } | 234 } |
| 189 | 235 |
| 236 function typed_less_strong(x, y) { |
| 237 "use strong"; |
| 238 return (+x) < (+y); |
| 239 } |
| 240 |
| 241 function typed_greater_strong(x, y) { |
| 242 "use strong"; |
| 243 return (+x) > (+y); |
| 244 } |
| 245 |
| 246 function typed_less_equal_strong(x, y) { |
| 247 "use strong"; |
| 248 return (+x) <= (+y); |
| 249 } |
| 250 |
| 251 function typed_greater_equal_strong(x, y) { |
| 252 "use strong"; |
| 253 return (+x) >= (+y); |
| 254 } |
| 255 |
| 190 let strongNumberFuncs = [add_num_strong, sub_strong, mul_strong, div_strong, | 256 let strongNumberFuncs = [add_num_strong, sub_strong, mul_strong, div_strong, |
| 191 mod_strong, or_strong, and_strong, xor_strong, | 257 mod_strong, or_strong, and_strong, xor_strong, |
| 192 shl_strong, shr_strong, sar_strong, typed_add_strong, | 258 shl_strong, shr_strong, sar_strong, less_num_strong, |
| 259 greater_num_strong, less_equal_num_strong, |
| 260 greater_equal_num_strong, typed_add_strong, |
| 193 typed_sub_strong, typed_mul_strong, typed_div_strong, | 261 typed_sub_strong, typed_mul_strong, typed_div_strong, |
| 194 typed_mod_strong, typed_or_strong, typed_and_strong, | 262 typed_mod_strong, typed_or_strong, typed_and_strong, |
| 195 typed_xor_strong, typed_shl_strong, typed_shr_strong, | 263 typed_xor_strong, typed_shl_strong, typed_shr_strong, |
| 196 typed_sar_strong]; | 264 typed_sar_strong, typed_less_strong, |
| 265 typed_greater_strong, typed_less_equal_strong, |
| 266 typed_greater_equal_strong]; |
| 197 | 267 |
| 198 let strongStringOrNumberFuncs = [add_strong]; | 268 let strongStringOrNumberFuncs = [add_strong, less_strong, greater_strong, |
| 269 less_equal_strong, greater_equal_strong]; |
| 199 | 270 |
| 200 let strongFuncs = strongNumberFuncs.concat(strongStringOrNumberFuncs); | 271 let strongFuncs = strongNumberFuncs.concat(strongStringOrNumberFuncs); |
| 201 | 272 |
| 202 function assertStrongNonThrowBehaviour(expr) { | 273 function assertStrongNonThrowBehaviour(expr) { |
| 203 assertEquals(eval(expr), eval("'use strong';" + expr)); | 274 assertEquals(eval(expr), eval("'use strong';" + expr)); |
| 204 assertDoesNotThrow("'use strong'; " + expr + ";"); | 275 assertDoesNotThrow("'use strong'; " + expr + ";"); |
| 205 assertDoesNotThrow("'use strong'; let v = " + expr + ";"); | 276 assertDoesNotThrow("'use strong'; let v = " + expr + ";"); |
| 206 } | 277 } |
| 207 | 278 |
| 208 function assertStrongThrowBehaviour(expr) { | 279 function assertStrongThrowBehaviour(expr) { |
| 209 assertDoesNotThrow("'use strict'; " + expr + ";"); | 280 assertDoesNotThrow("'use strict'; " + expr + ";"); |
| 210 assertDoesNotThrow("'use strict'; let v = " + expr + ";"); | 281 assertDoesNotThrow("'use strict'; let v = " + expr + ";"); |
| 211 assertThrows("'use strong'; " + expr + ";", TypeError); | 282 assertThrows("'use strong'; " + expr + ";", TypeError); |
| 212 assertThrows("'use strong'; let v = " + expr + ";", TypeError); | 283 assertThrows("'use strong'; let v = " + expr + ";", TypeError); |
| 213 } | 284 } |
| 214 | 285 |
| 215 function checkArgumentCombinations(op, leftList, rightList, willThrow) { | 286 function checkArgumentCombinations(op, leftList, rightList, willThrow) { |
| 216 for (let v1 of leftList) { | 287 for (let v1 of leftList) { |
| 217 let assignExpr = "foo " + op + "= " + v1 + ";"; | 288 let assignExpr = "foo " + op[0] + "= " + v1 + ";"; |
| 218 for (let v2 of rightList) { | 289 for (let v2 of rightList) { |
| 219 let compoundAssignment = "'use strong'; let foo = " + v2 + "; " + | 290 let compoundAssignment = "'use strong'; let foo = " + v2 + "; " + |
| 220 assignExpr; | 291 assignExpr; |
| 221 if(willThrow) { | 292 if (willThrow) { |
| 222 assertThrows(compoundAssignment, TypeError); | 293 if (op[1]) { |
| 223 assertStrongThrowBehaviour("(" + v1 + op + v2 + ")"); | 294 assertThrows(compoundAssignment, TypeError); |
| 295 } |
| 296 assertStrongThrowBehaviour("(" + v1 + op[0] + v2 + ")"); |
| 224 } else { | 297 } else { |
| 225 assertDoesNotThrow(compoundAssignment); | 298 if (op[1]) { |
| 226 assertStrongNonThrowBehaviour("(" + v1 + op + v2 + ")"); | 299 assertDoesNotThrow(compoundAssignment); |
| 300 } |
| 301 assertStrongNonThrowBehaviour("(" + v1 + op[0] + v2 + ")"); |
| 227 } | 302 } |
| 228 } | 303 } |
| 229 } | 304 } |
| 230 } | 305 } |
| 231 | 306 |
| 232 for (let op of strongBinops) { | 307 for (let op of strongBinops) { |
| 233 checkArgumentCombinations(op, numberValues, numberValues, false); | 308 checkArgumentCombinations(op, numberValues, numberValues, false); |
| 234 checkArgumentCombinations(op, numberValues, nonNumberValues, true); | 309 checkArgumentCombinations(op, numberValues, nonNumberValues, true); |
| 235 } | 310 } |
| 236 | 311 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 assertThrows(function(){func(2, "foo");}, TypeError); | 366 assertThrows(function(){func(2, "foo");}, TypeError); |
| 292 %DeoptimizeFunction(func); | 367 %DeoptimizeFunction(func); |
| 293 func(NaN, NaN); | 368 func(NaN, NaN); |
| 294 func(NaN, NaN); | 369 func(NaN, NaN); |
| 295 // Check IC Generic*Generic->Generic throws | 370 // Check IC Generic*Generic->Generic throws |
| 296 assertThrows(function(){func(2, "foo");}, TypeError); | 371 assertThrows(function(){func(2, "foo");}, TypeError); |
| 297 %OptimizeFunctionOnNextCall(func); | 372 %OptimizeFunctionOnNextCall(func); |
| 298 assertThrows(function(){func(2, "foo");}, TypeError); | 373 assertThrows(function(){func(2, "foo");}, TypeError); |
| 299 %DeoptimizeFunction(func); | 374 %DeoptimizeFunction(func); |
| 300 } | 375 } |
| OLD | NEW |