| 1 |
// |reftest| async |
| 2 |
// Copyright (C) 2024 Richard Gibson. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
/*--- |
| 5 |
esid: prod-ConditionalExpression |
| 6 |
description: > |
| 7 |
await binds more tightly than conditional operators |
| 8 |
info: | |
| 9 |
ConditionalExpression[In, Yield, Await] : |
| 10 |
ShortCircuitExpression[?In, ?Yield, ?Await] |
| 11 |
ShortCircuitExpression[?In, ?Yield, ?Await] `?` AssignmentExpression[+In, ?Yield, ?Await] `:` AssignmentExpression[?In, ?Yield, ?Await] |
| 12 |
|
| 13 |
ShortCircuitExpression[In, Yield, Await] : |
| 14 |
LogicalORExpression[?In, ?Yield, ?Await] |
| 15 |
CoalesceExpression[?In, ?Yield, ?Await] |
| 16 |
|
| 17 |
LogicalORExpression[In, Yield, Await] : |
| 18 |
LogicalANDExpression[?In, ?Yield, ?Await] |
| 19 |
LogicalORExpression[?In, ?Yield, ?Await] `||` LogicalANDExpression[?In, ?Yield, ?Await] |
| 20 |
|
| 21 |
LogicalANDExpression[In, Yield, Await] : |
| 22 |
BitwiseORExpression[?In, ?Yield, ?Await] |
| 23 |
LogicalANDExpression[?In, ?Yield, ?Await] `&&` BitwiseORExpression[?In, ?Yield, ?Await] |
| 24 |
|
| 25 |
BitwiseORExpression[In, Yield, Await] : |
| 26 |
BitwiseXORExpression[?In, ?Yield, ?Await] |
| 27 |
|
| 28 |
BitwiseXORExpression[In, Yield, Await] : |
| 29 |
BitwiseANDExpression[?In, ?Yield, ?Await] |
| 30 |
|
| 31 |
BitwiseANDExpression[In, Yield, Await] : |
| 32 |
EqualityExpression[?In, ?Yield, ?Await] |
| 33 |
|
| 34 |
EqualityExpression[In, Yield, Await] : |
| 35 |
RelationalExpression[?In, ?Yield, ?Await] |
| 36 |
|
| 37 |
RelationalExpression[In, Yield, Await] : |
| 38 |
ShiftExpression[?Yield, ?Await] |
| 39 |
|
| 40 |
ShiftExpression[Yield, Await] : |
| 41 |
AdditiveExpression[?Yield, ?Await] |
| 42 |
|
| 43 |
AdditiveExpression[Yield, Await] : |
| 44 |
MultiplicativeExpression[?Yield, ?Await] |
| 45 |
|
| 46 |
MultiplicativeExpression[Yield, Await] : |
| 47 |
ExponentiationExpression[?Yield, ?Await] |
| 48 |
|
| 49 |
ExponentiationExpression[Yield, Await] : |
| 50 |
UnaryExpression[?Yield, ?Await] |
| 51 |
|
| 52 |
UnaryExpression[Yield, Await] : |
| 53 |
UpdateExpression[?Yield, ?Await] |
| 54 |
[+Await] AwaitExpression[?Yield] |
| 55 |
|
| 56 |
AwaitExpression[Yield] : |
| 57 |
`await` UnaryExpression[?Yield, +Await] |
| 58 |
flags: [async] |
| 59 |
includes: [asyncHelpers.js] |
| 60 |
---*/ |
| 61 |
|
| 62 |
async function foo() { |
| 63 |
let x = 'initial value'; |
| 64 |
let shouldNotBeAwaited = { |
| 65 |
then: function(onFulfilled) { |
| 66 |
x = 'unexpected then() call'; |
| 67 |
Promise.resolve().then(onFulfilled); |
| 68 |
} |
| 69 |
}; |
| 70 |
// This must parse like `(await false) || shouldNotBeAwaited`. |
| 71 |
await false || shouldNotBeAwaited; |
| 72 |
assert.sameValue(x, 'initial value'); |
| 73 |
} |
| 74 |
asyncTest(foo); |