js/src/tests/js1_5/extensions/getset-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: 14 April 2001
     8  *
     9  * SUMMARY: Testing obj.prop getter/setter
    10  * Note: this is a non-ECMA extension to the language.
    11  */
    12 //-----------------------------------------------------------------------------
    13 var UBound = 0;
    14 var BUGNUMBER = '(none)';
    15 var summary = 'Testing obj.prop getter/setter';
    16 var statprefix = 'Status: ';
    17 var status = '';
    18 var statusitems = [ ];
    19 var actual = '';
    20 var actualvalues = [ ];
    21 var expect= '';
    22 var expectedvalues = [ ];
    23 var cnDEFAULT = 'default name';
    24 var cnFRED = 'Fred';
    25 var obj = {};
    26 var obj2 = {};
    27 var s = '';
    30 // SECTION1: define getter/setter directly on an object (not its prototype)
    31 obj = new Object();
    32 obj.nameSETS = 0;
    33 obj.nameGETS = 0;
    34 Object.defineProperty(obj, "name",
    35 {
    36   enumerable: true, configurable: true,
    37   set: function(newValue) {this._name=newValue; this.nameSETS++;},
    38   get: function() {this.nameGETS++; return this._name;}
    39 });
    41     status = 'In SECTION1 of test after 0 sets, 0 gets';
    42 actual = [obj.nameSETS,obj.nameGETS];
    43 expect = [0,0];
    44 addThis();
    46 s = obj.name;
    47 status = 'In SECTION1 of test after 0 sets, 1 get';
    48 actual = [obj.nameSETS,obj.nameGETS];
    49 expect = [0,1];
    50 addThis();
    52 obj.name = cnFRED;
    53 status = 'In SECTION1 of test after 1 set, 1 get';
    54 actual = [obj.nameSETS,obj.nameGETS];
    55 expect = [1,1];
    56 addThis();
    58 obj.name = obj.name;
    59 status = 'In SECTION1 of test after 2 sets, 2 gets';
    60 actual = [obj.nameSETS,obj.nameGETS];
    61 expect = [2,2];
    62 addThis();
    65 // SECTION2: define getter/setter in Object.prototype
    66 Object.prototype.nameSETS = 0;
    67 Object.prototype.nameGETS = 0;
    68 Object.defineProperty(Object.prototype, "name",
    69 {
    70   enumerable: true, configurable: true,
    71   set: function(newValue) {this._name=newValue; this.nameSETS++;},
    72   get: function() {this.nameGETS++; return this._name;}
    73 });
    75     obj = new Object();
    76 status = 'In SECTION2 of test after 0 sets, 0 gets';
    77 actual = [obj.nameSETS,obj.nameGETS];
    78 expect = [0,0];
    79 addThis();
    81 s = obj.name;
    82 status = 'In SECTION2 of test after 0 sets, 1 get';
    83 actual = [obj.nameSETS,obj.nameGETS];
    84 expect = [0,1];
    85 addThis();
    87 obj.name = cnFRED;
    88 status = 'In SECTION2 of test after 1 set, 1 get';
    89 actual = [obj.nameSETS,obj.nameGETS];
    90 expect = [1,1];
    91 addThis();
    93 obj.name = obj.name;
    94 status = 'In SECTION2 of test after 2 sets, 2 gets';
    95 actual = [obj.nameSETS,obj.nameGETS];
    96 expect = [2,2];
    97 addThis();
   100 // SECTION 3: define getter/setter in prototype of user-defined constructor
   101 function TestObject()
   102 {
   103 }
   104 TestObject.prototype.nameSETS = 0;
   105 TestObject.prototype.nameGETS = 0;
   106 Object.defineProperty(TestObject.prototype, "name",
   107 {
   108   enumerable: true, configurable: true,
   109   set: function(newValue) {this._name=newValue; this.nameSETS++;},
   110   get: function() {this.nameGETS++; return this._name;}
   111 });
   112     TestObject.prototype.name = cnDEFAULT;
   114 obj = new TestObject();
   115 status = 'In SECTION3 of test after 1 set, 0 gets'; // (we set a default value in the prototype)
   116 actual = [obj.nameSETS,obj.nameGETS];
   117 expect = [1,0];
   118 addThis();
   120 s = obj.name;
   121 status = 'In SECTION3 of test after 1 set, 1 get';
   122 actual = [obj.nameSETS,obj.nameGETS];
   123 expect = [1,1];
   124 addThis();
   126 obj.name = cnFRED;
   127 status = 'In SECTION3 of test after 2 sets, 1 get';
   128 actual = [obj.nameSETS,obj.nameGETS];
   129 expect = [2,1];
   130 addThis();
   132 obj.name = obj.name;
   133 status = 'In SECTION3 of test after 3 sets, 2 gets';
   134 actual = [obj.nameSETS,obj.nameGETS];
   135 expect = [3,2];
   136 addThis();
   138 obj2 = new TestObject();
   139 status = 'obj2 = new TestObject() after 1 set, 0 gets';
   140 actual = [obj2.nameSETS,obj2.nameGETS];
   141 expect = [1,0]; // we set a default value in the prototype -
   142 addThis();
   144 // Use both obj and obj2  -
   145 obj2.name = obj.name +  obj2.name;
   146 status = 'obj2 = new TestObject() after 2 sets, 1 get';
   147 actual = [obj2.nameSETS,obj2.nameGETS];
   148 expect = [2,1];
   149 addThis();
   151 status = 'In SECTION3 of test after 3 sets, 3 gets';
   152 actual = [obj.nameSETS,obj.nameGETS];
   153 expect = [3,3];  // we left off at [3,2] above -
   154 addThis();
   157 //---------------------------------------------------------------------------------
   158 test();
   159 //---------------------------------------------------------------------------------
   162 function addThis()
   163 {
   164   statusitems[UBound] = status;
   165   actualvalues[UBound] = actual.toString();
   166   expectedvalues[UBound] = expect.toString();
   167   UBound++;
   168 }
   171 function test()
   172 {
   173   enterFunc ('test');
   174   printBugNumber(BUGNUMBER);
   175   printStatus (summary);
   177   for (var i = 0; i < UBound; i++)
   178   {
   179     reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
   180   }
   182   exitFunc ('test');
   183 }
   186 function getStatus(i)
   187 {
   188   return statprefix + statusitems[i];
   189 }

mercurial