js/src/tests/ecma_5/String/match-throws-nonwritable-lastIndex-global.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 var BUGNUMBER = 501739;
     7 var summary =
     8   "String.prototype.match should throw when called with a global RegExp " +
     9   "whose .lastIndex is non-writable";
    11 print(BUGNUMBER + ": " + summary);
    13 /**************
    14  * BEGIN TEST *
    15  **************/
    17 var s = '0x2x4x6x8';
    19 // First time with .lastIndex === 0
    21 var p1 = /x/g;
    22 Object.defineProperty(p1, "lastIndex", { writable: false });
    24 try
    25 {
    26   s.match(p1);
    27   throw "didn't throw";
    28 }
    29 catch (e)
    30 {
    31   assertEq(e instanceof TypeError, true,
    32            "should have thrown a TypeError, instead got: " + e);
    33 }
    35 // Second time with .lastIndex !== 0
    37 var p2 = /x/g;
    38 Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 });
    40 try
    41 {
    42   s.match(p2);
    43   throw "didn't throw";
    44 }
    45 catch (e)
    46 {
    47   assertEq(e instanceof TypeError, true,
    48            "should have thrown a TypeError, instead got: " + e);
    49 }
    51 // Third time with .lastIndex === 0, no matches
    53 var p3 = /q/g;
    54 Object.defineProperty(p3, "lastIndex", { writable: false });
    56 try
    57 {
    58   s.match(p3);
    59   throw "didn't throw";
    60 }
    61 catch (e)
    62 {
    63   assertEq(e instanceof TypeError, true,
    64            "should have thrown a TypeError, instead got: " + e);
    65 }
    67 // Fourth time with .lastIndex !== 0, no matches
    69 var p4 = /q/g;
    70 Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 });
    72 try
    73 {
    74   s.match(p4);
    75   throw "didn't throw";
    76 }
    77 catch (e)
    78 {
    79   assertEq(e instanceof TypeError, true,
    80            "should have thrown a TypeError, instead got: " + e);
    81 }
    83 /******************************************************************************/
    85 if (typeof reportCompare === "function")
    86   reportCompare(true, true);
    88 print("Tests complete");

mercurial