js/src/tests/js1_5/extensions/regress-90596-002.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  * Date: 28 August 2001
     8  *
     9  * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
    11  *
    12  * NOTE: some inefficiencies in the test are made for the sake of readability.
    13  * Sorting properties alphabetically is done for definiteness in comparisons.
    14  */
    15 //-----------------------------------------------------------------------------
    16 var UBound = 0;
    17 var BUGNUMBER = 90596;
    18 var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
    19 var cnCOMMA = ',';
    20 var cnLBRACE = '{';
    21 var cnRBRACE = '}';
    22 var cnLPAREN = '(';
    23 var cnRPAREN = ')';
    24 var status = '';
    25 var statusitems = [];
    26 var actual = '';
    27 var actualvalues = [];
    28 var expect= '';
    29 var expectedvalues = [];
    30 var obj = {};
    33 status = inSection(1);
    34 obj = {toString:9};
    35 actual = uneval(obj);
    36 expect = '({toString:9})';
    37 addThis();
    39 status = inSection(2);
    40 obj = {hasOwnProperty:"Hi"};
    41 actual = uneval(obj);
    42 expect = '({hasOwnProperty:"Hi"})';
    43 addThis();
    45 status = inSection(3);
    46 obj = {toString:9, hasOwnProperty:"Hi"};
    47 actual = uneval(obj);
    48 expect = '({toString:9, hasOwnProperty:"Hi"})';
    49 addThis();
    51 status = inSection(4);
    52 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
    53 actual = uneval(obj);
    54 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
    55 addThis();
    58 // TRY THE SAME THING IN EVAL CODE
    59 var s = '';
    61 status = inSection(5);
    62 s = 'obj = {toString:9}';
    63 eval(s);
    64 actual = uneval(obj);
    65 expect = '({toString:9})';
    66 addThis();
    68 status = inSection(6);
    69 s = 'obj = {hasOwnProperty:"Hi"}';
    70 eval(s);
    71 actual = uneval(obj);
    72 expect = '({hasOwnProperty:"Hi"})';
    73 addThis();
    75 status = inSection(7);
    76 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
    77 eval(s);
    78 actual = uneval(obj);
    79 expect = '({toString:9, hasOwnProperty:"Hi"})';
    80 addThis();
    82 status = inSection(8);
    83 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
    84 eval(s);
    85 actual = uneval(obj);
    86 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
    87 addThis();
    90 // TRY THE SAME THING IN FUNCTION CODE
    91 function A()
    92 {
    93   status = inSection(9);
    94   var s = 'obj = {toString:9}';
    95   eval(s);
    96   actual = uneval(obj);
    97   expect = '({toString:9})';
    98   addThis();
    99 }
   100 A();
   102 function B()
   103 {
   104   status = inSection(10);
   105   var s = 'obj = {hasOwnProperty:"Hi"}';
   106   eval(s);
   107   actual = uneval(obj);
   108   expect = '({hasOwnProperty:"Hi"})';
   109   addThis();
   110 }
   111 B();
   113 function C()
   114 {
   115   status = inSection(11);
   116   var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
   117   eval(s);
   118   actual = uneval(obj);
   119   expect = '({toString:9, hasOwnProperty:"Hi"})';
   120   addThis();
   121 }
   122 C();
   124 function D()
   125 {
   126   status = inSection(12);
   127   var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
   128   eval(s);
   129   actual = uneval(obj);
   130   expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
   131   addThis();
   132 }
   133 D();
   137 //-----------------------------------------------------------------------------
   138 test();
   139 //-----------------------------------------------------------------------------
   143 /*
   144  * Sort properties alphabetically -
   145  */
   146 function addThis()
   147 {
   148   statusitems[UBound] = status;
   149   actualvalues[UBound] = sortThis(actual);
   150   expectedvalues[UBound] = sortThis(expect);
   151   UBound++;
   152 }
   155 /*
   156  * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
   157  */
   158 function sortThis(sList)
   159 {
   160   sList = compactThis(sList);
   161   sList = stripParens(sList);
   162   sList = stripBraces(sList);
   163   var arr = sList.split(cnCOMMA);
   164   arr = arr.sort();
   165   var ret = String(arr);
   166   ret = addBraces(ret);
   167   ret = addParens(ret);
   168   return ret;
   169 }
   172 /*
   173  * Strips out any whitespace from the text -
   174  */
   175 function compactThis(text)
   176 {
   177   var charCode = 0;
   178   var ret = '';
   180   for (var i=0; i<text.length; i++)
   181   {
   182     charCode = text.charCodeAt(i);
   184     if (!isWhiteSpace(charCode))
   185       ret += text.charAt(i);
   186   }
   188   return ret;
   189 }
   192 function isWhiteSpace(charCode)
   193 {
   194   switch (charCode)
   195   {
   196   case (0x0009):
   197   case (0x000B):
   198   case (0x000C):
   199   case (0x0020):
   200   case (0x000A):  // '\n'
   201   case (0x000D):  // '\r'
   202     return true;
   203     break;
   205   default:
   206     return false;
   207   }
   208 }
   211 /*
   212  * strips off parens at beginning and end of text -
   213  */
   214 function stripParens(text)
   215 {
   216   // remember to escape the parens...
   217   var arr = text.match(/^\((.*)\)$/);
   219   // defend against a null match...
   220   if (arr != null && arr[1] != null)
   221     return arr[1];
   222   return text;
   223 }
   226 /*
   227  * strips off braces at beginning and end of text -
   228  */
   229 function stripBraces(text)
   230 {
   231   // remember to escape the braces...
   232   var arr = text.match(/^\{(.*)\}$/);
   234   // defend against a null match...
   235   if (arr != null && arr[1] != null)
   236     return arr[1];
   237   return text;
   238 }
   241 function addBraces(text)
   242 {
   243   return cnLBRACE + text + cnRBRACE;
   244 }
   247 function addParens(text)
   248 {
   249   return cnLPAREN + text + cnRPAREN;
   250 }
   253 function test()
   254 {
   255   enterFunc ('test');
   256   printBugNumber(BUGNUMBER);
   257   printStatus (summary);
   259   for (var i=0; i<UBound; i++)
   260   {
   261     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   262   }
   264   exitFunc ('test');
   265 }

mercurial