Print a test case. Takes a couple of boolean flags, on which the printed Javascript code depends.
(flags)
| 200 | NUM_TESTS_IN_SHARD = 0 |
| 201 | |
| 202 | def printtest(flags): |
| 203 | """Print a test case. Takes a couple of boolean flags, on which the |
| 204 | printed Javascript code depends.""" |
| 205 | |
| 206 | assert all(isinstance(flag, bool) for flag in flags) |
| 207 | |
| 208 | # The alternative flags are in reverse order so that if we take all possible |
| 209 | # tuples, ordered lexicographically from false to true, we get first the |
| 210 | # default, then alternative 1, then 2, etc. |
| 211 | ( |
| 212 | alternativeFn5, # use alternative #5 for returning/throwing: |
| 213 | # return/throw using property |
| 214 | alternativeFn4, # use alternative #4 for returning/throwing: |
| 215 | # return/throw using constructor |
| 216 | alternativeFn3, # use alternative #3 for returning/throwing: |
| 217 | # return/throw indirectly, based on function argument |
| 218 | alternativeFn2, # use alternative #2 for returning/throwing: |
| 219 | # return/throw indirectly in unoptimized code, |
| 220 | # no branching |
| 221 | alternativeFn1, # use alternative #1 for returning/throwing: |
| 222 | # return/throw indirectly, based on boolean arg |
| 223 | tryThrows, # in try block, call throwing function |
| 224 | tryReturns, # in try block, call returning function |
| 225 | tryFirstReturns, # in try block, returning goes before throwing |
| 226 | tryResultToLocal, # in try block, result goes to local variable |
| 227 | doCatch, # include catch block |
| 228 | catchReturns, # in catch block, return |
| 229 | catchWithLocal, # in catch block, modify or return the local variable |
| 230 | catchThrows, # in catch block, throw |
| 231 | doFinally, # include finally block |
| 232 | finallyReturns, # in finally block, return local variable |
| 233 | finallyThrows, # in finally block, throw |
| 234 | endReturnLocal, # at very end, return variable local |
| 235 | deopt, # deopt inside inlined function |
| 236 | ) = flags |
| 237 | |
| 238 | # BASIC RULES |
| 239 | |
| 240 | # Only one alternative can be applied at any time. |
| 241 | if (alternativeFn1 + alternativeFn2 + alternativeFn3 + alternativeFn4 |
| 242 | + alternativeFn5 > 1): |
| 243 | return |
| 244 | |
| 245 | # In try, return or throw, or both. |
| 246 | if not (tryReturns or tryThrows): return |
| 247 | |
| 248 | # Either doCatch or doFinally. |
| 249 | if not doCatch and not doFinally: return |
| 250 | |
| 251 | # Catch flags only make sense when catching |
| 252 | if not doCatch and (catchReturns or catchWithLocal or catchThrows): |
| 253 | return |
| 254 | |
| 255 | # Finally flags only make sense when finallying |
| 256 | if not doFinally and (finallyReturns or finallyThrows): |
| 257 | return |
| 258 | |
| 259 | # tryFirstReturns is only relevant when both tryReturns and tryThrows are |