tor-browser

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

for-inof-coverinitname-destr-assign.js (1481B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 const defaultValue = "default-value";
      6 const unreachable = () => { throw "unreachable"; };
      7 
      8 // for-in statement, object destructuring.
      9 var forIn;
     10 for ({forIn = defaultValue} in {"": null});
     11 assertEq(forIn, defaultValue);
     12 
     13 forIn = undefined;
     14 String.prototype.forIn = defaultValue;
     15 for ({forIn = unreachable()} in {"": null});
     16 delete String.prototype.forIn;
     17 assertEq(forIn, defaultValue);
     18 
     19 // for-in statement, array destructuring.
     20 forIn = undefined;
     21 for ([forIn = defaultValue] in {"": null});
     22 assertEq(forIn, defaultValue);
     23 
     24 forIn = undefined;
     25 for ([forIn = unreachable()] in {"ABC": null});
     26 assertEq(forIn, "A");
     27 
     28 
     29 // for-of statement, object destructuring.
     30 var forOf;
     31 for ({forOf = defaultValue} of [{}]);
     32 assertEq(forOf, defaultValue);
     33 
     34 forOf = undefined;
     35 for ({forOf = unreachable()} of [{forOf: defaultValue}]);
     36 assertEq(forOf, defaultValue);
     37 
     38 // for-of statement, array destructuring.
     39 forOf = undefined;
     40 for ([forOf = defaultValue] of [[]]);
     41 assertEq(forOf, defaultValue);
     42 
     43 forOf = undefined;
     44 for ([forOf = unreachable()] of [[defaultValue]]);
     45 assertEq(forOf, defaultValue);
     46 
     47 
     48 // for-statement, object destructuring.
     49 assertThrowsInstanceOf(() => eval(`
     50  for ({invalid = 0};;);
     51 `), SyntaxError);
     52 
     53 
     54 if (typeof reportCompare === "function")
     55    reportCompare(true, true);