js/src/tests/ecma_3/RegExp/regress-85721.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 // |reftest| random -- bogus perf test (bug 467263)
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /*
     8  *
     9  * Date:    14 Feb 2002
    10  * SUMMARY: Performance: Regexp performance degraded from 4.7
    11  * See http://bugzilla.mozilla.org/show_bug.cgi?id=85721
    12  *
    13  * Adjust this testcase if necessary. The FAST constant defines
    14  * an upper bound in milliseconds for any execution to take.
    15  *
    16  */
    17 //-----------------------------------------------------------------------------
    18 var BUGNUMBER = 85721;
    19 var summary = 'Performance: execution of regular expression';
    20 var FAST = 100; // execution should be 100 ms or less to pass the test
    21 var MSG_FAST = 'Execution took less than ' + FAST + ' ms';
    22 var MSG_SLOW = 'Execution took ';
    23 var MSG_MS = ' ms';
    24 var str = '';
    25 var re = '';
    26 var status = '';
    27 var actual = '';
    28 var expect= '';
    30 printBugNumber(BUGNUMBER);
    31 printStatus (summary);
    34 function elapsedTime(startTime)
    35 {
    36   return new Date() - startTime;
    37 }
    40 function isThisFast(ms)
    41 {
    42   if (ms <= FAST)
    43     return MSG_FAST;
    44   return MSG_SLOW + ms + MSG_MS;
    45 }
    49 /*
    50  * The first regexp. We'll test for performance (Section 1) and accuracy (Section 2).
    51  */
    52 str='<sql:connection id="conn1"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>';
    53 re = /<sql:connection id="([^\r\n]*?)">\s*<sql:url>\s*([^\r\n]*?)\s*<\/sql:url>\s*<sql:driver>\s*([^\r\n]*?)\s*<\/sql:driver>\s*(\s*<sql:userId>\s*([^\r\n]*?)\s*<\/sql:userId>\s*)?\s*(\s*<sql:password>\s*([^\r\n]*?)\s*<\/sql:password>\s*)?\s*<\/sql:connection>/;
    54 expect = Array("<sql:connection id=\"conn1\"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>","conn1","www.m.com","drive.class","<sql:userId>foo</sql:userId> ","foo","<sql:password>goo</sql:password> ","goo");
    56 /*
    57  *  Check performance -
    58  */
    59 status = inSection(1);
    60 var start = new Date();
    61 var result = re.exec(str);
    62 actual = elapsedTime(start);
    63 reportCompare(isThisFast(FAST), isThisFast(actual), status);
    65 /*
    66  *  Check accuracy -
    67  */
    68 status = inSection(2);
    69 testRegExp([status], [re], [str], [result], [expect]);
    73 /*
    74  * The second regexp (HUGE!). We'll test for performance (Section 3) and accuracy (Section 4).
    75  * It comes from the O'Reilly book "Mastering Regular Expressions" by Jeffrey Friedl, Appendix B
    76  */
    78 //# Some things for avoiding backslashitis later on.
    79 $esc        = '\\\\';     
    80 $Period      = '\.';
    81 $space      = '\040';              $tab         = '\t';
    82 $OpenBR     = '\\[';               $CloseBR     = '\\]';
    83 $OpenParen  = '\\(';               $CloseParen  = '\\)';
    84 $NonASCII   = '\x80-\xff';         $ctrl        = '\000-\037';
    85 $CRlist     = '\n\015';  //# note: this should really be only \015.
    86 // Items 19, 20, 21
    87 $qtext = '[^' + $esc + $NonASCII + $CRlist + '\"]';						  // # for within "..."
    88 $dtext = '[^' + $esc + $NonASCII + $CRlist + $OpenBR + $CloseBR + ']';    // # for within [...]
    89 $quoted_pair = $esc + '[^' + $NonASCII + ']';							  // # an escaped character
    91 //##############################################################################
    92 //# Items 22 and 23, comment.
    93 //# Impossible to do properly with a regex, I make do by allowing at most one level of nesting.
    94 $ctext   =  '[^' + $esc + $NonASCII + $CRlist + '()]';
    96 //# $Cnested matches one non-nested comment.
    97 //# It is unrolled, with normal of $ctext, special of $quoted_pair.
    98 $Cnested =
    99   $OpenParen +                                 // #  (
   100   $ctext + '*' +                            // #     normal*
   101   '(?:' + $quoted_pair + $ctext + '*)*' +   // #     (special normal*)*
   102   $CloseParen;                                 // #                       )
   105 //# $comment allows one level of nested parentheses
   106 //# It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested)
   107 $comment =
   108   $OpenParen +                                           // #  (
   109   $ctext + '*' +                                     // #     normal*
   110   '(?:' +                                            // #       (
   111   '(?:' + $quoted_pair + '|' + $Cnested + ')' +   // #         special
   112   $ctext + '*' +                                 // #         normal*
   113   ')*' +                                             // #            )*
   114   $CloseParen;                                           // #                )
   117 //##############################################################################
   118 //# $X is optional whitespace/comments.
   119 $X =
   120   '[' + $space + $tab + ']*' +					       // # Nab whitespace.
   121   '(?:' + $comment + '[' + $space + $tab + ']*)*';    // # If comment found, allow more spaces.
   124 //# Item 10: atom
   125 $atom_char   = '[^(' + $space + '<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $ctrl + $NonASCII + ']';
   126 $atom =
   127   $atom_char + '+' +            // # some number of atom characters...
   128   '(?!' + $atom_char + ')';     // # ..not followed by something that could be part of an atom
   130 // # Item 11: doublequoted string, unrolled.
   131 $quoted_str =
   132   '\"' +                                         // # "
   133   $qtext + '*' +                              // #   normal
   134   '(?:' + $quoted_pair + $qtext + '*)*' +     // #   ( special normal* )*
   135   '\"';                                          // # "
   137 //# Item 7: word is an atom or quoted string
   138 $word =
   139   '(?:' +
   140   $atom +                // # Atom
   141   '|' +                  //     #  or
   142   $quoted_str +          // # Quoted string
   143   ')'
   145 //# Item 12: domain-ref is just an atom
   146   $domain_ref  = $atom;
   148 //# Item 13: domain-literal is like a quoted string, but [...] instead of  "..."
   149 $domain_lit  =
   150   $OpenBR +								   	     // # [
   151   '(?:' + $dtext + '|' + $quoted_pair + ')*' +     // #    stuff
   152   $CloseBR;                                        // #           ]
   154 // # Item 9: sub-domain is a domain-ref or domain-literal
   155 $sub_domain  =
   156   '(?:' +
   157   $domain_ref +
   158   '|' +
   159   $domain_lit +
   160   ')' +
   161   $X;                 // # optional trailing comments
   163 // # Item 6: domain is a list of subdomains separated by dots.
   164 $domain =
   165   $sub_domain +
   166   '(?:' +
   167   $Period + $X + $sub_domain +
   168   ')*';
   170 //# Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon.
   171 $route =
   172   '\@' + $X + $domain +
   173   '(?:,' + $X + '\@' + $X + $domain + ')*' +  // # additional domains
   174   ':' +
   175   $X;					// # optional trailing comments
   177 //# Item 6: local-part is a bunch of $word separated by periods
   178 $local_part =
   179   $word + $X
   180   '(?:' +
   181   $Period + $X + $word + $X +		// # additional words
   182   ')*';
   184 // # Item 2: addr-spec is local@domain
   185 $addr_spec  =
   186   $local_part + '\@' + $X + $domain;
   188 //# Item 4: route-addr is <route? addr-spec>
   189 $route_addr =
   190   '<' + $X +                     // # <
   191   '(?:' + $route + ')?' +     // #       optional route
   192   $addr_spec +                // #       address spec
   193   '>';                           // #                 >
   195 //# Item 3: phrase........
   196 $phrase_ctrl = '\000-\010\012-\037'; // # like ctrl, but without tab
   198 //# Like atom-char, but without listing space, and uses phrase_ctrl.
   199 //# Since the class is negated, this matches the same as atom-char plus space and tab
   200 $phrase_char =
   201   '[^()<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $NonASCII + $phrase_ctrl + ']';
   203 // # We've worked it so that $word, $comment, and $quoted_str to not consume trailing $X
   204 // # because we take care of it manually.
   205 $phrase =
   206   $word +                                                  // # leading word
   207   $phrase_char + '*' +                                     // # "normal" atoms and/or spaces
   208   '(?:' +
   209   '(?:' + $comment + '|' + $quoted_str + ')' +          // # "special" comment or quoted string
   210   $phrase_char + '*' +                                  // #  more "normal"
   211   ')*';
   213 // ## Item #1: mailbox is an addr_spec or a phrase/route_addr
   214 $mailbox =
   215   $X +                                // # optional leading comment
   216   '(?:' +
   217   $phrase + $route_addr +     // # name and address
   218   '|' +                       //     #  or
   219   $addr_spec +                // # address
   220   ')';
   223 //###########################################################################
   226 re = new RegExp($mailbox, "g");
   227 str = 'Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>';
   228 expect = Array('Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>');
   230 /*
   231  *  Check performance -
   232  */
   233 status = inSection(3);
   234 var start = new Date();
   235 var result = re.exec(str);
   236 actual = elapsedTime(start);
   237 reportCompare(isThisFast(FAST), isThisFast(actual), status);
   239 /*
   240  *  Check accuracy -
   241  */
   242 status = inSection(4);
   243 testRegExp([status], [re], [str], [result], [expect]);

mercurial