js/src/tests/js1_5/Regress/regress-224956.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  *
     8  * Date:    08 November 2003
     9  * SUMMARY: |expr()| should cause a TypeError if |typeof expr| != 'function'
    10  *
    11  * See http://bugzilla.mozilla.org/show_bug.cgi?id=224956
    12  *
    13  */
    14 //-----------------------------------------------------------------------------
    15 var UBound = 0;
    16 var BUGNUMBER = 224956;
    17 var summary = "|expr()| should cause TypeError if |typeof expr| != 'function'";
    18 var TEST_PASSED = 'TypeError';
    19 var TEST_FAILED = 'Generated an error, but NOT a TypeError! ';
    20 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
    21 var CHECK_PASSED = 'Should not generate an error';
    22 var CHECK_FAILED = 'Generated an error!';
    23 var status = '';
    24 var statusitems = [];
    25 var actual = '';
    26 var actualvalues = [];
    27 var expect= '';
    28 var expectedvalues = [];
    29 var x;
    32 /*
    33  * All the following contain invalid uses of the call operator ()
    34  * and should generate TypeErrors. That's what we're testing for.
    35  *
    36  * To save writing try...catch over and over, we hide all the
    37  * errors inside eval strings, and let testThis() catch them.
    38  */
    39 status = inSection(1);
    40 x = 'abc';
    41 testThis('x()');
    43 status = inSection(2);
    44 testThis('"abc"()');
    46 status = inSection(3);
    47 x = new Date();
    48 testThis('x()');
    50 status = inSection(4);
    51 testThis('Date(12345)()');
    53 status = inSection(5);
    54 x = Number(1);
    55 testThis('x()');
    57 status = inSection(6);
    58 testThis('1()');
    60 status = inSection(7);
    61 x = void(0);
    62 testThis('x()');
    64 status = inSection(8);
    65 testThis('void(0)()');
    67 status = inSection(9);
    68 x = Math;
    69 testThis('x()');
    71 status = inSection(10);
    72 testThis('Math()');
    74 status = inSection(11);
    75 x = Array(5);
    76 testThis('x()');
    78 status = inSection(12);
    79 testThis('[1,2,3,4,5]()');
    81 status = inSection(13);
    82 x = [1,2,3].splice(1,2);
    83 testThis('x()');
    86 /*
    87  * Same as above, but with non-empty call parentheses
    88  */
    89 status = inSection(14);
    90 x = 'abc';
    91 testThis('x(1)');
    93 status = inSection(15);
    94 testThis('"abc"(1)');
    96 status = inSection(16);
    97 x = new Date();
    98 testThis('x(1)');
   100 status = inSection(17);
   101 testThis('Date(12345)(1)');
   103 status = inSection(18);
   104 x = Number(1);
   105 testThis('x(1)');
   107 status = inSection(19);
   108 testThis('1(1)');
   110 status = inSection(20);
   111 x = void(0);
   112 testThis('x(1)');
   114 status = inSection(21);
   115 testThis('void(0)(1)');
   117 status = inSection(22);
   118 x = Math;
   119 testThis('x(1)');
   121 status = inSection(23);
   122 testThis('Math(1)');
   124 status = inSection(24);
   125 x = Array(5);
   126 testThis('x(1)');
   128 status = inSection(25);
   129 testThis('[1,2,3,4,5](1)');
   131 status = inSection(26);
   132 x = [1,2,3].splice(1,2);
   133 testThis('x(1)');
   136 /*
   137  * Expression from website in original bug report above -
   138  */
   139 status = inSection(27);
   140 var A = 1, C=2, Y=3, T=4, I=5;
   141 testThis('(((C/A-0.3)/0.2)+((Y/A-3)/4)+((T/A)/0.05)+((0.095-I/A)/0.4))(100/6)');
   144 status = inSection(28);
   145 x = /a()/;
   146 testThis('x("abc")');
   148 status = inSection(29);
   149 x = /a()/gi;
   150 testThis('x("abc")');
   152 status = inSection(30);
   153 x = RegExp('a()');
   154 testThis('x("abc")');
   156 status = inSection(31);
   157 x = new RegExp('a()', 'gi');
   158 testThis('x("")');
   161 /*
   162  * Functions have |typeof| == 'function'.
   163  *
   164  * Therefore these expressions should not cause any errors.
   165  * Note we use checkThis() instead of testThis()
   166  *
   167  */
   168 status = inSection(32);
   169 x = function (y) {return y+1;};
   170 checkThis('x("abc")');
   172 status = inSection(33);
   173 checkThis('(function (y) {return y+1;})("abc")');
   175 status = inSection(34);
   176 function f(y) { function g() {return y;}; return g();};
   177 checkThis('f("abc")');
   181 //-----------------------------------------------------------------------------
   182 test();
   183 //-----------------------------------------------------------------------------
   188 /*
   189  * |expr()| should generate a TypeError if |expr| is not a function
   190  */
   191 function testThis(sInvalidSyntax)
   192 {
   193   expect = TEST_PASSED;
   194   actual = TEST_FAILED_BADLY;
   196   try
   197   {
   198     eval(sInvalidSyntax);
   199   }
   200   catch(e)
   201   {
   202     if (e instanceof TypeError)
   203       actual = TEST_PASSED;
   204     else
   205       actual = TEST_FAILED + e;
   206   }
   208   statusitems[UBound] = status;
   209   expectedvalues[UBound] = expect;
   210   actualvalues[UBound] = actual;
   211   UBound++;
   212 }
   215 /*
   216  * Valid syntax shouldn't generate any errors
   217  */
   218 function checkThis(sValidSyntax)
   219 {
   220   expect = CHECK_PASSED;
   221   actual = CHECK_PASSED;
   223   try
   224   {
   225     eval(sValidSyntax);
   226   }
   227   catch(e)
   228   {
   229     actual = CHECK_FAILED;
   230   }
   232   statusitems[UBound] = status;
   233   expectedvalues[UBound] = expect;
   234   actualvalues[UBound] = actual;
   235   UBound++;
   236 }
   239 function test()
   240 {
   241   enterFunc('test');
   242   printBugNumber(BUGNUMBER);
   243   printStatus(summary);
   245   for (var i=0; i<UBound; i++)
   246   {
   247     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   248   }
   250   exitFunc ('test');
   251 }

mercurial