js/src/tests/ecma_3_1/Object/regress-444787.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 var BUGNUMBER = 444787;
     8 var summary = 'Object.getPrototypeOf';
     9 var actual = '';
    10 var expect = '';
    13 //-----------------------------------------------------------------------------
    14 test();
    15 //-----------------------------------------------------------------------------
    17 function test()
    18 {
    19   enterFunc ('test');
    20   printBugNumber(BUGNUMBER);
    21   printStatus (summary);
    23   var i;
    24   var type;
    25   var instance;
    26   var types = [
    27     Array,
    28     Boolean,
    29     Date,
    30     Error,
    31     Function,
    32     Math,
    33     Number,
    34     Object,
    35     RegExp,
    36     String,
    37     ];
    39   for (i = 0; i < types.length; i++)
    40   {
    41     type = types[i];
    43     if (typeof type.__proto__ != 'undefined')
    44     {
    45       expect = type.__proto__;
    46       actual = Object.getPrototypeOf(type);
    47       reportCompare(expect, actual, summary + ': ' + type.name);
    48     }
    50     try
    51     {
    52       eval('instance = new ' + type.name);
    53       expect = type.prototype;
    54       actual = Object.getPrototypeOf(instance);
    55       reportCompare(expect, actual, summary + ': new ' + type.name);
    56     }
    57     catch(ex if ex instanceof TypeError)
    58     {
    59       print('Ignore ' + ex);
    60     }
    61     catch(ex)
    62     {
    63       actual = ex + '';
    64       reportCompare(expect, actual, summary + ': new ' + type.name);
    65     }
    67   }
    69   types = [null, undefined];
    71   for (i = 0; i < types.length; i++)
    72   {
    73     type = types[i];
    74     expect = 'TypeError: Object.getPrototype is not a function';
    75     try
    76     {
    77       actual = Object.getPrototype(null);
    78     }
    79     catch(ex)
    80     {
    81       actual = ex + '';
    82     }
    83     reportCompare(expect, actual, summary + ': ' + type);
    84   }
    86   var objects = [
    87     {instance: [0], type: Array},
    88     {instance: (function () {}), type: Function},
    89     {instance: eval, type: Function},
    90     {instance: parseInt, type: Function},
    91     {instance: {a: ''}, type: Object},
    92     {instance: /foo/, type: RegExp}
    93     ];
    95   for (i = 0; i < objects.length; i++)
    96   {
    97     instance = objects[i].instance;
    98     type     = objects[i].type;
    99     expect   = type.prototype;
   100     actual   = Object.getPrototypeOf(instance);
   101     reportCompare(expect, actual, summary + ' instance: ' + instance + ', type: ' + type.name);
   102   }
   104   var non_objects = [ true, false, 1.0, Infinity, NaN, Math.PI, "bar" ];
   106   for (i = 0; i < non_objects.length; i++)
   107   {
   108     instance = non_objects[i];
   109     expect = 'TypeError: instance is not an object';
   110     try
   111     {
   112       actual = Object.getPrototypeOf(instance);
   113     }
   114     catch(ex)
   115     {
   116       actual = ex + '';
   117     }
   118     reportCompare(expect, actual, summary + ' non-object: ' + actual);
   119   }
   121   exitFunc ('test');
   122 }

mercurial