js/src/tests/js1_7/extensions/destructuring-order.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //-----------------------------------------------------------------------------
     7 var BUGNUMBER     = "(none)";
     8 var summary = "Order of destructuring, destructuring in the presence of " +
     9   "exceptions";
    10 var actual, expect;
    12 printBugNumber(BUGNUMBER);
    13 printStatus(summary);
    15 /**************
    16  * BEGIN TEST *
    17  **************/
    19 var failed = false;
    22 var a = "FAILED", b = "PASSED";
    24 function exceptObj()
    25 {
    26   return { get b() { throw "PASSED"; }, a: "PASSED" };
    27 }
    29 function partialEvalObj()
    30 {
    31   try
    32   {
    33     ({a:a, b:b}) = exceptObj();
    34     throw "FAILED";
    35   }
    36   catch (ex)
    37   {
    38     if (ex !== "PASSED")
    39       throw "bad exception thrown: " + ex;
    40   }
    41 }
    44 var c = "FAILED", d = "FAILED", e = "PASSED", f = "PASSED";
    46 function exceptArr()
    47 {
    48   return ["PASSED", {e: "PASSED", get f() { throw "PASSED"; }}, "FAILED"];
    49 }
    51 function partialEvalArr()
    52 {
    53   try
    54   {
    55     [c, {e: d, f: e}, f] = exceptArr();
    56     throw "FAILED";
    57   }
    58   catch (ex)
    59   {
    60     if (ex !== "PASSED")
    61       throw "bad exception thrown: " + ex;
    62   }
    63 }
    66 var g = "FAILED", h = "FAILED", i = "FAILED", j = "FAILED", k = "FAILED";
    67 var _g = "PASSED", _h = "FAILED", _i = "FAILED", _j = "FAILED", _k = "FAILED";
    68 var order = [];
    70 function objWithGetters()
    71 {
    72   return {
    73     get j()
    74     {
    75       var rv = _j;
    76       _g = _h = _i = _j = "FAILED";
    77       _k = "PASSED";
    78       order.push("j");
    79       return rv;
    80     },
    81       get g()
    82       {
    83 	var rv = _g;
    84 	_g = _i = _j = _k = "FAILED";
    85 	_h = "PASSED";
    86 	order.push("g");
    87 	return rv;
    88       },
    89 	get i()
    90 	{
    91 	  var rv = _i;
    92 	  _g = _h = _i = _k = "FAILED";
    93 	  _j = "PASSED";
    94 	  order.push("i");
    95 	  return rv;
    96 	},
    97 	  get k()
    98 	  {
    99 	    var rv = _k;
   100 	    _g = _h = _i = _j = _k = "FAILED";
   101 	    order.push("k");
   102 	    return rv;
   103 	  },
   104 	    get h()
   105 	    {
   106 	      var rv = _h;
   107 	      _g = _h = _j = _k = "FAILED";
   108 	      _i = "PASSED";
   109 	      order.push("h");
   110 	      return rv;
   111 	    }
   112   };
   113 }
   115 function partialEvalObj2()
   116 {
   117   ({g: g, h: h, i: i, j: j, k: k}) = objWithGetters();
   118 }
   120 try
   121 {
   122   partialEvalObj();
   123   if (a !== "PASSED" || b !== "PASSED")
   124     throw "FAILED: lhs not mutated correctly during destructuring!\n" +
   125       "a == " + a + ", b == " + b;
   127   partialEvalObj2();
   128   if (g !== "PASSED" ||
   129       h !== "PASSED" ||
   130       i !== "PASSED" ||
   131       j !== "PASSED" ||
   132       k !== "PASSED")
   133     throw "FAILED: order of property accesses wrong!\n" +
   134       "order == " + order;
   136   partialEvalArr();
   137   if (c !== "PASSED" || d !== "PASSED" || e !== "PASSED")
   138     throw "FAILED: lhs not mutated correctly during destructuring!\n" +
   139       "c == " + c +
   140       ", d == " + d +
   141       ", e == " + e +
   142       ", f == " + f ;
   143 }
   144 catch (ex)
   145 {
   146   failed = ex;
   147 }
   149 expect = false;
   150 actual = failed;
   152 reportCompare(expect, actual, summary);

mercurial