member-expression-async-identifier.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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 on member expression in async context
  7. info: |
  8. Left-Hand-Side Expressions
  9. OptionalExpression
  10. MemberExpression [PrimaryExpression identifier] OptionalChain
  11. features: [optional-chaining]
  12. flags: [async]
  13. ---*/
  14. const a = undefined;
  15. const c = {d: Promise.resolve(11)};
  16. async function checkAssertions() {
  17. assert.sameValue(await a?.b, undefined);
  18. assert.sameValue(await c?.d, 11);
  19. Promise.prototype.x = 42;
  20. var res = await Promise.resolve(undefined)?.x;
  21. assert.sameValue(res, 42, 'await unwraps the evaluation of the whole optional chaining expression #1');
  22. Promise.prototype.y = 43;
  23. var res = await Promise.reject(undefined)?.y;
  24. assert.sameValue(res, 43, 'await unwraps the evaluation of the whole optional chaining expression #2');
  25. c.e = Promise.resolve(39);
  26. assert.sameValue(await c?.e, 39, 'await unwraps the promise given after the evaluation of the OCE');
  27. }
  28. checkAssertions().then($DONE, $DONE);