tor-browser

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

optional-chain.js (1172B)


      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  various optional chain expansions
      7 info: |
      8  OptionalChain[Yield, Await]:
      9    ?.[Expression]
     10    ?.IdentifierName
     11    ?.Arguments
     12    ?.TemplateLiteral
     13    OptionalChain [Expression]
     14    OptionalChain .IdentifierName
     15    OptionalChain Arguments[?Yield, ?Await]
     16    OptionalChain TemplateLiteral
     17 features: [optional-chaining]
     18 ---*/
     19 
     20 const arr = [10, 11];
     21 const obj = {
     22  a: 'hello',
     23  b: {val: 13},
     24  c(arg1) {
     25    return arg1 * 2;
     26  },
     27  arr: [11, 12]
     28 };
     29 const i = 0;
     30 
     31 // OptionalChain: ?.[Expression]
     32 assert.sameValue(11, arr?.[i + 1]);
     33 
     34 // OptionalChain: ?.IdentifierName
     35 assert.sameValue('hello', obj?.a);
     36 
     37 // OptionalChain: ?.Arguments
     38 const fn = (arg1, arg2) => {
     39  return arg1 + arg2;
     40 }
     41 assert.sameValue(30, fn?.(10, 20));
     42 
     43 // OptionalChain: OptionalChain [Expression]
     44 assert.sameValue(12, obj?.arr[i + 1]);
     45 
     46 // OptionalChain: OptionalChain .IdentifierName
     47 assert.sameValue(13, obj?.b.val);
     48 
     49 // OptionalChain: OptionalChain Arguments
     50 assert.sameValue(20, obj?.c(10));
     51 
     52 reportCompare(0, 0);