js/src/tests/ecma_5/String/defaultvalue.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 var BUGNUMBER = 645464;
     7 var summary =
     8   "[[DefaultValue]] behavior wrong for String with overridden valueOf/toString";
    10 print(BUGNUMBER + ": " + summary);
    12 /**************
    13  * BEGIN TEST *
    14  **************/
    16 // equality
    18 var s = new String("c");
    19 assertEq(s == "c", true);
    21 var s2 = new String();
    22 s2.valueOf = function() { return "foo"; };
    23 assertEq(s2 == "foo", true);
    25 var s3 = new String();
    26 s3.toString = function() { return "bar"; };
    27 assertEq(s3 == "", true);
    29 function testEquality()
    30 {
    31   var s = new String("c");
    32   assertEq(s == "c", true);
    34   var s2 = new String();
    35   s2.valueOf = function() { return "foo"; };
    36   assertEq(s2 == "foo", true);
    38   var s3 = new String();
    39   s3.toString = function() { return "bar"; };
    40   assertEq(s3 == "", true);
    41 }
    42 testEquality();
    45 // addition of String to string
    47 var s = new String();
    48 assertEq(s + "", "");
    50 var s2 = new String();
    51 s2.toString = function() { return "bar"; };
    52 assertEq(s2 + "", "");
    54 var s3 = new String();
    55 s3.valueOf = function() { return "baz"; };
    56 assertEq(s3 + "", "baz");
    58 function testStringAddition()
    59 {
    60   var s = new String();
    61   assertEq(s + "", "");
    63   var s2 = new String();
    64   s2.toString = function() { return "bar"; };
    65   assertEq(s2 + "", "");
    67   var s3 = new String();
    68   s3.valueOf = function() { return "baz"; };
    69   assertEq(s3 + "", "baz");
    70 }
    71 testStringAddition();
    74 // addition of String to String
    76 var s = new String();
    77 assertEq(s + s, "");
    79 var s2 = new String();
    80 s2.toString = function() { return "baz"; };
    81 assertEq(s2 + s2, "");
    83 var s3 = new String();
    84 s3.valueOf = function() { return "quux"; };
    85 assertEq(s3 + s3, "quuxquux");
    87 function testNonStringAddition()
    88 {
    89   var s = new String();
    90   assertEq(s + s, "");
    92   var s2 = new String();
    93   s2.toString = function() { return "baz"; };
    94   assertEq(s2 + s2, "");
    96   var s3 = new String();
    97   s3.valueOf = function() { return "quux"; };
    98   assertEq(s3 + s3, "quuxquux");
    99 }
   100 testNonStringAddition();
   103 // String as bracketed property name
   105 var obj = { primitive: 17, valueOf: 42, toString: 8675309 };
   107 var s = new String("primitive");
   108 assertEq(obj[s], 17);
   110 var s2 = new String("primitive");
   111 s2.valueOf = function() { return "valueOf"; }
   112 assertEq(obj[s2], 17);
   114 var s3 = new String("primitive");
   115 s3.toString = function() { return "toString"; };
   116 assertEq(obj[s3], 8675309);
   118 function testPropertyNameToString()
   119 {
   120   var obj = { primitive: 17, valueOf: 42, toString: 8675309 };
   122   var s = new String("primitive");
   123   assertEq(obj[s], 17);
   125   var s2 = new String("primitive");
   126   s2.valueOf = function() { return "valueOf"; }
   127   assertEq(obj[s2], 17);
   129   var s3 = new String("primitive");
   130   s3.toString = function() { return "toString"; };
   131   assertEq(obj[s3], 8675309);
   132 }
   133 testPropertyNameToString();
   136 // String as property name with |in| operator
   138 var s = new String();
   139 assertEq(s in { "": 5 }, true);
   141 var s2 = new String();
   142 s.toString = function() { return "baz"; };
   143 assertEq(s in { baz: 42 }, true);
   145 var s3 = new String();
   146 s3.valueOf = function() { return "quux"; };
   147 assertEq(s3 in { "": 17 }, true);
   149 function testInOperatorName()
   150 {
   151   var s = new String();
   152   assertEq(s in { "": 5 }, true);
   154   var s2 = new String();
   155   s.toString = function() { return "baz"; };
   156   assertEq(s in { baz: 42 }, true);
   158   var s3 = new String();
   159   s3.valueOf = function() { return "quux"; };
   160   assertEq(s3 in { "": 17 }, true);
   161 }
   162 testInOperatorName();
   164 /******************************************************************************/
   166 if (typeof reportCompare === "function")
   167   reportCompare(true, true);
   169 print("All tests passed!");

mercurial