member-expression-async-identifier.js (1162B)
1 // |reftest| async 2 // Copyright 2019 Google, Inc. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: prod-OptionalExpression 6 description: > 7 optional chain on member expression in async context 8 info: | 9 Left-Hand-Side Expressions 10 OptionalExpression 11 MemberExpression [PrimaryExpression identifier] OptionalChain 12 features: [optional-chaining] 13 flags: [async] 14 includes: [asyncHelpers.js] 15 ---*/ 16 17 const a = undefined; 18 const c = {d: Promise.resolve(11)}; 19 async function checkAssertions() { 20 assert.sameValue(await a?.b, undefined); 21 assert.sameValue(await c?.d, 11); 22 23 Promise.prototype.x = 42; 24 var res = await Promise.resolve(undefined)?.x; 25 assert.sameValue(res, 42, 'await unwraps the evaluation of the whole optional chaining expression #1'); 26 27 Promise.prototype.y = 43; 28 var res = await Promise.reject(undefined)?.y; 29 assert.sameValue(res, 43, 'await unwraps the evaluation of the whole optional chaining expression #2'); 30 31 c.e = Promise.resolve(39); 32 assert.sameValue(await c?.e, 39, 'await unwraps the promise given after the evaluation of the OCE'); 33 } 34 asyncTest(checkAssertions);