optional-chain-async-square-brackets.js 780 B

123456789101112131415161718192021222324
  1. // Copyright 2019 Google, Inc. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: prod-OptionalExpression
  5. description: >
  6. optional chain expansions in an async context
  7. info: |
  8. Left-Hand-Side Expressions
  9. OptionalExpression
  10. MemberExpression [PrimaryExpression Identifier] OptionalChain
  11. OptionalChain ?.[Expression]
  12. features: [optional-chaining]
  13. flags: [async]
  14. ---*/
  15. async function checkAssertions() {
  16. assert.sameValue(await [11]?.[0], 11);
  17. assert.sameValue([22, 33]?.[await Promise.resolve(1)], 33);
  18. assert.sameValue([44, await Promise.resolve(55)]?.[1], 55);
  19. assert.sameValue(undefined?.[
  20. await Promise.reject(new Error('unreachable'))
  21. ], undefined);
  22. }
  23. checkAssertions().then($DONE, $DONE);