js/src/tests/ecma_2/String/match-004.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/. */
     7 /**
     8  *  File Name:          String/match-004.js
     9  *  ECMA Section:       15.6.4.9
    10  *  Description:        Based on ECMA 2 Draft 7 February 1999
    11  *
    12  *  Author:             christine@netscape.com
    13  *  Date:               19 February 1999
    14  */
    16 /*
    17  *  String.match( regexp )
    18  *
    19  *  If regexp is not an object of type RegExp, it is replaced with result
    20  *  of the expression new RegExp(regexp). Let string denote the result of
    21  *  converting the this value to a string.  If regexp.global is false,
    22  *  return the result obtained by invoking RegExp.prototype.exec (see
    23  *  section 15.7.5.3) on regexp with string as parameter.
    24  *
    25  *  Otherwise, set the regexp.lastIndex property to 0 and invoke
    26  *  RegExp.prototype.exec repeatedly until there is no match. If there is a
    27  *  match with an empty string (in other words, if the value of
    28  *  regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
    29  *  The value returned is an array with the properties 0 through n-1
    30  *  corresponding to the first element of the result of each matching
    31  *  invocation of RegExp.prototype.exec.
    32  *
    33  *  Note that the match function is intentionally generic; it does not
    34  *  require that its this value be a string object.  Therefore, it can be
    35  *  transferred to other kinds of objects for use as a method.
    36  *
    37  *
    38  *  The match function should be intentionally generic, and not require
    39  *  this to be a string.
    40  *
    41  */
    43 var SECTION = "String/match-004.js";
    44 var VERSION = "ECMA_2";
    45 var TITLE   = "String.prototype.match( regexp )";
    47 var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=345818";
    49 startTest();
    51 // set the value of lastIndex
    52 re = /0./;
    53 s = 10203040506070809000;
    55 Number.prototype.match = String.prototype.match;
    57 AddRegExpCases(  re,
    58 		 "re = " + re ,
    59 		 s,
    60 		 String(s),
    61 		 1,
    62 		 ["02"]);
    65 re.lastIndex = 0;
    66 AddRegExpCases(  re,
    67 		 "re = " + re +" [lastIndex is " + re.lastIndex+"]",
    68 		 s,
    69 		 String(s),
    70 		 1,
    71 		 ["02"]);
    72 /*
    74 re.lastIndex = s.length;
    76 AddRegExpCases( re,
    77 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
    78 s.length,
    79 s,
    80 s.lastIndexOf("0"),
    81 null );
    83 re.lastIndex = s.lastIndexOf("0");
    85 AddRegExpCases( re,
    86 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
    87 s.lastIndexOf("0"),
    88 s,
    89 s.lastIndexOf("0"),
    90 ["02134"]);
    92 re.lastIndex = s.lastIndexOf("0") + 1;
    94 AddRegExpCases( re,
    95 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
    96 s.lastIndexOf("0") +1,
    97 s,
    98 0,
    99 null);
   100 */
   101 test();
   103 function AddRegExpCases(
   104   regexp, str_regexp, string, str_string, index, matches_array ) {
   106   // prevent a runtime error
   108   if ( regexp.exec(string) == null || matches_array == null ) {
   109     AddTestCase(
   110       string + ".match(" + regexp +")",
   111       matches_array,
   112       string.match(regexp) );
   114     return;
   115   }
   117   AddTestCase(
   118     "( " + string  + " ).match(" + str_regexp +").length",
   119     matches_array.length,
   120     string.match(regexp).length );
   122   AddTestCase(
   123     "( " + string + " ).match(" + str_regexp +").index",
   124     index,
   125     string.match(regexp).index );
   127   AddTestCase(
   128     "( " + string + " ).match(" + str_regexp +").input",
   129     str_string,
   130     string.match(regexp).input );
   132   var limit = matches_array.length > string.match(regexp).length ?
   133     matches_array.length :
   134     string.match(regexp).length;
   136   for ( var matches = 0; matches < limit; matches++ ) {
   137     AddTestCase(
   138       "( " + string + " ).match(" + str_regexp +")[" + matches +"]",
   139       matches_array[matches],
   140       string.match(regexp)[matches] );
   141   }
   142 }
   144 function AddGlobalRegExpCases(
   145   regexp, str_regexp, string, matches_array ) {
   147   // prevent a runtime error
   149   if ( regexp.exec(string) == null || matches_array == null ) {
   150     AddTestCase(
   151       regexp + ".exec(" + string +")",
   152       matches_array,
   153       regexp.exec(string) );
   155     return;
   156   }
   158   AddTestCase(
   159     "( " + string  + " ).match(" + str_regexp +").length",
   160     matches_array.length,
   161     string.match(regexp).length );
   163   var limit = matches_array.length > string.match(regexp).length ?
   164     matches_array.length :
   165     string.match(regexp).length;
   167   for ( var matches = 0; matches < limit; matches++ ) {
   168     AddTestCase(
   169       "( " + string + " ).match(" + str_regexp +")[" + matches +"]",
   170       matches_array[matches],
   171       string.match(regexp)[matches] );
   172   }
   173 }

mercurial