js/src/tests/js1_5/Scope/scope-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: 2001-07-03
     8  *
     9  * SUMMARY:  Testing scope with nested functions
    10  *
    11  * From correspondence with Christopher Oliver <coliver@mminternet.com>:
    12  *
    13  * > Running this test with Rhino produces the following exception:
    14  * >
    15  * > uncaught JavaScript exception: undefined: Cannot find default value for
    16  * > object. (line 3)
    17  * >
    18  * > This is due to a bug in org.mozilla.javascript.NativeCall which doesn't
    19  * > implement toString or valueOf or override getDefaultValue.
    20  * > However, even after I hacked in an implementation of getDefaultValue in
    21  * > NativeCall, Rhino still produces a different result then SpiderMonkey:
    22  * >
    23  * > [object Call]
    24  * > [object Object]
    25  * > [object Call]
    26  *
    27  * Note the results should be:
    28  *
    29  *   [object global]
    30  *   [object Object]
    31  *   [object global]
    32  *
    33  * This is what we are checking for in this testcase -
    34  */
    35 //-----------------------------------------------------------------------------
    36 var UBound = 0;
    37 var BUGNUMBER = '(none)';
    38 var summary = 'Testing scope with nested functions';
    39 var statprefix = 'Section ';
    40 var statsuffix = ' of test -';
    41 var self = this; // capture a reference to the global object;
    42 var cnGlobal = self.toString();
    43 var cnObject = (new Object).toString();
    44 var statusitems = [];
    45 var actualvalues = [];
    46 var expectedvalues = [];
    49 function a()
    50 {
    51   function b()
    52   {
    53     capture(this.toString());
    54   }
    56   this.c = function()
    57     {
    58       capture(this.toString());
    59       b();
    60     }
    62   b();
    63 }
    66 var obj = new a();  // captures actualvalues[0]
    67 obj.c();            // captures actualvalues[1], actualvalues[2]
    70 // The values we expect - see introduction above -
    71 expectedvalues[0] = cnGlobal;
    72 expectedvalues[1] = cnObject;
    73 expectedvalues[2] = cnGlobal;
    77 //-----------------------------------------------------------------------------
    78 test();
    79 //-----------------------------------------------------------------------------
    83 function capture(val)
    84 {
    85   actualvalues[UBound] = val;
    86   statusitems[UBound] = getStatus(UBound);
    87   UBound++;
    88 }
    91 function test()
    92 {
    93   enterFunc ('test');
    94   printBugNumber(BUGNUMBER);
    95   printStatus (summary);
    97   for (var i=0; i<UBound; i++)
    98   {
    99     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   100   }
   102   exitFunc ('test');
   103 }
   106 function getStatus(i)
   107 {
   108   return statprefix + i + statsuffix;
   109 }

mercurial