js/src/tests/js1_5/Object/regress-90596-003.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 for-in loops.
    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  * For example, we quote string values like "Hi" in lines like this:
    14  *
    15  *                    actual = enumerateThis(obj);
    16  *                    expect = '{prop:"Hi"}';
    17  *
    18  * But enumerateThis(obj) gets literal value Hi for obj.prop, not
    19  * literal "Hi".  We take care of all these details in the
    20  * compactThis(), sortThis() functions.  Sorting properties
    21  * alphabetically is necessary for the test to work in Rhino.
    22  */
    23 //-----------------------------------------------------------------------------
    24 var UBound = 0;
    25 var BUGNUMBER = 90596;
    26 var summary = '[DontEnum] props (if overridden) should appear in for-in loops';
    27 var cnCOMMA = ',';
    28 var cnCOLON = ':';
    29 var cnLBRACE = '{';
    30 var cnRBRACE = '}';
    31 var status = '';
    32 var statusitems = [];
    33 var actual = '';
    34 var actualvalues = [];
    35 var expect= '';
    36 var expectedvalues = [];
    37 var obj = {};
    40 status = inSection(1);
    41 obj = {toString:9};
    42 actual = enumerateThis(obj);
    43 expect = '{toString:9}';
    44 addThis();
    46 status = inSection(2);
    47 obj = {hasOwnProperty:"Hi"};
    48 actual = enumerateThis(obj);
    49 expect = '{hasOwnProperty:"Hi"}';
    50 addThis();
    52 status = inSection(3);
    53 obj = {toString:9, hasOwnProperty:"Hi"};
    54 actual = enumerateThis(obj);
    55 expect = '{toString:9, hasOwnProperty:"Hi"}';
    56 addThis();
    58 status = inSection(4);
    59 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
    60 actual = enumerateThis(obj);
    61 expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
    62 addThis();
    65 // TRY THE SAME THING IN EVAL CODE
    66 var s = '';
    68 status = inSection(5);
    69 s = 'obj = {toString:9}';
    70 eval(s);
    71 actual = enumerateThis(obj);
    72 expect = '{toString:9}';
    73 addThis();
    75 status = inSection(6);
    76 s = 'obj = {hasOwnProperty:"Hi"}';
    77 eval(s);
    78 actual = enumerateThis(obj);
    79 expect = '{hasOwnProperty:"Hi"}';
    80 addThis();
    82 status = inSection(7);
    83 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
    84 eval(s);
    85 actual = enumerateThis(obj);
    86 expect = '{toString:9, hasOwnProperty:"Hi"}';
    87 addThis();
    89 status = inSection(8);
    90 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
    91 eval(s);
    92 actual = enumerateThis(obj);
    93 expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
    94 addThis();
    97 // TRY THE SAME THING IN FUNCTION CODE
    98 function A()
    99 {
   100   status = inSection(9);
   101   var s = 'obj = {toString:9}';
   102   eval(s);
   103   actual = enumerateThis(obj);
   104   expect = '{toString:9}';
   105   addThis();
   106 }
   107 A();
   109 function B()
   110 {
   111   status = inSection(10);
   112   var s = 'obj = {hasOwnProperty:"Hi"}';
   113   eval(s);
   114   actual = enumerateThis(obj);
   115   expect = '{hasOwnProperty:"Hi"}';
   116   addThis();
   117 }
   118 B();
   120 function C()
   121 {
   122   status = inSection(11);
   123   var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
   124   eval(s);
   125   actual = enumerateThis(obj);
   126   expect = '{toString:9, hasOwnProperty:"Hi"}';
   127   addThis();
   128 }
   129 C();
   131 function D()
   132 {
   133   status = inSection(12);
   134   var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
   135   eval(s);
   136   actual = enumerateThis(obj);
   137   expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
   138   addThis();
   139 }
   140 D();
   144 //-----------------------------------------------------------------------------
   145 test();
   146 //-----------------------------------------------------------------------------
   150 function enumerateThis(obj)
   151 {
   152   var arr = new Array();
   154   for (var prop in obj)
   155   {
   156     arr.push(prop + cnCOLON + obj[prop]);
   157   }
   159   var ret = addBraces(String(arr));
   160   return ret;
   161 }
   164 function addBraces(text)
   165 {
   166   return cnLBRACE + text + cnRBRACE;
   167 }
   170 /*
   171  * Sort properties alphabetically so the test will work in Rhino
   172  */
   173 function addThis()
   174 {
   175   statusitems[UBound] = status;
   176   actualvalues[UBound] = sortThis(actual);
   177   expectedvalues[UBound] = sortThis(expect);
   178   UBound++;
   179 }
   182 /*
   183  * Takes a string of the form '{"c", "b", "a", 2}' and returns '{2,a,b,c}'
   184  */
   185 function sortThis(sList)
   186 {
   187   sList = compactThis(sList);
   188   sList = stripBraces(sList);
   189   var arr = sList.split(cnCOMMA);
   190   arr = arr.sort();
   191   var ret = String(arr);
   192   ret = addBraces(ret);
   193   return ret;
   194 }
   197 /*
   198  * Strips out any whitespace or quotes from the text -
   199  */
   200 function compactThis(text)
   201 {
   202   var charCode = 0;
   203   var ret = '';
   205   for (var i=0; i<text.length; i++)
   206   {
   207     charCode = text.charCodeAt(i);
   209     if (!isWhiteSpace(charCode) && !isQuote(charCode))
   210       ret += text.charAt(i);
   211   }
   213   return ret;
   214 }
   217 function isWhiteSpace(charCode)
   218 {
   219   switch (charCode)
   220   {
   221   case (0x0009):
   222   case (0x000B):
   223   case (0x000C):
   224   case (0x0020):
   225   case (0x000A):  // '\n'
   226   case (0x000D):  // '\r'
   227     return true;
   228     break;
   230   default:
   231     return false;
   232   }
   233 }
   236 function isQuote(charCode)
   237 {
   238   switch (charCode)
   239   {
   240   case (0x0027): // single quote
   241   case (0x0022): // double quote
   242     return true;
   243     break;
   245   default:
   246     return false;
   247   }
   248 }
   251 /*
   252  * strips off braces at beginning and end of text -
   253  */
   254 function stripBraces(text)
   255 {
   256   // remember to escape the braces...
   257   var arr = text.match(/^\{(.*)\}$/);
   259   // defend against a null match...
   260   if (arr != null && arr[1] != null)
   261     return arr[1];
   262   return text;
   263 }
   266 function test()
   267 {
   268   enterFunc ('test');
   269   printBugNumber(BUGNUMBER);
   270   printStatus (summary);
   272   for (var i=0; i<UBound; i++)
   273   {
   274     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   275   }
   277   exitFunc ('test');
   278 }

mercurial