js/src/tests/js1_7/regexp/yflag.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 = 371932;
     8 var summary = 'ES4 Regular Expression /y flag';
     9 var actual = '';
    10 var expect = '';
    12 print('See http://developer.mozilla.org/es4/proposals/extend_regexps.html#y_flag');
    14 //-----------------------------------------------------------------------------
    15 test();
    16 //-----------------------------------------------------------------------------
    18 function test()
    19 {
    20   enterFunc ('test');
    21   printBugNumber(BUGNUMBER);
    22   printStatus (summary);
    24   var c;
    25   var s = '123456';
    27   print('Test global flag.');
    29   var g = /(1)/g;
    30   expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
    31   actual = 'captures: ' + g.exec('1234561') +
    32     '; RegExp.leftContext: "' + RegExp.leftContext +
    33     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    34   reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") first call');
    36   expect = 'captures: 1,1; RegExp.leftContext: "123456"; RegExp.rightContext: ""';
    37   actual = 'captures: ' + g.exec('1234561') +
    38     '; RegExp.leftContext: "' + RegExp.leftContext +
    39     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    40   reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") second call');
    41   var y = /(1)/y;
    43   print('Test sticky flag.');
    45   /*
    46    * calls to reportCompare invoke regular expression matches which interfere
    47    * with the test of the sticky flag. Collect expect and actual values prior
    48    * to calling reportCompare. Note setting y = /(1)/y resets the lastIndex etc.
    49    */
    51   var y = /(1)/y;
    52   var expect4 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
    53   var actual4 = 'captures: ' + y.exec('1234561') +
    54     '; RegExp.leftContext: "' + RegExp.leftContext +
    55     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    57   var expect5 = 'captures: null; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
    58   var actual5 = 'captures: ' + y.exec('1234561') +
    59     '; RegExp.leftContext: "' + RegExp.leftContext +
    60     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    62   reportCompare(expect4, actual4, summary + ' - /(1)/y.exec("1234561") first call');
    63   reportCompare(expect5, actual5, summary + ' - /(1)/y.exec("1234561") second call');
    65   var y = /(1)/y;
    67   reportCompare(expect5, actual5, summary);
    69   y = /(1)/y;
    70   var expect6 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "123456"';
    71   var actual6 = 'captures: ' + y.exec('1123456') +
    72     '; RegExp.leftContext: "' + RegExp.leftContext +
    73     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    75   var expect7 = 'captures: 1,1; RegExp.leftContext: "1"; RegExp.rightContext: "23456"';
    76   var actual7 = 'captures: ' + y.exec('1123456') +
    77     '; RegExp.leftContext: "' + RegExp.leftContext +
    78     '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
    80   reportCompare(expect6, actual6, summary + ' - /(1)/y.exec("1123456") first call');
    81   reportCompare(expect7, actual7, summary + ' - /(1)/y.exec("1123456") second call');
    83   var y = /(1)/y;
    85   reportCompare(expect, actual, summary);
    87   exitFunc ('test');
    88 }

mercurial