tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

optional-chain-async-optional-chain-square-brackets.js (910B)


      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 expansions in an async context
      8 info: |
      9  Left-Hand-Side Expressions
     10    OptionalExpression
     11      MemberExpression [PrimaryExpression Identifier] OptionalChain
     12        OptionalChain OptionalChain ?.[Expression]
     13 features: [optional-chaining]
     14 flags: [async]
     15 includes: [asyncHelpers.js]
     16 ---*/
     17 
     18 async function checkAssertions() {
     19  assert.sameValue(await {a: [11]}?.a[0], 11);
     20  const b = {c: [22, 33]};
     21  assert.sameValue(b?.c[await Promise.resolve(1)], 33);
     22  function e(val) {
     23    return val;
     24  }
     25  assert.sameValue({d: e}?.d(await Promise.resolve([44, 55]))[1], 55);
     26  assert.sameValue(undefined?.arr[
     27    await Promise.reject(new Error('unreachable'))
     28  ], undefined);
     29 }
     30 asyncTest(checkAssertions);